aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/com/encora/Main.java7
-rw-r--r--src/main/java/com/encora/ToDosRepository.java12
2 files changed, 10 insertions, 9 deletions
diff --git a/src/main/java/com/encora/Main.java b/src/main/java/com/encora/Main.java
index 7793be9..ea3a2a4 100644
--- a/src/main/java/com/encora/Main.java
+++ b/src/main/java/com/encora/Main.java
@@ -6,10 +6,7 @@ import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
@SpringBootApplication
@RestController
@@ -215,7 +212,7 @@ public class Main {
}
final int pageSize = 10;
- List<ToDos> myToDos = toDosRepository.filteredToDos;
+ List<ToDos> myToDos = toDosRepository.getFilteredToDos();
int fromIndex = (page - 1) * pageSize;
if (myToDos.size() <= fromIndex) {
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 .
*/