From 1dd01d0249db07d23197e19c6ee3c5ec9b3434e9 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 28 Oct 2023 18:30:14 +0200 Subject: [PATCH] Fix removing objects from lists while iterating over them --- .../entities/timemanager/BasicTaskSchedule.java | 14 ++++++++++++++ .../java/core/services/TaskScheduleService.java | 10 ++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/core/entities/timemanager/BasicTaskSchedule.java b/backend/src/main/java/core/entities/timemanager/BasicTaskSchedule.java index 55fd4e7..00d281e 100644 --- a/backend/src/main/java/core/entities/timemanager/BasicTaskSchedule.java +++ b/backend/src/main/java/core/entities/timemanager/BasicTaskSchedule.java @@ -3,6 +3,7 @@ package core.entities.timemanager; import javax.persistence.*; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.Objects; @Entity @Table(name = "basic_schedules") @@ -79,4 +80,17 @@ public class BasicTaskSchedule { public boolean isActivateAble() { return startTime == null; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + BasicTaskSchedule that = (BasicTaskSchedule) o; + return scheduleID == that.scheduleID; + } + + @Override + public int hashCode() { + return Objects.hash(scheduleID); + } } diff --git a/backend/src/main/java/core/services/TaskScheduleService.java b/backend/src/main/java/core/services/TaskScheduleService.java index 464e84d..9d62574 100644 --- a/backend/src/main/java/core/services/TaskScheduleService.java +++ b/backend/src/main/java/core/services/TaskScheduleService.java @@ -13,6 +13,7 @@ import org.springframework.stereotype.Service; import java.time.Duration; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.LinkedList; import java.util.List; import java.util.Optional; @@ -61,14 +62,15 @@ public class TaskScheduleService { } List basicTaskSchedules = basicTaskScheduleRepository.findAllByUserAndDate(user.get(), LocalDate.now()); + List activatableSchedules = new LinkedList<>(); if(onlyActivateable) { - for(int i=0; i(basicTaskSchedules); + return new ServiceResult<>(activatableSchedules); } public ServiceResult> loadSchedules(String username) {