diff --git a/src/main/java/duchess/logic/commands/ReminderCommand.java b/src/main/java/duchess/logic/commands/ReminderCommand.java index b185d5fa9b..5260e5fec2 100644 --- a/src/main/java/duchess/logic/commands/ReminderCommand.java +++ b/src/main/java/duchess/logic/commands/ReminderCommand.java @@ -8,7 +8,9 @@ import duchess.ui.Ui; import java.util.ArrayList; +import java.util.Collection; import java.util.List; +import java.util.stream.Collectors; /** * Searches Tasklist and filters out deadline objects. @@ -36,13 +38,10 @@ public void execute(TaskList taskList, Ui ui, Storage storage) throws DukeExcept * @param taskList of user inputs */ private List addDeadlines(TaskList taskList) { - ArrayList reminderList = new ArrayList<>(); - for (Task task : taskList.getTasks()) { - if (task instanceof Deadline) { - reminderList.add(task); - } - } - return reminderList; + return taskList.getTasks().stream() + .map(task -> task.getReminders()) + .flatMap(Collection::stream) + .collect(Collectors.toList()); } /** diff --git a/src/main/java/duchess/model/task/Deadline.java b/src/main/java/duchess/model/task/Deadline.java index 0320cf3b72..2ab3c84fc9 100644 --- a/src/main/java/duchess/model/task/Deadline.java +++ b/src/main/java/duchess/model/task/Deadline.java @@ -5,6 +5,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -50,6 +51,13 @@ public void snooze() { deadline.setTime(date.getTimeInMillis()); } + @Override + public List getReminders() { + List list = new ArrayList<>(); + list.add(this); + return list; + } + @Override public String toString() { return String.format("[D]%s %s (by: %s)", super.toString(), this.description, formatter.format(this.deadline)); diff --git a/src/main/java/duchess/model/task/Event.java b/src/main/java/duchess/model/task/Event.java index c1c6945b27..209af34ce9 100644 --- a/src/main/java/duchess/model/task/Event.java +++ b/src/main/java/duchess/model/task/Event.java @@ -5,6 +5,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -91,6 +92,11 @@ public void snooze() { end.setTime(date.getTimeInMillis()); } + @Override + public List getReminders() { + return new ArrayList<>(); + } + @Override public String toString() { return String.format("[E]%s %s (at: %s to %s)", super.toString(), this.description, diff --git a/src/main/java/duchess/model/task/Task.java b/src/main/java/duchess/model/task/Task.java index 5bea4c867c..ef7879f15e 100644 --- a/src/main/java/duchess/model/task/Task.java +++ b/src/main/java/duchess/model/task/Task.java @@ -5,6 +5,7 @@ import java.io.Serializable; import java.util.Date; +import java.util.List; public abstract class Task implements Serializable { private boolean isDone; @@ -27,4 +28,6 @@ public String toString() { public abstract Schedule isWithinTimeFrame(Date startDate, Date endDate); public abstract void snooze() throws DukeException; + + public abstract List getReminders(); } diff --git a/src/main/java/duchess/model/task/Todo.java b/src/main/java/duchess/model/task/Todo.java index 9b2c19f8b4..58a740e2d7 100644 --- a/src/main/java/duchess/model/task/Todo.java +++ b/src/main/java/duchess/model/task/Todo.java @@ -3,6 +3,7 @@ import duchess.logic.commands.exceptions.DukeException; import duchess.model.Schedule; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -41,4 +42,9 @@ public Schedule isWithinTimeFrame(Date startDate, Date endDate) { public void snooze() throws DukeException { throw new DukeException("You can't snooze that task."); } + + @Override + public List getReminders() { + return new ArrayList<>(); + } }