Skip to content

Commit

Permalink
Updated some check style and edited multiple command file to reduce c…
Browse files Browse the repository at this point in the history
…ode length
  • Loading branch information
LinWanLeii committed Sep 20, 2023
1 parent 371e040 commit 8aca4cb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
9 changes: 3 additions & 6 deletions Testing.txt
Original file line number Diff line number Diff line change
@@ -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)
[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)
25 changes: 18 additions & 7 deletions src/main/java/command/MultipleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/duke/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/tasks/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 8aca4cb

Please sign in to comment.