Skip to content

Commit

Permalink
Merge pull request #211 from tyeryan/master
Browse files Browse the repository at this point in the history
Updated overdue and automatic removal of leave
  • Loading branch information
tyeryan authored Nov 7, 2019
2 parents a10183d + 97c505c commit d6bf73c
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main/java/Enums/TaskType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public enum TaskType {
list, bye, find, done , delete, time, snooze, others, help, priority, reorder,
restore, add, subtask, update, sort, log, overdue, reschedule, completed, show, deleted
restore, add, subtask, update, sort, log, overdue, reschedule, completed, show, deleted, remove
}
22 changes: 22 additions & 0 deletions src/main/java/Operations/OverdueList.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import Enums.ExceptionType;
import Model_Classes.Assignment;
import Model_Classes.Task;
import Enums.TaskType;


import java.util.ArrayList;

Expand Down Expand Up @@ -82,4 +84,24 @@ public Task get(int index) throws RoomShareException{
throw new RoomShareException(ExceptionType.outOfBounds);
}
}

public void remove(int[] index, TempDeleteList deletedList) throws RoomShareException {
int[] idx = index.clone();
if (idx.length == 1) {
if (idx[0] < 0 || idx[0] >= Overdue.size()) {
throw new RoomShareException(ExceptionType.outOfBounds);
}
deletedList.add(Overdue.get(idx[0]));
Overdue.remove(idx[0]);
}
else {
if (idx[0] < 0 || idx[0] >= Overdue.size() || idx[1] < 0 || idx[1] >= Overdue.size()) {
throw new RoomShareException(ExceptionType.outOfBounds);
}
for (int i = idx[0]; idx[1] >= idx[0]; idx[1]--) {
deletedList.add(Overdue.get(i));
Overdue.remove(i);
}
}
}
}
25 changes: 17 additions & 8 deletions src/main/java/Operations/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class TaskList {
private static ArrayList<Task> tasks;
private static SortType sortType = SortType.priority;
public ArrayList<Task> overdueList = new ArrayList<>();
public static ArrayList<Task> overdueList = new ArrayList<>();

/**
* Constructor for the TaskList class.
Expand Down Expand Up @@ -65,6 +65,7 @@ public void delete(int[] index, TempDeleteList deletedList) throws RoomShareExce
}
}
}

/**
* Lists out all tasks in the current list in the order they were added into the list.
* shows all information related to the tasks
Expand All @@ -78,8 +79,8 @@ public void list() throws RoomShareException {
for(int i=0; i<tasks.size(); i++) {
if (new Date().after(tasks.get(i).getDate())) {
tasks.get(i).setOverdue(true);
this.overdueList.add(tasks.get(i));
tasks.remove(i);
overdueList.add(tasks.get(i));
tasks.remove(tasks.get(i));
}
}

Expand Down Expand Up @@ -107,6 +108,13 @@ public void list() throws RoomShareException {
listCount += 1;
}
}
for(int i=0; i<tasks.size(); i++) {
if (tasks.get(i) instanceof Leave) {
if (((Leave) tasks.get(i)).getEndDate().after(new Date())) {
tasks.remove(tasks.get(i));
}
}
}
} else {
throw new RoomShareException(ExceptionType.emptyList);
}
Expand Down Expand Up @@ -144,17 +152,18 @@ public void showCompleted() throws RoomShareException {
* @return ArrayList of tasks containing tasks that are overdue.
* @throws RoomShareException when the list is empty.
*/
public ArrayList<Task> getOverdueList() throws RoomShareException {
public static ArrayList<Task> getOverdueList() throws RoomShareException {
if( tasks.size() != 0 ){
for (Task output : tasks) {
if(new Date().after(output.getDate())) {
this.overdueList.add(output);
for (int i=0; i<tasks.size(); i++) {
if(new Date().after(tasks.get(i).getDate())) {
overdueList.add(tasks.get(i));
tasks.remove(tasks.get(i));
}
}
} else {
throw new RoomShareException(ExceptionType.emptyList);
}
return this.overdueList;
return overdueList;
}

/**
Expand Down
45 changes: 37 additions & 8 deletions src/main/java/RoomShare.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public RoomShare() throws RoomShareException {
taskList = new TaskList(emptyList);
}
try {
ArrayList<Task> overdueAL;
overdueAL = TaskList.getOverdueList();
overdueList = new OverdueList(storage.loadFile("overdue.txt"));
} catch (RoomShareException e) {
ui.showError(e);
Expand Down Expand Up @@ -90,6 +92,11 @@ public void run() throws RoomShareException, IOException, InterruptedException {
} catch (RoomShareException e) {
ui.showError(e);
}
try {
storage.writeFile(TaskList.getOverdueList(), "overdue.txt");
} catch (RoomShareException e) {
ui.showError(e);
}
parser.close();
ui.showBye();
break;
Expand Down Expand Up @@ -132,6 +139,21 @@ public void run() throws RoomShareException, IOException, InterruptedException {
listRoutine.list();
break;

case remove:
Ui.clearScreen();
ui.startUp();
try {
String input = parser.getCommandLine();
int[] index = parser.getIndexRange(input);
overdueList.remove(index, tempDeleteList);
ui.showDeleted(index);
storage.writeFile(TaskList.getOverdueList(), "overdue.txt");
} catch (RoomShareException e) {
ui.showError(e);
}
listRoutine.list();
break;

case restore:
Ui.clearScreen();
ui.startUp();
Expand Down Expand Up @@ -313,22 +335,19 @@ public void run() throws RoomShareException, IOException, InterruptedException {
case overdue:
Ui.clearScreen();
ui.startUp();
ArrayList<Task> overdueAL;
ui.showOverdueList();
try {
overdueAL = taskList.getOverdueList();
overdueList = new OverdueList(overdueAL);
storage.writeFile(overdueAL, "overdue.txt");
overdueList.list();
} catch (RoomShareException e) {
ui.showError(e);
ArrayList<Task> emptyList = new ArrayList<>();
overdueList = new OverdueList(emptyList);
}
ui.showOverdueList();
try {
overdueList.list();
overdueList = new OverdueList(TaskList.getOverdueList());
storage.writeFile(TaskList.getOverdueList(), "overdue.txt");
} catch (RoomShareException e) {
ui.showError(e);
}

listRoutine.list();
break;

Expand All @@ -348,6 +367,11 @@ public void run() throws RoomShareException, IOException, InterruptedException {
ui.showError(e);
storage.writeFile(TaskList.currentList(), "data.txt");
}
try {
storage.writeFile(TaskList.getOverdueList(), "overdue.txt");
} catch (RoomShareException e) {
ui.showError(e);
}
listRoutine.list();
break;

Expand Down Expand Up @@ -382,6 +406,11 @@ public void run() throws RoomShareException, IOException, InterruptedException {
listRoutine.list();
ui.showCommandError();
storage.writeFile(TaskList.currentList(), "data.txt");
try {
storage.writeFile(TaskList.getOverdueList(), "overdue.txt");
} catch (RoomShareException e) {
ui.showError(e);
}
break;
}
}
Expand Down

0 comments on commit d6bf73c

Please sign in to comment.