From 563991180dd282270c04c9821e932d3a66af809c Mon Sep 17 00:00:00 2001 From: Ryan Tay Date: Sun, 10 Nov 2019 12:30:11 +0800 Subject: [PATCH] edited the help functions, added range based rescheduling --- src/main/java/Operations/Help.java | 22 ++++-- src/main/java/Operations/OverdueList.java | 31 +++++--- src/main/java/Operations/Ui.java | 96 ++++++++++++++--------- src/main/java/RoomShare.java | 20 +++-- src/test/java/OverdueListTest.java | 94 ++++++++++++++++++++++ 5 files changed, 203 insertions(+), 60 deletions(-) create mode 100644 src/test/java/OverdueListTest.java diff --git a/src/main/java/Operations/Help.java b/src/main/java/Operations/Help.java index 5cebb6eed4..1264038c89 100644 --- a/src/main/java/Operations/Help.java +++ b/src/main/java/Operations/Help.java @@ -23,11 +23,8 @@ public void showHelp(String keyword) { taskType = TaskType.others; } switch (taskType) { - case add: - ui.helpAdd(); - break; - case delete: - ui.helpDelete(); + case bye: + ui.helpBye(); break; case list: ui.helperList(); @@ -35,6 +32,12 @@ public void showHelp(String keyword) { case done: ui.helpDone(); break; + case delete: + ui.helpDelete(); + break; + case removeoverdue: + ui.helpRemoveoverdue(); + break; case restore: ui.helpRestore(); break; @@ -44,6 +47,9 @@ public void showHelp(String keyword) { case priority: ui.helpPriority(); break; + case add: + ui.helpAdd(); + break; case snooze: ui.helpSnooze(); break; @@ -62,9 +68,6 @@ public void showHelp(String keyword) { case log: ui.helpLog(); break; - case bye: - ui.helpBye(); - break; case completed: ui.helpCompleted(); break; @@ -74,6 +77,9 @@ public void showHelp(String keyword) { case reschedule: ui.helpReschedule(); break; + case show: + ui.helpShow(); + break; } } diff --git a/src/main/java/Operations/OverdueList.java b/src/main/java/Operations/OverdueList.java index 1d704011b6..eca29ecaa2 100644 --- a/src/main/java/Operations/OverdueList.java +++ b/src/main/java/Operations/OverdueList.java @@ -32,18 +32,31 @@ public void add(Task task) { * Reschedules an overdue task that was in the overdued list to be placed back into * the original task list for the user. * - * @param index index of the task in the Overdued task list that is being rescheduled. + * @param idx index of the task in the Overdued task list that is being rescheduled. * @throws RoomShareException if the index entered is not valid */ - public void reschedule(int index, TaskList taskList) throws RoomShareException { - if (index < 0 || index > Overdue.size() - 1) { - System.out.println("This are your tasks in your Overdue list"); - list(); - throw new RoomShareException(ExceptionType.outOfBounds); + public void reschedule(int[] idx, TaskList taskList) throws RoomShareException { + int[] index = idx.clone(); + if (index.length ==1) { + if (index[0] < 0 || index[0] >= Overdue.size()) { + System.out.println("This are your tasks in your Overdue list"); + list(); + throw new RoomShareException(ExceptionType.outOfBounds); + } else { + taskList.add(Overdue.get(index[0])); + Overdue.get(index[0]).setOverdue(false); + } } else { - taskList.add(Overdue.get(index)); - Overdue.get(index).setOverdue(false); - Overdue.remove(index); + if (index[0] < 0 || index[0] >= Overdue.size() || index[1] < 0 || index[1] >= Overdue.size()) { + throw new RoomShareException(ExceptionType.outOfBounds); + } + for (int i = index[0]; i <= index[1]; i++){ + taskList.add(Overdue.get(i)); + Overdue.get(i).setOverdue(false); + } + } + for (int i = 0; i < index.length; i++){ + Overdue.removeIf(n -> !n.getOverdue()); } } diff --git a/src/main/java/Operations/Ui.java b/src/main/java/Operations/Ui.java index eb934adcb9..c9baeee9ea 100644 --- a/src/main/java/Operations/Ui.java +++ b/src/main/java/Operations/Ui.java @@ -38,6 +38,29 @@ public void startUp() { System.out.println("Enter 'help' if you require assistance"); } + public void helpList() { + System.out.println("Here are a list of commands you can input: " + + "\n bye " + + "\n list " + + "\n done " + + "\n delete " + + "\n removeoverdue " + + "\n restore " + + "\n find " + + "\n priority " + + "\n add " + + "\n snooze " + + "\n reorder " + + "\n subtask " + + "\n update " + + "\n sort " + + "\n log " + + "\n completed " + + "\n overdue " + + "\n reschedule " + + "\n show \n" + + "For more information about a specific command you can \nEnter help followed by a command, eg. help add\n"); + } public void helpAdd() { System.out.println("Adds a Meeting or Assignment to the list\n"); @@ -138,6 +161,37 @@ public void helpLog() { System.out.println("Logs the current task list into a saved file"); } + public void helpRemoveoverdue() { + System.out.println("Remove tasks from the overdue list if you do not want to reschedule it"); + System.out.println("\teg. removeoverdue 2"); + System.out.println("\teg. removeoverdue 1-3"); + } + + public void helpBye() { + System.out.println("Typing in 'bye' will exit the program"); + } + + public void helpCompleted() { + System.out.println("Shows the list of completed tasks"); + } + + public void helpOverdue() { + System.out.println("Shows the list of overdued tasks"); + } + + public void helpReschedule() { + System.out.println("Reschedules an overdued task by index to a later date by inputting a new date"); + System.out.println("\teg. reschedule 1 &20/11/2019 10:00&"); + System.out.println("\teg. reschedule 3-4 &tmr 10:00&"); + System.out.println("This will reschedule the tasks specified by their index to the new date"); + } + + public void helpShow() { + System.out.println("Shows you the task tagged to each user in the task list"); + System.out.println("\teg. show kelly"); + System.out.println("This will list all the tasks assigned to kelly and everyone"); + } + /** * Prints a message telling the user that the task at the index has been deleted. * @@ -235,27 +289,7 @@ public void showReordering() { System.out.println("Reordering the task list..."); } - public void helpList() { - System.out.println("Here are a list of commands you can input: " + - "\n add " + - "\n delete " + - "\n list " + - "\n done " + - "\n restore " + - "\n find " + - "\n priority " + - "\n snooze " + - "\n reorder " + - "\n subtask " + - "\n update " + - "\n sort " + - "\n bye " + - "\n completed " + - "\n overdue " + - "\n reschedule " + - "\n log \n" + - "For more information about a specific command you can \nEnter help followed by a command, eg. help add"); - } + /** * Show the message of an error encountered @@ -310,26 +344,10 @@ public void showOverdueList() { System.out.println("Here are your overdued tasks: "); } - public void helpBye() { - System.out.println("Typing in 'bye' will exit the program"); - } - - public void helpCompleted() { - System.out.println("Shows the list of completed tasks"); - } - - public void helpOverdue() { - System.out.println("Shows the list of overdued tasks"); - } - - public void helpReschedule() { - System.out.println("Reschedules an overdued task by index to a later date by inputting a new date"); - System.out.println("\teg. reschedule 1 &20/11/2019 10:00&"); - System.out.println("This will reschedule task 1 in the overdue task list to have a deadline of 20th Nov 2019 at 10am"); - } public void showTagged(String user) { System.out.println("These are the tasks assigned to " + user + ":"); } + public void showTaggedPercentage(String user) { System.out.println("The completion status for '" + user + "' is:"); } @@ -337,4 +355,6 @@ public void showTaggedPercentage(String user) { public void showDeletedList() { System.out.println("Here are the tasks that you have deleted and are in temporary storage"); } + + } diff --git a/src/main/java/RoomShare.java b/src/main/java/RoomShare.java index 70ad79a538..3b27a1f030 100644 --- a/src/main/java/RoomShare.java +++ b/src/main/java/RoomShare.java @@ -11,6 +11,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; /** * Main class of the RoomShare program. @@ -385,11 +386,20 @@ public void run() throws RoomShareException, IOException, InterruptedException { try { overdueList.list(); String input = parser.getCommandLine(); - int index = parser.getIndex(input); - Task oldTask = overdueList.get(index); - taskCreator.rescheduleTask(input,oldTask); - overdueList.reschedule(index, taskList); - ui.showUpdated(index+1); + String[] range = input.split(" "); + int[] indexes = parser.getIndexRange(range[0]); + if (indexes.length != 1) { + for (int i = indexes[0]; i <= indexes[1]; i++) { + Task oldTask = overdueList.get(i); + taskCreator.rescheduleTask(input, oldTask); + ui.showUpdated(i + 1); + } + } else { + Task oldTask = overdueList.get(indexes[0]); + taskCreator.rescheduleTask(input, oldTask); + ui.showUpdated(indexes[0] + 1); + } + overdueList.reschedule(indexes, taskList); storage.writeFile(TaskList.currentList(), "data.txt"); storage.writeFile(OverdueList.getOverdueList(), "overdue.txt"); } catch (RoomShareException e) { diff --git a/src/test/java/OverdueListTest.java b/src/test/java/OverdueListTest.java new file mode 100644 index 0000000000..1407eda5bf --- /dev/null +++ b/src/test/java/OverdueListTest.java @@ -0,0 +1,94 @@ +import CustomExceptions.RoomShareException; +import Enums.Priority; +import Enums.TimeUnit; +import Model_Classes.Assignment; +import Model_Classes.Leave; +import Model_Classes.Meeting; +import Operations.OverdueList; +import Operations.TaskList; +import Operations.TempDeleteList; +import org.junit.jupiter.api.Test; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; + +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertEquals; + +class OverdueListTest { + private SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm"); + private Date date1; + private Date date2; + private Date date3; + private Date date4; + + { + try { + date1 = format.parse("22/12/2019 18:00"); + date2 = format.parse("23/12/2019 18:00"); + date3 = format.parse("24/12/2019 18:00"); + date4 = format.parse("25/12/2019 18:00"); + } catch (ParseException e) { + e.printStackTrace(); + } + } + + private Assignment assignment1 = new Assignment("assignment1", date1); + private Assignment assignment2 = new Assignment("assignment2", date2); + private Meeting meeting1 = new Meeting("meeting1", date3); + private Meeting meeting2 = new Meeting("meeting2", date4); + + private Leave leave = new Leave("leave", "kel", date3, date4); + private OverdueList overdueList = new OverdueList(new ArrayList<>()); + + @Test + void add() { + overdueList.add(assignment1); + overdueList.add(assignment2); + overdueList.add(meeting1); + overdueList.add(meeting2); + try { + assertEquals("[A] assignment1 (everyone) (by: Sun Dec 22 18:00:00 SGT 2019)", overdueList.get(0).toString()); + assertEquals("[A] assignment2 (everyone) (by: Mon Dec 23 18:00:00 SGT 2019)", overdueList.get(1).toString()); + assertEquals("[M] meeting1 (everyone) (on: Tue Dec 24 18:00:00 SGT 2019)", overdueList.get(2).toString()); + assertEquals("[M] meeting2 (everyone) (on: Wed Dec 25 18:00:00 SGT 2019)", overdueList.get(3).toString()); + } catch (RoomShareException e) { + e.printStackTrace(); + } + } + + @Test + void reschedule() { + overdueList.add(assignment1); + overdueList.add(meeting1); + overdueList.add(assignment2); + overdueList.add(meeting2); + int[] index = {0, 1}; + try { + overdueList.reschedule(index, new TaskList(new ArrayList<>())); + assertEquals("[A] assignment2 (everyone) (by: Sun Dec 22 18:00:00 SGT 2019)\n" + + "[M] meeting2 (everyone) (by: Sun Dec 22 18:00:00 SGT 2019)", overdueList.get(0).toString() + "\n" + overdueList.get(1).toString()); + } catch (RoomShareException e) { + e.printStackTrace(); + } + } + + @Test + void remove() { + overdueList.add(assignment1); + overdueList.add(meeting1); + overdueList.add(assignment2); + overdueList.add(meeting2); + int[] index = {0, 1}; + try { + overdueList.remove(index, new TempDeleteList(new ArrayList<>())); + assertEquals("[A] assignment2 (everyone) (by: Mon Dec 23 18:00:00 SGT 2019)\n" + + "[M] meeting2 (everyone) (on: Wed Dec 25 18:00:00 SGT 2019)", overdueList.get(0).toString() + "\n" + overdueList.get(1).toString()); + } catch (RoomShareException e) { + e.printStackTrace(); + } + } + +}