diff options
author | Adrián Oliva <adrian.oliva@cimat.mx> | 2023-05-29 21:51:07 -0600 |
---|---|---|
committer | Adrián Oliva <adrian.oliva@cimat.mx> | 2023-05-29 21:51:07 -0600 |
commit | 82a11efa31f0a0d259e089e702f58dd9c141ed02 (patch) | |
tree | 6b0289fc54bb1c43715289b580bba4212faf1f4d /src/main/java/com/encora/ToDosRepository.java | |
parent | 1f192c7ad1a7c3854efa5595321783e5b1a3fe81 (diff) | |
download | ToDo-App-BE-82a11efa31f0a0d259e089e702f58dd9c141ed02.tar.gz ToDo-App-BE-82a11efa31f0a0d259e089e702f58dd9c141ed02.zip |
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.
Diffstat (limited to 'src/main/java/com/encora/ToDosRepository.java')
-rw-r--r-- | src/main/java/com/encora/ToDosRepository.java | 12 |
1 files changed, 8 insertions, 4 deletions
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<ToDos, Integer> { 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<ToDos, Integer> { // 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<ToDos> 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<ToDos> getFilteredToDos() { + return this.filteredToDos; + } + /* * N O T Y E T D E F I N E D . */ |