From 7e5730a19ffe222a74e92df65b1a24e6d3887838 Mon Sep 17 00:00:00 2001 From: giavaphi Date: Mon, 28 Nov 2022 13:09:59 +0100 Subject: [PATCH] fix nullpointer exception check date garden schedule --- .../models/GardenSchedule.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java b/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java index a3eccfa..56a3a54 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java @@ -146,13 +146,17 @@ public class GardenSchedule { dayTaskList.add(new ArrayList<>()); final int finalI = i; weekTasks.forEach(task -> { - LocalDate checkDate = task.getNextExecution(); - do { - if (date.equals(checkDate) && !date.isAfter(task.getEndDate().orElse(LocalDate.MIN))) { - dayTaskList.get(finalI).add(task); - } - checkDate = checkDate.plusDays(task.getInterval().orElse(0)); - } while (!(task.getInterval().orElse(0) == 0) && checkDate.isBefore(LocalDate.now().plusDays(listLength))); + if (task.getNextExecution() == null) { + task.isDone(); + } else { + LocalDate checkDate = task.getNextExecution(); + do { + if (date.equals(checkDate) && !date.isAfter(task.getEndDate().orElse(LocalDate.MIN))) { + 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; @@ -187,6 +191,6 @@ public class GardenSchedule { * @return a sorted coppy of the given Tasklist */ private List getSortedTaskList(List taskList, Comparator comparator) { - return taskList.stream().sorted(comparator).collect(Collectors.toList()); + return taskList.stream().filter(task -> task.getNextExecution() != null).sorted(comparator).collect(Collectors.toList()); } }