From 82a11efa31f0a0d259e089e702f58dd9c141ed02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Oliva?= Date: Mon, 29 May 2023 21:51:07 -0600 Subject: New get function and sorting problems. Get function for filtered to dos. Sorting can now compare null objects. Reordered sorting because of a Concurrent Modification Exception. --- src/main/java/com/encora/ToDosRepository.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/main/java/com/encora/ToDosRepository.java') diff --git a/src/main/java/com/encora/ToDosRepository.java b/src/main/java/com/encora/ToDosRepository.java index a4c9a10..c4bdcba 100644 --- a/src/main/java/com/encora/ToDosRepository.java +++ b/src/main/java/com/encora/ToDosRepository.java @@ -171,7 +171,7 @@ public class ToDosRepository implements JpaRepository { break; case "DueDate": - comparator = Comparator.comparing(ToDos::getDueDate); + comparator = Comparator.comparing(ToDos::getDueDate, Comparator.nullsLast(Comparator.naturalOrder())); break; default: @@ -187,16 +187,20 @@ public class ToDosRepository implements JpaRepository { // Filter and then sort all of our to dos. public void refreshFilteredToDos(Sort sort, String name, String priority, String done) throws Exception { - this.filteredToDos = this.findAllWithFilter(name, priority, done); - try { Comparator comparator = this.getToDoComparator(sort); - Collections.sort(this.filteredToDos, comparator); + + this.filteredToDos = this.findAllWithFilter(name, priority, done); + this.filteredToDos.sort(comparator); } catch (Exception e) { throw new RuntimeException(e); } } + public List getFilteredToDos() { + return this.filteredToDos; + } + /* * N O T Y E T D E F I N E D . */ -- cgit v1.2.3