From a48c1fc568798f562131fd650e2714b0725d21f4 Mon Sep 17 00:00:00 2001 From: muserr <42793613+muserr@users.noreply.github.com> Date: Fri, 4 Oct 2019 10:09:42 +0800 Subject: [PATCH] Includes history log V1.0 (#69) * Remove instanceof from ReminderCommand * Updates to ReminderCommand V1.0 * Sorts reminders in ascending order * Includes Event as part of reminder display * Merges with upstream * Changes to Indent Case * Changes to switch case alignment * Includes history log V1.0 * Includes history log V1.1 --- .gitignore | 1 + data.json | 4 +++- src/main/java/Duke.java | 6 +++++- .../logic/commands/AddDeadlineCommand.java | 1 - .../logic/commands/AddEventCommand.java | 1 - .../logic/commands/AddTodoCommand.java | 1 - .../duchess/logic/commands/ByeCommand.java | 1 - .../java/duchess/logic/commands/Command.java | 2 +- .../duchess/logic/commands/DeleteCommand.java | 1 - .../duchess/logic/commands/DoneCommand.java | 1 - .../duchess/logic/commands/FindCommand.java | 1 - .../duchess/logic/commands/ListCommand.java | 1 - .../duchess/logic/commands/LogCommand.java | 18 +++++++++++++++++ .../duchess/logic/commands/SnoozeCommand.java | 1 - .../logic/commands/ViewScheduleCommand.java | 1 - .../java/duchess/logic/parser/Parser.java | 3 +++ .../java/duchess/model/task/DuchessLog.java | 20 +++++++++++++++++++ src/main/java/duchess/ui/Ui.java | 14 +++++++++++++ src/test/java/ReminderCommandTest.java | 4 +++- 19 files changed, 68 insertions(+), 14 deletions(-) create mode 100644 src/main/java/duchess/logic/commands/LogCommand.java create mode 100644 src/main/java/duchess/model/task/DuchessLog.java diff --git a/.gitignore b/.gitignore index 03ea54b870..c010949308 100644 --- a/.gitignore +++ b/.gitignore @@ -15,5 +15,6 @@ bin/ # Data files data.json +/data.json text_file diff --git a/data.json b/data.json index f20a130863..2856e9c60f 100644 --- a/data.json +++ b/data.json @@ -1 +1,3 @@ -["duchess.model.task.TaskList",{"tasks":["java.util.ArrayList",[]]}] \ No newline at end of file +[ "duchess.storage.Store", { + "taskList" : [ "java.util.ArrayList", [ [ "duchess.model.task.Todo", { + "description" : "work" \ No newline at end of file diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java index a61b07eeb0..13bf3df014 100644 --- a/src/main/java/Duke.java +++ b/src/main/java/Duke.java @@ -1,16 +1,17 @@ import duchess.logic.commands.Command; import duchess.logic.parser.Parser; +import duchess.model.task.DuchessLog; import duchess.storage.Storage; import duchess.storage.Store; import duchess.ui.Ui; import duchess.logic.commands.exceptions.DukeException; -import duchess.model.task.TaskList; public class Duke { private Storage storage; private Store store; private Ui ui; + private DuchessLog duchessLog; /** * Creates an instant of Duke to be executed. @@ -34,10 +35,13 @@ private Duke(String filePath) { */ private void run() { ui.showWelcome(); + duchessLog = new DuchessLog(); + boolean isExit = false; while (!isExit) { try { String fullCommand = ui.readCommand(); + duchessLog.add(fullCommand); ui.beginBlock(); Command c = Parser.parse(fullCommand); c.execute(store, ui, storage); diff --git a/src/main/java/duchess/logic/commands/AddDeadlineCommand.java b/src/main/java/duchess/logic/commands/AddDeadlineCommand.java index 8a516f09e8..3f32c40c0a 100644 --- a/src/main/java/duchess/logic/commands/AddDeadlineCommand.java +++ b/src/main/java/duchess/logic/commands/AddDeadlineCommand.java @@ -1,7 +1,6 @@ package duchess.logic.commands; import duchess.storage.Storage; -import duchess.model.task.TaskList; import duchess.model.task.Task; import duchess.model.task.Deadline; import duchess.logic.commands.exceptions.DukeException; diff --git a/src/main/java/duchess/logic/commands/AddEventCommand.java b/src/main/java/duchess/logic/commands/AddEventCommand.java index 9965c77866..8386399dc7 100644 --- a/src/main/java/duchess/logic/commands/AddEventCommand.java +++ b/src/main/java/duchess/logic/commands/AddEventCommand.java @@ -3,7 +3,6 @@ import duchess.storage.Storage; import duchess.logic.commands.exceptions.DukeException; import duchess.model.task.Event; -import duchess.model.task.TaskList; import duchess.storage.Store; import duchess.ui.Ui; diff --git a/src/main/java/duchess/logic/commands/AddTodoCommand.java b/src/main/java/duchess/logic/commands/AddTodoCommand.java index cc727d64eb..01c133d56a 100644 --- a/src/main/java/duchess/logic/commands/AddTodoCommand.java +++ b/src/main/java/duchess/logic/commands/AddTodoCommand.java @@ -1,7 +1,6 @@ package duchess.logic.commands; import duchess.storage.Storage; -import duchess.model.task.TaskList; import duchess.model.task.Todo; import duchess.model.task.Task; import duchess.logic.commands.exceptions.DukeException; diff --git a/src/main/java/duchess/logic/commands/ByeCommand.java b/src/main/java/duchess/logic/commands/ByeCommand.java index c4f366458c..d217860b1d 100644 --- a/src/main/java/duchess/logic/commands/ByeCommand.java +++ b/src/main/java/duchess/logic/commands/ByeCommand.java @@ -1,7 +1,6 @@ package duchess.logic.commands; import duchess.storage.Storage; -import duchess.model.task.TaskList; import duchess.logic.commands.exceptions.DukeException; import duchess.storage.Store; import duchess.ui.Ui; diff --git a/src/main/java/duchess/logic/commands/Command.java b/src/main/java/duchess/logic/commands/Command.java index 41873275f5..db99cee5ef 100644 --- a/src/main/java/duchess/logic/commands/Command.java +++ b/src/main/java/duchess/logic/commands/Command.java @@ -13,4 +13,4 @@ public boolean isExit() { } public abstract void execute(Store store, Ui ui, Storage storage) throws DukeException; -} +} \ No newline at end of file diff --git a/src/main/java/duchess/logic/commands/DeleteCommand.java b/src/main/java/duchess/logic/commands/DeleteCommand.java index 178d971361..db3e7dbf51 100644 --- a/src/main/java/duchess/logic/commands/DeleteCommand.java +++ b/src/main/java/duchess/logic/commands/DeleteCommand.java @@ -1,7 +1,6 @@ package duchess.logic.commands; import duchess.storage.Storage; -import duchess.model.task.TaskList; import duchess.model.task.Task; import duchess.logic.commands.exceptions.DukeException; import duchess.storage.Store; diff --git a/src/main/java/duchess/logic/commands/DoneCommand.java b/src/main/java/duchess/logic/commands/DoneCommand.java index 8b8d310f3f..11d0f9707a 100644 --- a/src/main/java/duchess/logic/commands/DoneCommand.java +++ b/src/main/java/duchess/logic/commands/DoneCommand.java @@ -1,7 +1,6 @@ package duchess.logic.commands; import duchess.storage.Storage; -import duchess.model.task.TaskList; import duchess.logic.commands.exceptions.DukeException; import duchess.model.task.Task; import duchess.storage.Store; diff --git a/src/main/java/duchess/logic/commands/FindCommand.java b/src/main/java/duchess/logic/commands/FindCommand.java index 4eab4395e4..f91fdcdfc9 100644 --- a/src/main/java/duchess/logic/commands/FindCommand.java +++ b/src/main/java/duchess/logic/commands/FindCommand.java @@ -2,7 +2,6 @@ import duchess.storage.Storage; import duchess.model.task.Task; -import duchess.model.task.TaskList; import duchess.logic.commands.exceptions.DukeException; import duchess.storage.Store; import duchess.ui.Ui; diff --git a/src/main/java/duchess/logic/commands/ListCommand.java b/src/main/java/duchess/logic/commands/ListCommand.java index ab6606f0ce..a1c2528e69 100644 --- a/src/main/java/duchess/logic/commands/ListCommand.java +++ b/src/main/java/duchess/logic/commands/ListCommand.java @@ -2,7 +2,6 @@ import duchess.storage.Storage; import duchess.logic.commands.exceptions.DukeException; -import duchess.model.task.TaskList; import duchess.storage.Store; import duchess.ui.Ui; diff --git a/src/main/java/duchess/logic/commands/LogCommand.java b/src/main/java/duchess/logic/commands/LogCommand.java new file mode 100644 index 0000000000..06de1e2acf --- /dev/null +++ b/src/main/java/duchess/logic/commands/LogCommand.java @@ -0,0 +1,18 @@ +package duchess.logic.commands; + +import duchess.logic.commands.exceptions.DukeException; +import duchess.model.task.DuchessLog; +import duchess.storage.Storage; +import duchess.storage.Store; +import duchess.ui.Ui; + +/** + * Command to display input history. + */ +public class LogCommand extends Command { + + @Override + public void execute(Store store, Ui ui, Storage storage) throws DukeException { + ui.showUserHistory(DuchessLog.getLog()); + } +} diff --git a/src/main/java/duchess/logic/commands/SnoozeCommand.java b/src/main/java/duchess/logic/commands/SnoozeCommand.java index af871dae6c..a0e9541ec0 100644 --- a/src/main/java/duchess/logic/commands/SnoozeCommand.java +++ b/src/main/java/duchess/logic/commands/SnoozeCommand.java @@ -3,7 +3,6 @@ import duchess.storage.Storage; import duchess.logic.commands.exceptions.DukeException; import duchess.model.task.Task; -import duchess.model.task.TaskList; import duchess.storage.Store; import duchess.ui.Ui; diff --git a/src/main/java/duchess/logic/commands/ViewScheduleCommand.java b/src/main/java/duchess/logic/commands/ViewScheduleCommand.java index ccac5266de..bfc9d6c4c2 100644 --- a/src/main/java/duchess/logic/commands/ViewScheduleCommand.java +++ b/src/main/java/duchess/logic/commands/ViewScheduleCommand.java @@ -3,7 +3,6 @@ import duchess.logic.commands.exceptions.DukeException; import duchess.model.TimeFrame; import duchess.model.task.Task; -import duchess.model.task.TaskList; import duchess.storage.Storage; import duchess.storage.Store; import duchess.ui.Ui; diff --git a/src/main/java/duchess/logic/parser/Parser.java b/src/main/java/duchess/logic/parser/Parser.java index 5217753d40..ee41559f02 100644 --- a/src/main/java/duchess/logic/parser/Parser.java +++ b/src/main/java/duchess/logic/parser/Parser.java @@ -9,6 +9,7 @@ import duchess.logic.commands.DoneCommand; import duchess.logic.commands.FindCommand; import duchess.logic.commands.ListCommand; +import duchess.logic.commands.LogCommand; import duchess.logic.commands.ReminderCommand; import duchess.logic.commands.SnoozeCommand; import duchess.logic.commands.ViewScheduleCommand; @@ -53,6 +54,8 @@ public static Command parse(String input) throws DukeException { return new ViewScheduleCommand(arguments); case "bye": return new ByeCommand(); + case "log": + return new LogCommand(); default: throw new DukeException("Please enter a valid command."); } diff --git a/src/main/java/duchess/model/task/DuchessLog.java b/src/main/java/duchess/model/task/DuchessLog.java new file mode 100644 index 0000000000..a7708d53b5 --- /dev/null +++ b/src/main/java/duchess/model/task/DuchessLog.java @@ -0,0 +1,20 @@ +package duchess.model.task; + +import java.util.ArrayList; +import java.util.List; + +public class DuchessLog { + private static List duchessLog; + + public DuchessLog() { + duchessLog = new ArrayList<>(); + } + + public void add(String input) { + duchessLog.add(input); + } + + public static List getLog() { + return duchessLog; + } +} diff --git a/src/main/java/duchess/ui/Ui.java b/src/main/java/duchess/ui/Ui.java index 2d14454af4..2bb11451fb 100644 --- a/src/main/java/duchess/ui/Ui.java +++ b/src/main/java/duchess/ui/Ui.java @@ -1,6 +1,7 @@ package duchess.ui; +import duchess.logic.commands.Command; import duchess.model.task.Task; import java.util.List; @@ -197,6 +198,19 @@ public void showDeadlines(List tasks) { showTasks(tasks); } + /** + * Displays user history. + * + * @param log list of user log + */ + public void showUserHistory(List log) { + printIndented("These are the commands you entered:"); + int counter = 1; + for (String userInput : log) { + printIndented(counter++ + ". " + userInput); + } + } + /** * Prints a straight line. */ diff --git a/src/test/java/ReminderCommandTest.java b/src/test/java/ReminderCommandTest.java index ceb8130b5e..9f4e83aef8 100644 --- a/src/test/java/ReminderCommandTest.java +++ b/src/test/java/ReminderCommandTest.java @@ -1,6 +1,7 @@ import duchess.logic.commands.AddDeadlineCommand; import duchess.logic.commands.ReminderCommand; import duchess.logic.parser.Parser; +import duchess.model.task.DuchessLog; import duchess.storage.Storage; import duchess.storage.Store; import duchess.ui.Ui; @@ -38,6 +39,7 @@ public void testExecuteWithDeadlines() throws DukeException { Ui ui = new Ui(); Storage storage = new Storage(filename); Parser parser = new Parser(); + DuchessLog duchessLog = new DuchessLog(); // Adding the firstDeadline List firstWords = Arrays.asList(firstDeadline.split(" ")); @@ -53,4 +55,4 @@ public void testExecuteWithDeadlines() throws DukeException { assertTrue(store.getTaskList().size() == 2); ReminderCommand reminderCommand = new ReminderCommand(); } -} +} \ No newline at end of file