From 9b1b1af523a30fb8fff6b904f1fcfca4d1493749 Mon Sep 17 00:00:00 2001 From: suriruhani Date: Tue, 12 Feb 2019 22:00:15 +0800 Subject: [PATCH 1/8] Add HistoryCommand class: AB ignores the command and prints testing msg --- .../addressbook/commands/HistoryCommand.java | 17 +++++++++++++++++ src/seedu/addressbook/parser/Parser.java | 4 ++++ 2 files changed, 21 insertions(+) create mode 100644 src/seedu/addressbook/commands/HistoryCommand.java diff --git a/src/seedu/addressbook/commands/HistoryCommand.java b/src/seedu/addressbook/commands/HistoryCommand.java new file mode 100644 index 000000000..b4ff7e80f --- /dev/null +++ b/src/seedu/addressbook/commands/HistoryCommand.java @@ -0,0 +1,17 @@ +package seedu.addressbook.commands; + + +public class HistoryCommand extends Command{ + + public static final String COMMAND_WORD = "history"; + public static final String MESSAGE_USAGE = "Shows all the commands history in reverse chronological order.\n" + + "Example: " + COMMAND_WORD; + + public static final String MESSAGE_SUCCESS = "Displaying all commands!"; + + @Override + public CommandResult execute() { + System.out.println("Testing history command"); + return new CommandResult(MESSAGE_SUCCESS); + } +} diff --git a/src/seedu/addressbook/parser/Parser.java b/src/seedu/addressbook/parser/Parser.java index abddb3f45..ce9d2ac4b 100644 --- a/src/seedu/addressbook/parser/Parser.java +++ b/src/seedu/addressbook/parser/Parser.java @@ -22,6 +22,7 @@ import seedu.addressbook.commands.ListCommand; import seedu.addressbook.commands.ViewAllCommand; import seedu.addressbook.commands.ViewCommand; +import seedu.addressbook.commands.HistoryCommand; import seedu.addressbook.data.exception.IllegalValueException; /** @@ -73,6 +74,9 @@ public Command parseCommand(String userInput) { switch (commandWord) { + case HistoryCommand.COMMAND_WORD: + return new HistoryCommand(); + case AddCommand.COMMAND_WORD: return prepareAdd(arguments); From 34241ae00a72303f242b1627690a11ed356d0f44 Mon Sep 17 00:00:00 2001 From: suriruhani Date: Tue, 12 Feb 2019 22:05:38 +0800 Subject: [PATCH 2/8] Add public static Stack CommandHistory to track all commands; commands pushed to stack when entered by user --- src/seedu/addressbook/Main.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/seedu/addressbook/Main.java b/src/seedu/addressbook/Main.java index bc18bed7e..181199268 100644 --- a/src/seedu/addressbook/Main.java +++ b/src/seedu/addressbook/Main.java @@ -3,6 +3,7 @@ import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.Stack; import seedu.addressbook.commands.Command; import seedu.addressbook.commands.CommandResult; @@ -24,7 +25,7 @@ public class Main { /** Version info of the program. */ public static final String VERSION = "AddressBook Level 2 - Version 1.0"; - + public static Stack CommandHistory = new Stack<>(); private TextUi ui; private StorageFile storage; private AddressBook addressBook; @@ -83,6 +84,7 @@ private void runCommandLoopUntilExitCommand() { Command command; do { String userCommandText = ui.getUserCommand(); + CommandHistory.push(userCommandText); command = new Parser().parseCommand(userCommandText); CommandResult result = executeCommand(command); recordResult(result); From 637e76e7709583a5c5d1ecc96dcc2e4dd1e4266c Mon Sep 17 00:00:00 2001 From: suriruhani Date: Tue, 12 Feb 2019 22:27:19 +0800 Subject: [PATCH 3/8] Add logic of HistoryCommand --- src/seedu/addressbook/commands/HistoryCommand.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/seedu/addressbook/commands/HistoryCommand.java b/src/seedu/addressbook/commands/HistoryCommand.java index b4ff7e80f..0481f9189 100644 --- a/src/seedu/addressbook/commands/HistoryCommand.java +++ b/src/seedu/addressbook/commands/HistoryCommand.java @@ -1,17 +1,24 @@ package seedu.addressbook.commands; +import java.util.Stack; + +import static seedu.addressbook.Main.CommandHistory; + public class HistoryCommand extends Command{ public static final String COMMAND_WORD = "history"; public static final String MESSAGE_USAGE = "Shows all the commands history in reverse chronological order.\n" + "Example: " + COMMAND_WORD; - public static final String MESSAGE_SUCCESS = "Displaying all commands!"; + public static final String MESSAGE_SUCCESS = "Displaying all past commands!"; @Override public CommandResult execute() { - System.out.println("Testing history command"); + Stack CHCopy = CommandHistory; + while (!CHCopy.empty()) { + System.out.println("|| " + CHCopy.pop()); + } return new CommandResult(MESSAGE_SUCCESS); } } From 77074079ecab088a4eb154fa17854ddc314dcea5 Mon Sep 17 00:00:00 2001 From: suriruhani Date: Tue, 12 Feb 2019 22:33:47 +0800 Subject: [PATCH 4/8] Refactored --- src/seedu/addressbook/commands/HistoryCommand.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/seedu/addressbook/commands/HistoryCommand.java b/src/seedu/addressbook/commands/HistoryCommand.java index 0481f9189..908f968cc 100644 --- a/src/seedu/addressbook/commands/HistoryCommand.java +++ b/src/seedu/addressbook/commands/HistoryCommand.java @@ -5,6 +5,9 @@ import static seedu.addressbook.Main.CommandHistory; +/** + * Displays all the past commands inputted by the user. + */ public class HistoryCommand extends Command{ public static final String COMMAND_WORD = "history"; From 944e3335137044b0c4066d2806e5ffa2f03f4c37 Mon Sep 17 00:00:00 2001 From: suriruhani Date: Tue, 12 Feb 2019 23:09:22 +0800 Subject: [PATCH 5/8] Update user guide --- docs/UserGuide.adoc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index 4abb17e3e..9e676c22d 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -111,6 +111,22 @@ Deletes the 2nd person in the address book. `delete 1` + Deletes the 1st person in the results of the `find` command. +== Listing all previous commands: `history` + +Displays all user entered commands in reverse chronological order. + +Format: `history` + +**** +Shows all previous commands, with the latest ones first. +**** + +Examples: + +* `history` + +`delete 2` + +`list` + + == View non-private details of a person : `view` Displays the non-private details of the specified person. + From f4e043404b45bbc5eab8e5679e092198564f6965 Mon Sep 17 00:00:00 2001 From: suriruhani Date: Tue, 12 Feb 2019 23:31:23 +0800 Subject: [PATCH 6/8] Update help command to include history command --- src/seedu/addressbook/commands/HelpCommand.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/seedu/addressbook/commands/HelpCommand.java b/src/seedu/addressbook/commands/HelpCommand.java index 9be217d89..2adef8f86 100644 --- a/src/seedu/addressbook/commands/HelpCommand.java +++ b/src/seedu/addressbook/commands/HelpCommand.java @@ -23,6 +23,7 @@ public CommandResult execute() { + "\n" + ViewAllCommand.MESSAGE_USAGE + "\n" + HelpCommand.MESSAGE_USAGE + "\n" + ExitCommand.MESSAGE_USAGE + + "\n" + HistoryCommand.MESSAGE_USAGE ); } } From 19933d92f8ca721a0333587bdc625b4f8dd95b28 Mon Sep 17 00:00:00 2001 From: suriruhani Date: Tue, 12 Feb 2019 23:37:48 +0800 Subject: [PATCH 7/8] Update IO tests --- test/expected.txt | 7 +++++++ test/input.txt | 1 + 2 files changed, 8 insertions(+) diff --git a/test/expected.txt b/test/expected.txt index 56fe5fcac..4cbe66d85 100644 --- a/test/expected.txt +++ b/test/expected.txt @@ -29,6 +29,13 @@ || Example: help || exit: Exits the program. || Example: exit +|| Shows all the commands history in reverse chronological order. +|| Example: history +|| =================================================== +|| Enter command: || [Command entered: history] +|| history +|| sfdfd +|| Displaying all past commands! || =================================================== || Enter command: || [Command entered: delete 1] || The person index provided is invalid diff --git a/test/input.txt b/test/input.txt index eb8df81f8..70acc8eb8 100644 --- a/test/input.txt +++ b/test/input.txt @@ -4,6 +4,7 @@ # should recognise invalid command sfdfd + history ########################################################## # commands using list index before any listing created From 912ee452e149c3dad5ff78cc090454c74dfa7d6e Mon Sep 17 00:00:00 2001 From: suriruhani Date: Fri, 15 Feb 2019 14:34:54 +0800 Subject: [PATCH 8/8] Change CommandHistory stack to private in main and other minor bug fixes --- src/seedu/addressbook/Main.java | 4 +++- src/seedu/addressbook/commands/HistoryCommand.java | 8 +++++--- src/seedu/addressbook/parser/Parser.java | 11 +++++------ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/seedu/addressbook/Main.java b/src/seedu/addressbook/Main.java index 181199268..03998ac0c 100644 --- a/src/seedu/addressbook/Main.java +++ b/src/seedu/addressbook/Main.java @@ -85,7 +85,9 @@ private void runCommandLoopUntilExitCommand() { do { String userCommandText = ui.getUserCommand(); CommandHistory.push(userCommandText); - command = new Parser().parseCommand(userCommandText); + Parser parser = new Parser(); + parser.CHStack = CommandHistory; + command = parser.parseCommand(userCommandText); CommandResult result = executeCommand(command); recordResult(result); ui.showResultToUser(result); diff --git a/src/seedu/addressbook/commands/HistoryCommand.java b/src/seedu/addressbook/commands/HistoryCommand.java index 908f968cc..709050a8a 100644 --- a/src/seedu/addressbook/commands/HistoryCommand.java +++ b/src/seedu/addressbook/commands/HistoryCommand.java @@ -3,12 +3,12 @@ import java.util.Stack; -import static seedu.addressbook.Main.CommandHistory; +//import static seedu.addressbook.Main.CommandHistory; /** * Displays all the past commands inputted by the user. */ -public class HistoryCommand extends Command{ +public class HistoryCommand extends Command { public static final String COMMAND_WORD = "history"; public static final String MESSAGE_USAGE = "Shows all the commands history in reverse chronological order.\n" @@ -16,9 +16,11 @@ public class HistoryCommand extends Command{ public static final String MESSAGE_SUCCESS = "Displaying all past commands!"; + public static Stack CommandHistory; + @Override public CommandResult execute() { - Stack CHCopy = CommandHistory; + Stack CHCopy = (Stack) CommandHistory.clone(); while (!CHCopy.empty()) { System.out.println("|| " + CHCopy.pop()); } diff --git a/src/seedu/addressbook/parser/Parser.java b/src/seedu/addressbook/parser/Parser.java index ce9d2ac4b..f3be533e3 100644 --- a/src/seedu/addressbook/parser/Parser.java +++ b/src/seedu/addressbook/parser/Parser.java @@ -3,11 +3,7 @@ import static seedu.addressbook.common.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.addressbook.common.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -42,6 +38,7 @@ public class Parser { + " (?p?)a/(?
[^/]+)" + "(?(?: t/[^/]+)*)"); // variable number of tags + public static Stack CHStack; /** * Signals that the user input could not be parsed. @@ -75,7 +72,9 @@ public Command parseCommand(String userInput) { switch (commandWord) { case HistoryCommand.COMMAND_WORD: - return new HistoryCommand(); + HistoryCommand hcexecute = new HistoryCommand(); + hcexecute.CommandHistory = CHStack; + return hcexecute; case AddCommand.COMMAND_WORD: return prepareAdd(arguments);