Skip to content

Commit

Permalink
Merge pull request #230 from tyeryan/master
Browse files Browse the repository at this point in the history
edited the help functions, added range based rescheduling
  • Loading branch information
tyeryan authored Nov 10, 2019
2 parents 6a443cd + 03b24ee commit c5986ef
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 95 deletions.
108 changes: 57 additions & 51 deletions src/main/java/Operations/Help.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,57 +23,63 @@ public void showHelp(String keyword) {
taskType = TaskType.others;
}
switch (taskType) {
case add:
ui.helpAdd();
break;
case delete:
ui.helpDelete();
break;
case list:
ui.helperList();
break;
case done:
ui.helpDone();
break;
case restore:
ui.helpRestore();
break;
case find:
ui.helpFind();
break;
case priority:
ui.helpPriority();
break;
case snooze:
ui.helpSnooze();
break;
case reorder:
ui.helpReorder();
break;
case subtask:
ui.helpSubtask();
break;
case update:
ui.helpUpdate();
break;
case sort:
ui.helpSort();
break;
case log:
ui.helpLog();
break;
case bye:
ui.helpBye();
break;
case completed:
ui.helpCompleted();
break;
case overdue:
ui.helpOverdue();
break;
case reschedule:
ui.helpReschedule();
break;
case bye:
ui.helpBye();
break;
case list:
ui.helperList();
break;
case done:
ui.helpDone();
break;
case delete:
ui.helpDelete();
break;
case removeoverdue:
ui.helpRemoveoverdue();
break;
case restore:
ui.helpRestore();
break;
case find:
ui.helpFind();
break;
case priority:
ui.helpPriority();
break;
case add:
ui.helpAdd();
break;
case snooze:
ui.helpSnooze();
break;
case reorder:
ui.helpReorder();
break;
case subtask:
ui.helpSubtask();
break;
case update:
ui.helpUpdate();
break;
case sort:
ui.helpSort();
break;
case log:
ui.helpLog();
break;
case completed:
ui.helpCompleted();
break;
case overdue:
ui.helpOverdue();
break;
case reschedule:
ui.helpReschedule();
break;
case show:
ui.helpShow();
break;
}
}

Expand Down
31 changes: 22 additions & 9 deletions src/main/java/Operations/OverdueList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
84 changes: 55 additions & 29 deletions src/main/java/Operations/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,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");
}

void helpAdd() {
System.out.println("Adds a Meeting or Assignment to the list\n");
Expand Down Expand Up @@ -137,6 +160,37 @@ 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.
*
Expand Down Expand Up @@ -235,18 +289,6 @@ public void showReordering() {
System.out.println("Reordering the task list...");
}

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.
* @param e the encountered error
Expand Down Expand Up @@ -296,26 +338,10 @@ public void showOverdueList() {
System.out.println("Here are your overdue tasks: ");
}

void helpBye() {
System.out.println("Typing in 'bye' will exit the program");
}

void helpCompleted() {
System.out.println("Shows the list of completed tasks");
}

void helpOverdue() {
System.out.println("Shows the list of overdue tasks");
}

void helpReschedule() {
System.out.println("Reschedules an overdue 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:");
}
Expand Down
23 changes: 17 additions & 6 deletions src/main/java/RoomShare.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,23 @@ public void run() throws RoomShareException, IOException, InterruptedException {
ui.startUp();
try {
overdueList.list();
String input = parser.getCommandLine().trim();
int index = parser.getIndex(input);
Task oldTask = overdueList.get(index);
taskCreator.rescheduleTask(input,oldTask);
overdueList.reschedule(index, taskList);
ui.showUpdated(index+1);
String input = parser.getCommandLine();
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) {
ui.showError(e);
} finally {
Expand Down
94 changes: 94 additions & 0 deletions src/test/java/OverdueListTest.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

}

0 comments on commit c5986ef

Please sign in to comment.