Skip to content

Commit

Permalink
Merge pull request #229 from benitokun123/master
Browse files Browse the repository at this point in the history
fix index out of bound error for reopen command
  • Loading branch information
benitokun123 authored Nov 10, 2019
2 parents aadcd8a + b32a3d6 commit 6a443cd
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/main/java/CustomExceptions/RoomShareException.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class RoomShareException extends Exception {
private static final String LOAD_ERROR_MESSAGE = "\terror in loading file: will be initialising empty list instead!\n";
private static final String INVALID_DATE_MESSAGE = "\tThe date you've input is before the current date!\n";
private static final String WRONG_DATE_FORMAT_TEXT = "\tYou've entered invalid date or time\n";
private static final String EMPTY_INDEX = "\tPlease enter a valid index within the range of the list! Eg. restore 1\n";
private static final String EMPTY_INDEX = "\tPlease enter a valid index within the range of the list! Eg. reopen 1\n";
private static final String INVALID_LEAVE_DATE_MESSAGE = "\tPlease check your dates for your leave!\n";
private static final String NO_SUCH_SUBTASK = "\tSubtask does not exist!\n";
private static final String ASSIGNEE_SET_TO_EVERYONE = "\tThere might have been an error when setting the assignee\n"
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/Enums/ReplyType.java

This file was deleted.

5 changes: 0 additions & 5 deletions src/main/java/Enums/ReportType.java

This file was deleted.

21 changes: 10 additions & 11 deletions src/main/java/Operations/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public void delete(int[] index, TempDeleteList deletedList) throws RoomShareExce
}
deletedList.add(tasks.get(idx[0]));
tasks.remove(idx[0]);
}
else {
} else {
if (idx[0] < 0 || idx[0] >= tasks.size() || idx[1] < 0 || idx[1] >= tasks.size()) {
throw new RoomShareException(ExceptionType.outOfBounds);
}
Expand Down Expand Up @@ -131,7 +130,7 @@ public void list(OverdueList overdueList) throws RoomShareException {
public void showCompleted() throws RoomShareException {
sortTasks();
System.out.println(COMPLETED_TASKS);
if (tasks.size() != 0){
if (tasks.size() != 0) {
int listCount = 1;
for (Task output : tasks) {
if (output.getDone()) {
Expand Down Expand Up @@ -166,14 +165,14 @@ public void done(int[] index) throws RoomShareException {
if (index[0] < 0 || index[0] >= tasks.size() || index[1] < 0 || index[1] >= tasks.size()) {
throw new RoomShareException(ExceptionType.outOfBounds);
}
for (int i = index[0]; i <= index[1]; i++){
for (int i = index[0]; i <= index[1]; i++) {
tasks.get(i).setDone(true);
}
}
}

/**
* Set a subtask from an assignment as done
* Set a subtask from an assignment as done.
* @param input the String containing the index of the Assignment and subtask
* @throws RoomShareException if there are formatting error or the task entered is not an Assignment
*/
Expand Down Expand Up @@ -389,7 +388,7 @@ public void reorder(int first, int second) throws RoomShareException {
* @param timeUnit unit for snooze time: month, day, hour, minute
* @throws IndexOutOfBoundsException when the specified index is not within the task list indices
*/
public void snooze (int index, int amount, TimeUnit timeUnit) throws RoomShareException {
public void snooze(int index, int amount, TimeUnit timeUnit) throws RoomShareException {
try {
switch (timeUnit) {
case month:
Expand Down Expand Up @@ -419,7 +418,7 @@ public void snooze (int index, int amount, TimeUnit timeUnit) throws RoomShareEx
*/
int getSize() {
int count = 0;
for(Task t : tasks) {
for (Task t : tasks) {
if (!t.getOverdue() && !(t instanceof Leave)) {
count += 1;
}
Expand Down Expand Up @@ -513,11 +512,11 @@ public int[] listTagged(String user) throws RoomShareException {
* @throws RoomShareException when the task selected is a Leave
*/
public void reopen(int index, Date date) throws RoomShareException {
tasks.get(index).setDate(date);
CheckAnomaly.checkDuplicate(tasks.get(index));
TaskList.get(index).setDate(date);
CheckAnomaly.checkDuplicate(TaskList.get(index));
if (tasks.get(index) instanceof Meeting) {
CheckAnomaly.checkTimeClash(tasks.get(index));
CheckAnomaly.checkTimeClash(TaskList.get(index));
}
tasks.get(index).setDone(false);
TaskList.get(index).setDone(false);
}
}
21 changes: 10 additions & 11 deletions src/main/java/Operations/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import java.io.IOException;

/**
* class to tell user about errors and completion of operations
* Class to tell user about errors and completion of operations.
*/
public class Ui {
/**
* Constructor for Ui class
* Constructor for Ui class.
*/
public Ui() {
}
Expand Down Expand Up @@ -146,8 +146,7 @@ void helpLog() {
public void showDeleted(int[] index) {
if (index.length == 1) {
System.out.println("Deleted task number " + (index[0] + 1) + "!");
}
else {
} else {
System.out.println("Deleted task number " + (index[0] + 1) + " to " + (index[1] + 1) + " !");
}
}
Expand Down Expand Up @@ -184,7 +183,7 @@ public void showBye() {
* tells the user that RoomShare is listing the tasks.
*/
void showList() {
System.out.println("Listing tasks in your task list...");
System.out.println("Listing tasks in the common task list...");
}

/**
Expand All @@ -204,29 +203,29 @@ public void showChangeInTaskList() {
}

/**
* tells the user that the requested task has been snoozed
* tells the user that the requested task has been snoozed.
*/
public void showSnoozeComplete(int index, int amount, TimeUnit unit) {
System.out.println("Great I've snoozed task " + index + " by " + amount + " " + unit.name());
}

/**
* Provides user with instructions to prioritise task
* Provides user with instructions to prioritise task.
*/
public void priorityInstruction() {
System.out.println("Enter task index followed by priority (high, medium, low)");
System.out.println("\te.g. 1 high");
}

/**
* Notifies the user that their task's priority has been set
* Notifies the user that their task's priority has been set.
*/
public void prioritySet() {
System.out.println("Your task's priority has been set");
}

/**
* Prompt user to enter the second index
* Prompt user to enter the second index.
*/
public void promptSecondIndex() {
System.out.println("Please enter the index to swap to");
Expand All @@ -237,8 +236,8 @@ public void showReordering() {
}

void helpList() {
System.out.println("Here are a list of commands you can input: " +
"\n add " + "\n delete " + "\n list " + "\n done "
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 "
Expand Down
49 changes: 24 additions & 25 deletions src/main/java/RoomShare.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ public void run() throws RoomShareException, IOException, InterruptedException {
case overdue:
Ui.clearScreen();
ui.startUp();
listRoutine.list();
ui.showOverdueList();
try {
overdueList.list();
Expand All @@ -362,8 +363,6 @@ public void run() throws RoomShareException, IOException, InterruptedException {
} catch (RoomShareException e) {
ui.showError(e);
}

listRoutine.list();
break;

case reschedule:
Expand All @@ -389,47 +388,47 @@ public void run() throws RoomShareException, IOException, InterruptedException {
case show:
Ui.clearScreen();
ui.startUp();
String input = parser.getCommandLine().trim();
if (input.equals("deleted")) {
ui.showDeletedList();
try {
tempDeleteList.list();
} catch (RoomShareException e) {
ui.showError(e);
}
storage.writeFile(TaskList.currentList(), "data.txt");
storage.writeFile(OverdueList.getOverdueList(), "overdue.txt");
listRoutine.list();
} else {
ui.showTagged(input);
try {
try {
String input = parser.getCommandLine().trim();
if (input.equals("deleted")) {
ui.showDeletedList();
try {
tempDeleteList.list();
} catch (RoomShareException e) {
ui.showError(e);
}
listRoutine.list();
} else {
ui.showTagged(input);
int[] doneArray = taskList.listTagged(input);
ui.showTaggedPercentage(input);
ProgressBar progressBar = new ProgressBar(doneArray[0], doneArray[1]);
ui.showBar(progressBar.showBar());
storage.writeFile(TaskList.currentList(), "data.txt");
storage.writeFile(OverdueList.getOverdueList(), "overdue.txt");
} catch (RoomShareException e) {
ui.showError(e);
}
} catch (RoomShareException e) {
ui.showError(e);
} finally {
storage.writeFile(TaskList.currentList(), "data.txt");
storage.writeFile(OverdueList.getOverdueList(), "overdue.txt");
}
break;

case reopen:
Ui.clearScreen();
String userInput = parser.getCommandLine();
ui.showDoneList();
taskList.showCompleted();
ui.startUp();
try {
int index = parser.getIndex(userInput);
ArrayList<Date> date = taskCreator.extractDate(userInput);
String input = parser.getCommandLine();
int index = parser.getIndex(input);
ArrayList<Date> date = taskCreator.extractDate(input);
taskList.reopen(index,date.get(0));
} catch (RoomShareException e) {
ui.showError(e);
}
storage.writeFile(TaskList.currentList(), "data.txt");
storage.writeFile(OverdueList.getOverdueList(), "overdue.txt");
listRoutine.list();
ui.showDoneList();
taskList.showCompleted();
break;

default:
Expand Down

0 comments on commit 6a443cd

Please sign in to comment.