diff --git a/Testing.txt b/Testing.txt index 7b6a0759ab..69d010a145 100644 --- a/Testing.txt +++ b/Testing.txt @@ -1,6 +1,3 @@ -[D][ ] work more on ip (by: Sep 22 2023) -[E][ ] workout (from: Sep 22 2023 to: Sep 22 3023) -[T][X] workout -[T][ ] shower -[D][ ] dry off (by: Sep 22 2023) -[E][ ] change clothes (from: Sep 23 2023 to: Sep 23 2024) \ No newline at end of file + [D][X] rk more on ip (by: Sep 22 2023) + [E][X] rkout (from: Sep 22 2023 to: Sep 22 3023) + [E][ ] ange clothes (from: Sep 23 2023 to: Sep 23 2024) diff --git a/src/main/java/command/MultipleCommand.java b/src/main/java/command/MultipleCommand.java index 160ef117a9..207975ed46 100644 --- a/src/main/java/command/MultipleCommand.java +++ b/src/main/java/command/MultipleCommand.java @@ -39,13 +39,8 @@ public String execute(TaskList taskList, Ui ui, FileStorage fileStorage) throws Result result = getResult(); int[] reversedValues = result.reversedValues; int[] values = result.values; - for (int i = 0; i < reversedValues.length; i++) { - for (int j = i + 1; j < reversedValues.length; j++) { - if (reversedValues[i] == reversedValues[j]) { - throw new DukeException("Oh no, do not repeat the indexes"); - } - } - } + checkForDuplicates(reversedValues); + checkForDuplicates(values); if (commandType.equals("del")) { for (int reversedValue : reversedValues) { Task task = taskList.deleteTask(reversedValue - 1); @@ -68,6 +63,22 @@ public String execute(TaskList taskList, Ui ui, FileStorage fileStorage) throws return ui.showNewList(result.newList, taskList, commandType); } + /** + * Throws an error if there is a duplicate in the list. + * + * @param intArray The Int array that will be checked. + * @throws DukeException If there are duplicates. + */ + private static void checkForDuplicates(int[] intArray) throws DukeException { + for (int i = 0; i < intArray.length; i++) { + for (int j = i + 1; j < intArray.length; j++) { + if (intArray[i] == intArray[j]) { + throw new DukeException("Oh no, do not repeat the indexes"); + } + } + } + } + /** * Reverses the array of indexes. * diff --git a/src/main/java/duke/Main.java b/src/main/java/duke/Main.java index c0e3faaf2b..3b45094d4d 100644 --- a/src/main/java/duke/Main.java +++ b/src/main/java/duke/Main.java @@ -13,7 +13,7 @@ */ public class Main extends Application { - private Duke duke = new Duke("Testing.txt"); + private final Duke duke = new Duke("Testing.txt"); @Override public void start(Stage stage) { diff --git a/src/main/java/tasks/Task.java b/src/main/java/tasks/Task.java index c0028e20cb..c2fc5024e3 100644 --- a/src/main/java/tasks/Task.java +++ b/src/main/java/tasks/Task.java @@ -20,7 +20,9 @@ public Task(String name) { public Task() { this.isEmpty = true; } - public boolean isItEmpty() { return isEmpty; } + public boolean isItEmpty() { + return isEmpty; + } public void setType(String type) { this.type = type; }