fix nullpointer exception check date garden schedule

This commit is contained in:
giavaphi 2022-11-28 13:09:59 +01:00
parent 3d36c85941
commit 7e5730a19f
1 changed files with 12 additions and 8 deletions

View File

@ -146,13 +146,17 @@ public class GardenSchedule {
dayTaskList.add(new ArrayList<>()); dayTaskList.add(new ArrayList<>());
final int finalI = i; final int finalI = i;
weekTasks.forEach(task -> { weekTasks.forEach(task -> {
LocalDate checkDate = task.getNextExecution(); if (task.getNextExecution() == null) {
do { task.isDone();
if (date.equals(checkDate) && !date.isAfter(task.getEndDate().orElse(LocalDate.MIN))) { } else {
dayTaskList.get(finalI).add(task); LocalDate checkDate = task.getNextExecution();
} do {
checkDate = checkDate.plusDays(task.getInterval().orElse(0)); if (date.equals(checkDate) && !date.isAfter(task.getEndDate().orElse(LocalDate.MIN))) {
} while (!(task.getInterval().orElse(0) == 0) && checkDate.isBefore(LocalDate.now().plusDays(listLength))); dayTaskList.get(finalI).add(task);
}
checkDate = checkDate.plusDays(task.getInterval().orElse(0));
} while (!(task.getInterval().orElse(0) == 0) && checkDate.isBefore(LocalDate.now().plusDays(listLength)));
}
}); });
} }
return dayTaskList; return dayTaskList;
@ -187,6 +191,6 @@ public class GardenSchedule {
* @return a sorted coppy of the given Tasklist * @return a sorted coppy of the given Tasklist
*/ */
private List<Task> getSortedTaskList(List<Task> taskList, Comparator<Task> comparator) { private List<Task> getSortedTaskList(List<Task> taskList, Comparator<Task> comparator) {
return taskList.stream().sorted(comparator).collect(Collectors.toList()); return taskList.stream().filter(task -> task.getNextExecution() != null).sorted(comparator).collect(Collectors.toList());
} }
} }