From 75de2ea4fa1c5fb88430931ac6db6a51e5eed952 Mon Sep 17 00:00:00 2001 From: TehZiHuai Date: Sun, 10 Nov 2019 16:26:36 +0800 Subject: [PATCH] bugfix in logic of CheckDuplicatesOverdue --- src/main/java/Operations/CheckAnomaly.java | 10 +++++----- src/main/java/Operations/TaskList.java | 2 +- src/main/java/RoomShare.java | 7 +++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/Operations/CheckAnomaly.java b/src/main/java/Operations/CheckAnomaly.java index 62be2b7dd6..475bb9f6c6 100644 --- a/src/main/java/Operations/CheckAnomaly.java +++ b/src/main/java/Operations/CheckAnomaly.java @@ -42,11 +42,11 @@ public static Boolean checkDuplicateOverdue(Task task) { String assignee = task.getAssignee(); String date = task.getDate().toString(); ArrayList temp = OverdueList.getOverdueList(); - for (int i = 0; i < temp.size(); i++) { - if (temp.get(i).getDescription().equals(name) - && temp.get(i).getAssignee().equals(assignee) - && temp.get(i).getDate().toString().equals(date) - && temp.get(i).getClass().equals(task.getClass())) { + for (Task value : temp) { + if (value.getDescription().equals(name) + && value.getAssignee().equals(assignee) + && value.getDate().toString().equals(date) + && value.getClass().equals(task.getClass())) { return true; } } diff --git a/src/main/java/Operations/TaskList.java b/src/main/java/Operations/TaskList.java index 56d29abde3..19d77cf4fd 100644 --- a/src/main/java/Operations/TaskList.java +++ b/src/main/java/Operations/TaskList.java @@ -80,7 +80,7 @@ public void list(OverdueList overdueList) throws RoomShareException { for (int i = 0; i < tasks.size(); i++) { if (new Date().after(tasks.get(i).getDate()) && !(tasks.get(i) instanceof Leave)) { tasks.get(i).setOverdue(true); - if (CheckAnomaly.checkDuplicateOverdue(tasks.get(i))) { + if (!CheckAnomaly.checkDuplicateOverdue(tasks.get(i))) { // no duplicates in overdue list overdueList.add(tasks.get(i)); } diff --git a/src/main/java/RoomShare.java b/src/main/java/RoomShare.java index 41a3f7c64f..4eb819bf00 100644 --- a/src/main/java/RoomShare.java +++ b/src/main/java/RoomShare.java @@ -22,7 +22,6 @@ public class RoomShare { private TaskList taskList; private OverdueList overdueList; private Parser parser; - private RecurHandler recurHandler; private TempDeleteList tempDeleteList; private TaskCreator taskCreator; private Help help; @@ -32,7 +31,7 @@ public class RoomShare { * Constructor of a RoomShare class. Creates all necessary objects and collections for RoomShare to run * Also loads the ArrayList of tasks from the data.txt file */ - public RoomShare() throws RoomShareException { + private RoomShare() throws RoomShareException { ui = new Ui(); help = new Help(); ui.startUp(); @@ -57,7 +56,7 @@ public RoomShare() throws RoomShareException { overdueList = new OverdueList(emptyList); } listRoutine = new ListRoutine(taskList, overdueList); - recurHandler = new RecurHandler(taskList); + RecurHandler recurHandler = new RecurHandler(taskList); if (recurHandler.checkRecurrence()) { ui.showChangeInTaskList(); taskList.list(overdueList); @@ -68,7 +67,7 @@ public RoomShare() throws RoomShareException { /** * Deals with the operation flow of RoomShare. */ - public void run() throws RoomShareException, IOException, InterruptedException { + private void run() throws RoomShareException, IOException, InterruptedException { boolean isExit = false; while (!isExit) { TaskType type;