forked from nusCS2113-AY1920S1/PersonalAssistant-Duke
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from RusdiHaizim/branch-B-Reminders
[CS2113T-W13-2]-RusdiHaizim-B-Reminders
- Loading branch information
Showing
15 changed files
with
289 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
T|✓|eat food | ||
E|✗|event|now | ||
T|✗|eat | ||
D|✗|a|0600 9/15/2019 | ||
D|✗|b|0500 9/15/2019 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package duke.commands; | ||
|
||
import duke.Storage; | ||
import duke.TaskList; | ||
import duke.Ui; | ||
import duke.tasks.Task; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class ReminderCommand extends Command { | ||
|
||
@Override | ||
public void execute(TaskList tasks, Ui ui, Storage storage) { | ||
ArrayList<Task> deadlineList = new ArrayList<>(); | ||
for (Task task : tasks.getData()) { | ||
if (task.getTaskType() == Task.TaskType.DEADLINE) { | ||
deadlineList.add(task); | ||
} | ||
} | ||
deadlineList.sort((o1, o2) -> { | ||
if (o1.getDateTime() == null) { | ||
return 1; | ||
} else if (o2.getDateTime() == null) { | ||
return -1; | ||
} | ||
if (o1.getDateTime().before(o2.getDateTime())) { | ||
return -1; | ||
} else if (o1.getDateTime().after(o2.getDateTime())) { | ||
return 1; | ||
} | ||
return 0; | ||
}); | ||
int idx = 1; | ||
if (deadlineList.size() > 0) { | ||
ui.showMessage("Here are the upcoming Deadlines:"); | ||
for (Task task : deadlineList) { | ||
StringBuilder stringBuilder = new StringBuilder(); | ||
stringBuilder.append(idx++).append("."); | ||
stringBuilder.append(task.getFullString()); | ||
ui.showMessage(stringBuilder.toString()); | ||
} | ||
} else { | ||
ui.showError("Empty List!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,55 @@ | ||
import duke.DukeException; | ||
import duke.Parser; | ||
import duke.TaskList; | ||
import duke.commands.Command; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class DeadlineTest { | ||
private static final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); | ||
private static final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); | ||
private static final PrintStream originalOut = System.out; | ||
private static final PrintStream originalErr = System.err; | ||
|
||
@BeforeEach | ||
void setUpStreams() { | ||
System.setOut(new PrintStream(outContent)); | ||
System.setErr(new PrintStream(errContent)); | ||
} | ||
|
||
@AfterEach | ||
void restoreStreams() { | ||
outContent.reset(); | ||
System.setOut(originalOut); | ||
System.setErr(originalErr); | ||
} | ||
|
||
@Test | ||
public void test(String input) throws DukeException { | ||
void test(String input) throws DukeException { | ||
setUpStreams(); | ||
TaskList taskList = new TaskList(); | ||
Parser.runDeadline(taskList.getData(), input, 1); | ||
assertEquals(taskList.get(0).getFullString(), "[D][✗] test (by: 0000)"); | ||
Command c = Parser.parse(input); | ||
c.execute(taskList, DukeTest.ui, DukeTest.storage); | ||
String exp = "Got it. I've added this task: \n [D][✗] test (by: 0000)\nNow you have 1 tasks in the list."; | ||
assertEquals(exp, outContent.toString().trim()); | ||
restoreStreams(); | ||
} | ||
|
||
@Test | ||
public void examBy_Date(String input) throws DukeException { | ||
void examBy_Date(String input) throws DukeException { | ||
setUpStreams(); | ||
TaskList taskList = new TaskList(); | ||
Parser.runDeadline(taskList.getData(), input, 1); | ||
assertEquals(taskList.get(0).getFullString(), "[D][✗] exam (by: 01/01/2019)"); | ||
Command c = Parser.parse(input); | ||
c.execute(taskList, DukeTest.ui, DukeTest.storage); | ||
String exp = "Got it. I've added this task: \n [D][✗] exam (by: 01/01/2019)\nNow you have 1 tasks in the list."; | ||
assertEquals(exp, outContent.toString().trim()); | ||
restoreStreams(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.