From 74fd175d812b91a5e7f99d31f8f571718df7fca3 Mon Sep 17 00:00:00 2001 From: Inaba Kazuhiro Date: Sun, 6 Nov 2016 15:09:26 +0800 Subject: [PATCH 01/11] Populate help table --- .../seedu/taskman/ui/HelpTableViewRow.java | 32 ++++++++++++ .../java/seedu/taskman/ui/HelpWindow.java | 51 ++++++++++++++++++- src/main/resources/view/HelpWindow.fxml | 6 +-- 3 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 src/main/java/seedu/taskman/ui/HelpTableViewRow.java diff --git a/src/main/java/seedu/taskman/ui/HelpTableViewRow.java b/src/main/java/seedu/taskman/ui/HelpTableViewRow.java new file mode 100644 index 000000000000..1a2d531f59e0 --- /dev/null +++ b/src/main/java/seedu/taskman/ui/HelpTableViewRow.java @@ -0,0 +1,32 @@ +package seedu.taskman.ui; + +import javafx.beans.property.SimpleStringProperty; + +/** + * Controller for a help page + */ +public class HelpTableViewRow { + + private final SimpleStringProperty command; + private final SimpleStringProperty format; + + protected HelpTableViewRow(String command, String format) { + this.command = new SimpleStringProperty(command); + this.format = new SimpleStringProperty(format); + } + + public String getCommand() { + return command.get(); + } + public void setCommand(String command) { + this.command.set(command); + } + + public String getFormat() { + return format.get(); + } + public void setFormat(String format) { + this.format.set(format); + } + +} \ No newline at end of file diff --git a/src/main/java/seedu/taskman/ui/HelpWindow.java b/src/main/java/seedu/taskman/ui/HelpWindow.java index b9bede727e32..8f6be05ecfd1 100644 --- a/src/main/java/seedu/taskman/ui/HelpWindow.java +++ b/src/main/java/seedu/taskman/ui/HelpWindow.java @@ -1,16 +1,34 @@ package seedu.taskman.ui; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.MenuItem; +import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; +import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.input.KeyCombination; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.VBox; import javafx.scene.web.WebView; import javafx.stage.Stage; import seedu.taskman.commons.util.FxViewUtil; +import seedu.taskman.logic.commands.AddCommand; +import seedu.taskman.logic.commands.AddECommand; +import seedu.taskman.logic.commands.ClearCommand; +import seedu.taskman.logic.commands.CompleteCommand; +import seedu.taskman.logic.commands.DeleteCommand; +import seedu.taskman.logic.commands.EditCommand; +import seedu.taskman.logic.commands.ExitCommand; +import seedu.taskman.logic.commands.HelpCommand; +import seedu.taskman.logic.commands.HistoryCommand; +import seedu.taskman.logic.commands.ListCommand; +import seedu.taskman.logic.commands.SelectCommand; +import seedu.taskman.logic.commands.StoragelocCommand; +import seedu.taskman.logic.commands.TagsCommand; +import seedu.taskman.logic.commands.UndoCommand; import seedu.taskman.commons.core.LogsCenter; import seedu.taskman.commons.events.ui.ExitAppRequestEvent; @@ -23,6 +41,22 @@ public class HelpWindow extends UiPart { private static final Logger logger = LogsCenter.getLogger(HelpWindow.class); private static final String FXML = "HelpWindow.fxml"; + final ObservableList data = FXCollections.observableArrayList( + new HelpTableViewRow(AddCommand.COMMAND_WORD, AddCommand.MESSAGE_USAGE), + new HelpTableViewRow(AddECommand.COMMAND_WORD, AddECommand.MESSAGE_USAGE), + new HelpTableViewRow(ClearCommand.COMMAND_WORD, ClearCommand.COMMAND_WORD), + new HelpTableViewRow(CompleteCommand.COMMAND_WORD, CompleteCommand.MESSAGE_USAGE), + new HelpTableViewRow(DeleteCommand.COMMAND_WORD, DeleteCommand.MESSAGE_USAGE), + new HelpTableViewRow(EditCommand.COMMAND_WORD, EditCommand.MESSAGE_USAGE), + new HelpTableViewRow(ExitCommand.COMMAND_WORD, ExitCommand.COMMAND_WORD), + new HelpTableViewRow(HelpCommand.COMMAND_WORD, HelpCommand.MESSAGE_USAGE), + new HelpTableViewRow(HistoryCommand.COMMAND_WORD, HistoryCommand.MESSAGE_USAGE), + new HelpTableViewRow(ListCommand.COMMAND_WORD, ListCommand.MESSAGE_USAGE), + new HelpTableViewRow(SelectCommand.COMMAND_WORD, SelectCommand.MESSAGE_USAGE), + new HelpTableViewRow(StoragelocCommand.COMMAND_WORD, StoragelocCommand.MESSAGE_USAGE), + new HelpTableViewRow(TagsCommand.COMMAND_WORD, TagsCommand.MESSAGE_USAGE), + new HelpTableViewRow(UndoCommand.COMMAND_WORD, UndoCommand.MESSAGE_USAGE)); + private VBox mainPane; private Scene previousScene; @@ -32,7 +66,13 @@ public class HelpWindow extends UiPart { private MenuItem backMenuItem; @FXML - private TableView cheatSheet; + private TableView helpTableView; + + @FXML + private TableColumn commandColumn; + + @FXML + private TableColumn formatColumn; public static HelpWindow load(Stage primaryStage, Scene mainScene) { logger.fine("Showing help page about the application."); @@ -56,11 +96,20 @@ private void configure(Scene mainScene) { helpScene = new Scene(mainPane); primaryStage.setScene(helpScene); setAccelerators(); + initTable(); } private void setAccelerators() { backMenuItem.setAccelerator(KeyCombination.valueOf("F1")); } + + private void initTable() { + commandColumn.setCellValueFactory( + new PropertyValueFactory("command")); + formatColumn.setCellValueFactory( + new PropertyValueFactory("format")); + helpTableView.setItems(data); + } public Scene getScene() { return helpScene; diff --git a/src/main/resources/view/HelpWindow.fxml b/src/main/resources/view/HelpWindow.fxml index c5dfbad628e2..fb513be6da8b 100644 --- a/src/main/resources/view/HelpWindow.fxml +++ b/src/main/resources/view/HelpWindow.fxml @@ -17,10 +17,10 @@ - + - - + + From 0099045c4e951b02f0d7af222efec407d200406b Mon Sep 17 00:00:00 2001 From: Inaba Kazuhiro Date: Sun, 6 Nov 2016 15:13:59 +0800 Subject: [PATCH 02/11] Add message usage for clear and exit --- src/main/java/seedu/taskman/logic/commands/ClearCommand.java | 2 ++ src/main/java/seedu/taskman/logic/commands/ExitCommand.java | 3 ++- src/main/java/seedu/taskman/ui/HelpWindow.java | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/taskman/logic/commands/ClearCommand.java b/src/main/java/seedu/taskman/logic/commands/ClearCommand.java index 4f0b5adc3cbc..953b20f87c23 100644 --- a/src/main/java/seedu/taskman/logic/commands/ClearCommand.java +++ b/src/main/java/seedu/taskman/logic/commands/ClearCommand.java @@ -8,6 +8,8 @@ public class ClearCommand extends Command { public static final String COMMAND_WORD = "clear"; + public static final String MESSAGE_USAGE = COMMAND_WORD + ": clears data in TaskMan.\n" + + "Example: " + COMMAND_WORD; public static final String MESSAGE_SUCCESS = "TaskMan has been cleared!"; public ClearCommand() { diff --git a/src/main/java/seedu/taskman/logic/commands/ExitCommand.java b/src/main/java/seedu/taskman/logic/commands/ExitCommand.java index 9085204ec6d4..5b82cc6e3618 100644 --- a/src/main/java/seedu/taskman/logic/commands/ExitCommand.java +++ b/src/main/java/seedu/taskman/logic/commands/ExitCommand.java @@ -9,7 +9,8 @@ public class ExitCommand extends Command { public static final String COMMAND_WORD = "exit"; - + public static final String MESSAGE_USAGE = COMMAND_WORD + ": exits TaskMan.\n" + + "Example: " + COMMAND_WORD; public static final String MESSAGE_EXIT_ACKNOWLEDGEMENT = "Exiting TaskMan as requested."; public ExitCommand() { diff --git a/src/main/java/seedu/taskman/ui/HelpWindow.java b/src/main/java/seedu/taskman/ui/HelpWindow.java index 8f6be05ecfd1..c128ed666cc2 100644 --- a/src/main/java/seedu/taskman/ui/HelpWindow.java +++ b/src/main/java/seedu/taskman/ui/HelpWindow.java @@ -44,11 +44,11 @@ public class HelpWindow extends UiPart { final ObservableList data = FXCollections.observableArrayList( new HelpTableViewRow(AddCommand.COMMAND_WORD, AddCommand.MESSAGE_USAGE), new HelpTableViewRow(AddECommand.COMMAND_WORD, AddECommand.MESSAGE_USAGE), - new HelpTableViewRow(ClearCommand.COMMAND_WORD, ClearCommand.COMMAND_WORD), + new HelpTableViewRow(ClearCommand.COMMAND_WORD, ClearCommand.MESSAGE_USAGE), new HelpTableViewRow(CompleteCommand.COMMAND_WORD, CompleteCommand.MESSAGE_USAGE), new HelpTableViewRow(DeleteCommand.COMMAND_WORD, DeleteCommand.MESSAGE_USAGE), new HelpTableViewRow(EditCommand.COMMAND_WORD, EditCommand.MESSAGE_USAGE), - new HelpTableViewRow(ExitCommand.COMMAND_WORD, ExitCommand.COMMAND_WORD), + new HelpTableViewRow(ExitCommand.COMMAND_WORD, ExitCommand.MESSAGE_USAGE), new HelpTableViewRow(HelpCommand.COMMAND_WORD, HelpCommand.MESSAGE_USAGE), new HelpTableViewRow(HistoryCommand.COMMAND_WORD, HistoryCommand.MESSAGE_USAGE), new HelpTableViewRow(ListCommand.COMMAND_WORD, ListCommand.MESSAGE_USAGE), From b78c4f831a49f61495ea01c42f0016f2dd09303d Mon Sep 17 00:00:00 2001 From: Inaba Kazuhiro Date: Sun, 6 Nov 2016 15:58:19 +0800 Subject: [PATCH 03/11] Clean command messages --- src/main/java/seedu/taskman/commons/core/Messages.java | 2 +- .../java/seedu/taskman/logic/commands/AddCommand.java | 5 +++-- .../java/seedu/taskman/logic/commands/AddECommand.java | 5 +++-- .../seedu/taskman/logic/commands/ClearCommand.java | 2 +- .../seedu/taskman/logic/commands/CompleteCommand.java | 6 +++--- .../seedu/taskman/logic/commands/DeleteCommand.java | 9 ++++----- .../java/seedu/taskman/logic/commands/EditCommand.java | 5 +++-- .../java/seedu/taskman/logic/commands/ExitCommand.java | 2 +- .../java/seedu/taskman/logic/commands/HelpCommand.java | 2 +- .../seedu/taskman/logic/commands/HistoryCommand.java | 4 ++-- .../java/seedu/taskman/logic/commands/ListCommand.java | 10 +++++----- .../seedu/taskman/logic/commands/SelectCommand.java | 9 ++++----- .../taskman/logic/commands/StoragelocCommand.java | 6 +++--- .../java/seedu/taskman/logic/commands/TagsCommand.java | 2 +- .../java/seedu/taskman/logic/commands/UndoCommand.java | 9 ++++----- 15 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/main/java/seedu/taskman/commons/core/Messages.java b/src/main/java/seedu/taskman/commons/core/Messages.java index 12dd8731da6b..0e0b70d9ebd6 100644 --- a/src/main/java/seedu/taskman/commons/core/Messages.java +++ b/src/main/java/seedu/taskman/commons/core/Messages.java @@ -6,7 +6,7 @@ public class Messages { public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command."; - public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format.\n%1$s."; + public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format."; public static final String MESSAGE_INVALID_COMMAND_FOR_EVENT = "Invalid command for event."; public static final String MESSAGE_INVALID_EVENT_DISPLAYED_INDEX = "The index provided is invalid."; diff --git a/src/main/java/seedu/taskman/logic/commands/AddCommand.java b/src/main/java/seedu/taskman/logic/commands/AddCommand.java index 089b3a3dbb0f..698412d95c07 100644 --- a/src/main/java/seedu/taskman/logic/commands/AddCommand.java +++ b/src/main/java/seedu/taskman/logic/commands/AddCommand.java @@ -20,7 +20,7 @@ public class AddCommand extends Command { public static final String COMMAND_WORD = "add"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a task to TaskMan.\n" + public static final String MESSAGE_USAGE = "Add a task to TaskMan.\n" + "Parameters: TITLE [d/DEADLINE] [s/SCHEDULE] [t/TAGS]...\n" + "Example: " + COMMAND_WORD + " pay bills d/next fri 1900 s/tmr 1800 to tmr 1830 t/bills"; @@ -62,7 +62,8 @@ private AddCommand(String title, String deadline, String schedule, Set t public static Command prepareAdd(String args) { final Matcher matcher = TASK_ADD_ARGS_FORMAT.matcher(args.trim()); if (!matcher.matches()) { - return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, MESSAGE_USAGE)); + return new IncorrectCommand(MESSAGE_INVALID_COMMAND_FORMAT + + "\n" + COMMAND_WORD + ": " + MESSAGE_USAGE); } try { return new AddCommand( diff --git a/src/main/java/seedu/taskman/logic/commands/AddECommand.java b/src/main/java/seedu/taskman/logic/commands/AddECommand.java index 8e31016dd409..27bbc5ab69c5 100644 --- a/src/main/java/seedu/taskman/logic/commands/AddECommand.java +++ b/src/main/java/seedu/taskman/logic/commands/AddECommand.java @@ -20,7 +20,7 @@ public class AddECommand extends Command { public static final String COMMAND_WORD = "adde"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds an event to TaskMan.\n" + public static final String MESSAGE_USAGE = "Add an event to TaskMan.\n" + "Parameters: TITLE s/SCHEDULE [t/TAGS]...\n" + "Example: " + COMMAND_WORD + " star gazing s/today 2300, today 2330 t/telescope"; @@ -59,7 +59,8 @@ public static Command prepareAddE(String args) { final Matcher matcher = EVENT_MARK_ARGS_FORMAT.matcher(args.trim()); // Validate arg string format if (!matcher.matches()) { - return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, MESSAGE_USAGE)); + return new IncorrectCommand(MESSAGE_INVALID_COMMAND_FORMAT + + "\n" + COMMAND_WORD + ": " + MESSAGE_USAGE); } try { return new AddECommand( diff --git a/src/main/java/seedu/taskman/logic/commands/ClearCommand.java b/src/main/java/seedu/taskman/logic/commands/ClearCommand.java index 953b20f87c23..9c6cffbc0403 100644 --- a/src/main/java/seedu/taskman/logic/commands/ClearCommand.java +++ b/src/main/java/seedu/taskman/logic/commands/ClearCommand.java @@ -8,7 +8,7 @@ public class ClearCommand extends Command { public static final String COMMAND_WORD = "clear"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": clears data in TaskMan.\n" + public static final String MESSAGE_USAGE = "Clear data in TaskMan.\n" + "Example: " + COMMAND_WORD; public static final String MESSAGE_SUCCESS = "TaskMan has been cleared!"; diff --git a/src/main/java/seedu/taskman/logic/commands/CompleteCommand.java b/src/main/java/seedu/taskman/logic/commands/CompleteCommand.java index 5761c4d1efe6..32f59aca5ac7 100644 --- a/src/main/java/seedu/taskman/logic/commands/CompleteCommand.java +++ b/src/main/java/seedu/taskman/logic/commands/CompleteCommand.java @@ -24,7 +24,7 @@ public class CompleteCommand extends Command { public static final String COMMAND_WORD = "complete"; private static final String STATUS_COMPLETE = "complete"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Marks an incomplete task as complete./n" + public static final String MESSAGE_USAGE = "Mark a task as complete.\n" + "Parameters: INDEX\n" + "Example: " + COMMAND_WORD + " d1"; @@ -46,8 +46,8 @@ private CompleteCommand(Activity.PanelType panelType, int targetIndex) { public static Command prepareComplete(String arguments) { Optional> panelIndexPair = parsePanelTypeWithIndexOnly(arguments); if(!panelIndexPair.isPresent()){ - return new IncorrectCommand( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, MESSAGE_USAGE)); + return new IncorrectCommand(MESSAGE_INVALID_COMMAND_FORMAT + + "\n" + COMMAND_WORD + ": " + MESSAGE_USAGE); } return new CompleteCommand( diff --git a/src/main/java/seedu/taskman/logic/commands/DeleteCommand.java b/src/main/java/seedu/taskman/logic/commands/DeleteCommand.java index 0ebbb1130eda..c9ed7db8c2e4 100644 --- a/src/main/java/seedu/taskman/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/taskman/logic/commands/DeleteCommand.java @@ -17,9 +17,8 @@ public class DeleteCommand extends Command { public static final String COMMAND_WORD = "delete"; - public static final String MESSAGE_USAGE = COMMAND_WORD - + ": Deletes the entry identified by the index number used in the listings.\n" - + "Parameters: INDEX (must be a positive whole number)\n" + public static final String MESSAGE_USAGE = "Delete an activity.\n" + + "Parameters: INDEX\n" + "Example: " + COMMAND_WORD + " f1"; public static final String MESSAGE_DELETE_EVENT_SUCCESS = "Deleted task: %1$s"; @@ -36,8 +35,8 @@ private DeleteCommand(Activity.PanelType panelType, int targetIndex) { public static Command prepareDelete(String arguments) { Optional> panelWithIndex = parsePanelTypeWithIndexOnly(arguments); if(!panelWithIndex.isPresent()){ - return new IncorrectCommand( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, MESSAGE_USAGE)); + return new IncorrectCommand(MESSAGE_INVALID_COMMAND_FORMAT + + "\n" + COMMAND_WORD + ": " + MESSAGE_USAGE); } Pair pair = panelWithIndex.get(); return new DeleteCommand(pair.getKey(), pair.getValue()); diff --git a/src/main/java/seedu/taskman/logic/commands/EditCommand.java b/src/main/java/seedu/taskman/logic/commands/EditCommand.java index 7b59e77471c1..ee6ab751fdf6 100644 --- a/src/main/java/seedu/taskman/logic/commands/EditCommand.java +++ b/src/main/java/seedu/taskman/logic/commands/EditCommand.java @@ -30,7 +30,7 @@ public class EditCommand extends Command { public static final String COMMAND_WORD = "edit"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits an existing entry.\n" + public static final String MESSAGE_USAGE = "Edit an activity.\n" + "Parameters: INDEX [TITLE] [d/DEADLINE] [s/SCHEDULE] [t/TAGS]...\n" + "Example: " + COMMAND_WORD + " s2 s/mon 10am, tue 2pm"; @@ -71,7 +71,8 @@ public static Command prepareEdit(String args) { final Matcher matcher = TASK_EDIT_ARGS_FORMAT.matcher(args.trim()); if (!matcher.matches()) { - return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, MESSAGE_USAGE)); + return new IncorrectCommand(MESSAGE_INVALID_COMMAND_FORMAT + + "\n" + COMMAND_WORD + ": " + MESSAGE_USAGE); } String panelTypeRaw = matcher.group(CommandParser.Group.panel.name).trim(); diff --git a/src/main/java/seedu/taskman/logic/commands/ExitCommand.java b/src/main/java/seedu/taskman/logic/commands/ExitCommand.java index 5b82cc6e3618..38b6142ab63d 100644 --- a/src/main/java/seedu/taskman/logic/commands/ExitCommand.java +++ b/src/main/java/seedu/taskman/logic/commands/ExitCommand.java @@ -9,7 +9,7 @@ public class ExitCommand extends Command { public static final String COMMAND_WORD = "exit"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": exits TaskMan.\n" + public static final String MESSAGE_USAGE = "Exit TaskMan.\n" + "Example: " + COMMAND_WORD; public static final String MESSAGE_EXIT_ACKNOWLEDGEMENT = "Exiting TaskMan as requested."; diff --git a/src/main/java/seedu/taskman/logic/commands/HelpCommand.java b/src/main/java/seedu/taskman/logic/commands/HelpCommand.java index 43a41f78185d..6a2911dd386d 100644 --- a/src/main/java/seedu/taskman/logic/commands/HelpCommand.java +++ b/src/main/java/seedu/taskman/logic/commands/HelpCommand.java @@ -11,7 +11,7 @@ public class HelpCommand extends Command { public static final String COMMAND_WORD = "help"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Shows program usage instructions.\n" + public static final String MESSAGE_USAGE = "Show command formats.\n" + "Example: " + COMMAND_WORD; public static final String SHOWING_HELP_MESSAGE = "Opened help window."; diff --git a/src/main/java/seedu/taskman/logic/commands/HistoryCommand.java b/src/main/java/seedu/taskman/logic/commands/HistoryCommand.java index 31f21c011af7..7b59156cad16 100644 --- a/src/main/java/seedu/taskman/logic/commands/HistoryCommand.java +++ b/src/main/java/seedu/taskman/logic/commands/HistoryCommand.java @@ -11,9 +11,9 @@ public class HistoryCommand extends Command { public static final String COMMAND_WORD = "history"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Shows the " + public static final String MESSAGE_USAGE = "Show the " + CAPACITY_UPP_BOUND_HISTORY_COMMAND - + " most recently executed commands the change the data.\n" + + " most recently executed commands that modified data.\n" + "Example: " + COMMAND_WORD; public static final String HISTORY_STRING_HEADER = "Most Recent History:\n"; diff --git a/src/main/java/seedu/taskman/logic/commands/ListCommand.java b/src/main/java/seedu/taskman/logic/commands/ListCommand.java index 4fb2fb9df5c1..a7ecdf8fb478 100644 --- a/src/main/java/seedu/taskman/logic/commands/ListCommand.java +++ b/src/main/java/seedu/taskman/logic/commands/ListCommand.java @@ -20,9 +20,9 @@ public class ListCommand extends Command { public static final String COMMAND_WORD = "list"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all entries whose titles contain any of " - + "the specified keywords (case-sensitive) or tags and filters them out in their respective panels.\n" - + "Parameters: [KEYWORDS]... [t/TAGS]...\n" + public static final String MESSAGE_USAGE = "Find all activities whose titles contain " + + "the specified keywords or holds the specified tags.\n" + + "Parameters: [PANEL]... [KEYWORDS]... [t/TAGS]...\n" + "Example: " + COMMAND_WORD + " d homework t/engineering"; public static final String MESSAGE_FEEDBACK_DEFAULT = "All entries are listed."; @@ -66,8 +66,8 @@ public static Command prepareList(String args) { matcherPaneless.group(CommandParser.Group.tagArguments.name) ); } else { - return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, - ListCommand.MESSAGE_USAGE)); + return new IncorrectCommand(MESSAGE_INVALID_COMMAND_FORMAT + + "\n" + COMMAND_WORD + ": " + MESSAGE_USAGE); } } diff --git a/src/main/java/seedu/taskman/logic/commands/SelectCommand.java b/src/main/java/seedu/taskman/logic/commands/SelectCommand.java index de831be8367a..294e315a846c 100644 --- a/src/main/java/seedu/taskman/logic/commands/SelectCommand.java +++ b/src/main/java/seedu/taskman/logic/commands/SelectCommand.java @@ -21,16 +21,15 @@ public class SelectCommand extends Command { public static final String COMMAND_WORD = "select"; - public static final String MESSAGE_USAGE = COMMAND_WORD - + ": Selects the entry identified by the index number used in the latest TaskMan listing.\n" - + "Parameters: INDEX (must be a positive integer)\n" + public static final String MESSAGE_USAGE = "Select an activity.\n" + + "Parameters: INDEX\n" + "Example: " + COMMAND_WORD + " f2"; public static Command prepareSelect(String arguments) { Optional> panelWithIndex = parsePanelTypeWithIndexOnly(arguments); if(!panelWithIndex.isPresent()){ - return new IncorrectCommand( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, MESSAGE_USAGE)); + return new IncorrectCommand(MESSAGE_INVALID_COMMAND_FORMAT + + "\n" + COMMAND_WORD + ": " + MESSAGE_USAGE); } Pair pair = panelWithIndex.get(); return new SelectCommand(pair.getKey(), pair.getValue()); diff --git a/src/main/java/seedu/taskman/logic/commands/StoragelocCommand.java b/src/main/java/seedu/taskman/logic/commands/StoragelocCommand.java index aea32e362849..b08a52d48647 100644 --- a/src/main/java/seedu/taskman/logic/commands/StoragelocCommand.java +++ b/src/main/java/seedu/taskman/logic/commands/StoragelocCommand.java @@ -17,7 +17,7 @@ public class StoragelocCommand extends Command { public static final String COMMAND_WORD = "storageloc"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Saves to the specified file name and location and sets the application to load from the specified location in the future.\n" + public static final String MESSAGE_USAGE = "Save to the specified file name and location and sets the application to load from the specified location in the future.\n" + "Parameters: LOCATION\n" + "Example: " + COMMAND_WORD + " C:/Users/Owner/Desktop/new_tasks.xm\n" @@ -39,8 +39,8 @@ public static Command prepareStorageloc(String args) { String trimmedArgs = args.trim(); if (!STORAGELOC_ARGS_FORMAT.matcher(trimmedArgs).matches()) { - return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, - MESSAGE_USAGE)); + return new IncorrectCommand(MESSAGE_INVALID_COMMAND_FORMAT + + "\n" + COMMAND_WORD + ": " + MESSAGE_USAGE); } if (trimmedArgs.equals(STORAGELOC_VIEW_KEYWORD)) { diff --git a/src/main/java/seedu/taskman/logic/commands/TagsCommand.java b/src/main/java/seedu/taskman/logic/commands/TagsCommand.java index 11de40c175b7..69e6a684ffe7 100644 --- a/src/main/java/seedu/taskman/logic/commands/TagsCommand.java +++ b/src/main/java/seedu/taskman/logic/commands/TagsCommand.java @@ -7,7 +7,7 @@ public class TagsCommand extends Command { public static final String COMMAND_WORD = "tags"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Shows all existing tags.\n" + public static final String MESSAGE_USAGE = "Show all existing tags.\n" + "Example: " + COMMAND_WORD; public static final String TAG_STRING_HEADER = "Existing tags:\n"; diff --git a/src/main/java/seedu/taskman/logic/commands/UndoCommand.java b/src/main/java/seedu/taskman/logic/commands/UndoCommand.java index 2cf86e2978fb..cd44a591f0de 100644 --- a/src/main/java/seedu/taskman/logic/commands/UndoCommand.java +++ b/src/main/java/seedu/taskman/logic/commands/UndoCommand.java @@ -9,9 +9,8 @@ public class UndoCommand extends Command { public static final String COMMAND_WORD = "undo"; - public static final String MESSAGE_USAGE = COMMAND_WORD - + ": Undo the most recently executed command which changed the data in TaskMan. If a number between 1 to 10 inclusive is specified, that number of commands will be undone. " - + "Parameters: NUMBER (1 to 10 inclusive)\n" + public static final String MESSAGE_USAGE = "Undo the specified number of executed commands which modified data in TaskMan.\n" + + "Parameters: [NUMBER (1 to 10 inclusive)]\n" + "Example: " + COMMAND_WORD + " 2"; @@ -26,8 +25,8 @@ public static Command prepareUndo(String arguments) { } else { Optional index = parseIndex(arguments); if(!index.isPresent()){ - return new IncorrectCommand( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, MESSAGE_USAGE)); + return new IncorrectCommand(MESSAGE_INVALID_COMMAND_FORMAT + + "\n" + COMMAND_WORD + ": " + MESSAGE_USAGE); } return new UndoCommand(index.get()); } From f46b3e3bff3679a7a27ba7d32107f40ac05d4787 Mon Sep 17 00:00:00 2001 From: Inaba Kazuhiro Date: Sun, 6 Nov 2016 16:28:43 +0800 Subject: [PATCH 04/11] Fix tests --- .../seedu/taskman/logic/logicmanager/StorageTests.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/java/seedu/taskman/logic/logicmanager/StorageTests.java b/src/test/java/seedu/taskman/logic/logicmanager/StorageTests.java index 96b2ed06cdcf..54cd16d0479f 100644 --- a/src/test/java/seedu/taskman/logic/logicmanager/StorageTests.java +++ b/src/test/java/seedu/taskman/logic/logicmanager/StorageTests.java @@ -14,6 +14,7 @@ import java.io.IOException; import static org.junit.Assert.assertEquals; +import static seedu.taskman.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; public class StorageTests extends LogicManagerTestBase { @@ -77,13 +78,15 @@ public void execute_storageloc_invalidFileName() throws Exception { @Test public void execute_storageloc_whitespace() throws Exception { assert_storage_location(StoragelocCommand.COMMAND_WORD + " ", - String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, StoragelocCommand.MESSAGE_USAGE), ConfigData.DEFAULT_TASK_MAN_FILE_PATH, false); + MESSAGE_INVALID_COMMAND_FORMAT + "\n" + StoragelocCommand.COMMAND_WORD + ": " + StoragelocCommand.MESSAGE_USAGE, + ConfigData.DEFAULT_TASK_MAN_FILE_PATH, false); } @Test public void execute_storageloc_empty() throws Exception { assert_storage_location(StoragelocCommand.COMMAND_WORD + "", - String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, StoragelocCommand.MESSAGE_USAGE), ConfigData.DEFAULT_TASK_MAN_FILE_PATH, false); + MESSAGE_INVALID_COMMAND_FORMAT + "\n" + StoragelocCommand.COMMAND_WORD + ": " + StoragelocCommand.MESSAGE_USAGE, + ConfigData.DEFAULT_TASK_MAN_FILE_PATH, false); } @Test From 108db42c7658b6d9eba73921909dc741661bd57c Mon Sep 17 00:00:00 2001 From: leeyimin Date: Sat, 5 Nov 2016 21:37:28 +0800 Subject: [PATCH 05/11] Improve ListCommand Regex --- .../taskman/logic/commands/ListCommand.java | 14 ++++----- .../taskman/logic/parser/CommandParser.java | 20 ++---------- .../seedu/taskman/model/event/Activity.java | 31 ++++++++++++++----- .../taskman/logic/logicmanager/ListTests.java | 3 -- 4 files changed, 33 insertions(+), 35 deletions(-) diff --git a/src/main/java/seedu/taskman/logic/commands/ListCommand.java b/src/main/java/seedu/taskman/logic/commands/ListCommand.java index a7ecdf8fb478..3b5a81db468b 100644 --- a/src/main/java/seedu/taskman/logic/commands/ListCommand.java +++ b/src/main/java/seedu/taskman/logic/commands/ListCommand.java @@ -31,12 +31,12 @@ public class ListCommand extends Command { public static final String MESSAGE_FEEDBACK_WORD_SEPARATOR = " "; private static final Pattern SPECIFY_PANEL_ARGS_FORMAT = - Pattern.compile("" + CommandParser.ArgumentPattern.PANEL + "?" + Pattern.compile("" + CommandParser.ArgumentPattern.PANEL + CommandParser.ArgumentPattern.OPTIONAL_KEYWORDS + CommandParser.ArgumentPattern.OPTIONAL_TAGS); - private static final Pattern SPECIFY_PANELESS_ARGS_FORMAT = - Pattern.compile("" + CommandParser.ArgumentPattern.KEYWORDS + private static final Pattern SPECIFY_NO_PANEL_ARGS_FORMAT = + Pattern.compile("" + CommandParser.ArgumentPattern.OPTIONAL_KEYWORDS + CommandParser.ArgumentPattern.OPTIONAL_TAGS); private final Activity.PanelType panelType; @@ -46,7 +46,7 @@ public class ListCommand extends Command { public static Command prepareList(String args) { final String trimmedArgs = args.trim(); final Matcher matcherWithPanel = SPECIFY_PANEL_ARGS_FORMAT.matcher(trimmedArgs); - final Matcher matcherPaneless = SPECIFY_PANELESS_ARGS_FORMAT.matcher(trimmedArgs); + final Matcher matcherWithoutPanel = SPECIFY_NO_PANEL_ARGS_FORMAT.matcher(trimmedArgs); if (trimmedArgs.isEmpty()) { return new ListCommand( @@ -60,10 +60,10 @@ public static Command prepareList(String args) { matcherWithPanel.group(CommandParser.Group.keywords.name), matcherWithPanel.group(CommandParser.Group.tagArguments.name) ); - } else if(matcherPaneless.matches()) { + } else if(matcherWithoutPanel.matches()) { return allPanelsListCommand( - matcherPaneless.group(CommandParser.Group.keywords.name), - matcherPaneless.group(CommandParser.Group.tagArguments.name) + matcherWithoutPanel.group(CommandParser.Group.keywords.name), + matcherWithoutPanel.group(CommandParser.Group.tagArguments.name) ); } else { return new IncorrectCommand(MESSAGE_INVALID_COMMAND_FORMAT diff --git a/src/main/java/seedu/taskman/logic/parser/CommandParser.java b/src/main/java/seedu/taskman/logic/parser/CommandParser.java index a4ad3557fbbc..ecbd2ce3b938 100644 --- a/src/main/java/seedu/taskman/logic/parser/CommandParser.java +++ b/src/main/java/seedu/taskman/logic/parser/CommandParser.java @@ -1,21 +1,6 @@ package seedu.taskman.logic.parser; -import seedu.taskman.logic.commands.AddCommand; -import seedu.taskman.logic.commands.ClearCommand; -import seedu.taskman.logic.commands.Command; -import seedu.taskman.logic.commands.CompleteCommand; -import seedu.taskman.logic.commands.DeleteCommand; -import seedu.taskman.logic.commands.EditCommand; -import seedu.taskman.logic.commands.ExitCommand; -import seedu.taskman.logic.commands.HelpCommand; -import seedu.taskman.logic.commands.HistoryCommand; -import seedu.taskman.logic.commands.IncorrectCommand; -import seedu.taskman.logic.commands.ListCommand; -import seedu.taskman.logic.commands.AddECommand; -import seedu.taskman.logic.commands.SelectCommand; -import seedu.taskman.logic.commands.StoragelocCommand; -import seedu.taskman.logic.commands.TagsCommand; -import seedu.taskman.logic.commands.UndoCommand; +import seedu.taskman.logic.commands.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -57,8 +42,7 @@ public enum ArgumentPattern { PANEL("(?<" + Group.panel.name + ">[dsf])"), TARGET_INDEX("(?<" + Group.targetIndex.name + ">[0-9]+)"), TITLE("(?<" + Group.title.name + ">[^/]+)"), - KEYWORDS("(?<" + Group.keywords.name + ">[^/]+)"), - OPTIONAL_KEYWORDS("(?<" + Group.keywords.name + ">(?:\\s+[^/]+)*)?"), + OPTIONAL_KEYWORDS("(?<" + Group.keywords.name + ">(?:\\s*[^/]+)*)?"), OPTIONAL_DEADLINE("(?:\\s+d/(?<" + Group.deadline.name + ">[^/]+))?"), OPTIONAL_SCHEDULE("(?:\\s+s/(?<" + Group.schedule.name + ">[^/]+))?"), OPTIONAL_STATUS("(?:\\s+c/(?<" + Group.status.name + ">[^/]+))?"), diff --git a/src/main/java/seedu/taskman/model/event/Activity.java b/src/main/java/seedu/taskman/model/event/Activity.java index 325909e9dfde..90644e9ce5dc 100644 --- a/src/main/java/seedu/taskman/model/event/Activity.java +++ b/src/main/java/seedu/taskman/model/event/Activity.java @@ -25,7 +25,7 @@ public enum ActivityType {EVENT, TASK} private MutableTagsEvent activity; private ActivityType type; - public Activity(Event event){ + public Activity(Event event) { if (event.getClass().getName().equals(Task.class.getName())) { activity = event; type = ActivityType.TASK; @@ -47,11 +47,11 @@ public Activity(Activity source) { break; } case EVENT: { - this.activity = new Event((ReadOnlyEvent) source.activity); + this.activity = new Event(source.activity); break; } default: { - this.activity = new Event((ReadOnlyEvent) source.activity); + this.activity = new Event(source.activity); } } type = source.getType(); @@ -68,8 +68,8 @@ public Optional getTask() { return Optional.of((ReadOnlyTask) activity); } - public Optional getEvent(){ - if(type != ActivityType.EVENT){ + public Optional getEvent() { + if (type != ActivityType.EVENT) { return Optional.empty(); } return Optional.of((ReadOnlyEvent) activity); @@ -206,11 +206,28 @@ public static PanelType fromString(String str) { } } - public String getName(){ + /** + * Returns the String which will compile into a Pattern that can differentiate the different panel types, excluding the ALL type + */ + public static String getPatternString() { + StringBuilder builder = new StringBuilder(); + for (PanelType panelType : PanelType.values()) { + //skip if panelType is ALL + if (!panelType.equals(ALL)) { + if (builder.length() != 0) { + builder.append('|'); + } + builder.append("(" + panelType.getString() + ")"); + } + } + return builder.toString(); + } + + public String getName() { return name; } - public String getString(){ + public String getString() { return string; } diff --git a/src/test/java/seedu/taskman/logic/logicmanager/ListTests.java b/src/test/java/seedu/taskman/logic/logicmanager/ListTests.java index 579f1577a583..2ae78ec1e48c 100644 --- a/src/test/java/seedu/taskman/logic/logicmanager/ListTests.java +++ b/src/test/java/seedu/taskman/logic/logicmanager/ListTests.java @@ -1,6 +1,5 @@ package seedu.taskman.logic.logicmanager; -import org.junit.Ignore; import org.junit.Test; import seedu.taskman.model.TaskMan; import seedu.taskman.model.event.Activity; @@ -143,7 +142,6 @@ public void execute_listDeadline_matchesIfAnyKeywordPresent() throws Exception { // TODO: test is insufficient - @Ignore @Test public void execute_listDeadline_filter_tags() throws Exception { // setup expectations @@ -170,7 +168,6 @@ public void execute_listDeadline_filter_tags() throws Exception { } // TODO: test is insufficient - @Ignore @Test public void execute_list_filter_keywords_with_tags() throws Exception { // setup expectations From 8c45a3bb8df0980c10931ce5fdf6295657abfb59 Mon Sep 17 00:00:00 2001 From: leeyimin Date: Sat, 5 Nov 2016 22:39:24 +0800 Subject: [PATCH 06/11] Improve deadline list tests --- .../taskman/logic/logicmanager/ListTests.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/test/java/seedu/taskman/logic/logicmanager/ListTests.java b/src/test/java/seedu/taskman/logic/logicmanager/ListTests.java index 2ae78ec1e48c..b132b5061d36 100644 --- a/src/test/java/seedu/taskman/logic/logicmanager/ListTests.java +++ b/src/test/java/seedu/taskman/logic/logicmanager/ListTests.java @@ -141,7 +141,6 @@ public void execute_listDeadline_matchesIfAnyKeywordPresent() throws Exception { } - // TODO: test is insufficient @Test public void execute_listDeadline_filter_tags() throws Exception { // setup expectations @@ -152,24 +151,28 @@ public void execute_listDeadline_filter_tags() throws Exception { TaskMan expectedTaskMan = helper.generateTaskMan(4); List expectedList = expectedTaskMan.getActivityList().subList(0, 2); - assertCommandStateChange("list t/tag2", + assertCommandStateChange("list d t/tag2", expectedTaskMan ); + assertTrue(model.getSortedDeadlineList().containsAll(expectedList)); + assertTrue(model.getSortedDeadlineList().size() == expectedList.size()); - assertCommandStateChange("list t/tag6", + assertCommandStateChange("list d t/tag6", expectedTaskMan ); + assertTrue(model.getSortedDeadlineList().isEmpty()); expectedList = new ArrayList<>(expectedTaskMan.getActivities()); expectedList.remove(1); - assertCommandStateChange("list t/tag1 t/tag4", + assertCommandStateChange("list d t/tag1 t/tag4", expectedTaskMan ); + assertTrue(model.getSortedDeadlineList().containsAll(expectedList)); + assertTrue(model.getSortedDeadlineList().size() == expectedList.size()); } - // TODO: test is insufficient @Test - public void execute_list_filter_keywords_with_tags() throws Exception { + public void execute_listDeadline_filterKeywordsWithTags() throws Exception { // setup expectations TestDataHelper helper = new TestDataHelper(); TaskMan expectedTaskMan = helper.generateTaskMan(5); @@ -180,10 +183,11 @@ public void execute_list_filter_keywords_with_tags() throws Exception { List expectedList = new ArrayList<>(); expectedList.add(new Activity(helper.generateFullTask(1))); expectedList.add(new Activity(helper.generateFullTask(5))); - // TODO: This passes and fails randomly - assertCommandStateChange("list 1 5 t/tag2 t/tag6", + assertCommandStateChange("list d 1 5 t/tag2 t/tag6", expectedTaskMan ); + assertTrue(model.getSortedDeadlineList().containsAll(expectedList)); + assertTrue(model.getSortedDeadlineList().size() == expectedList.size()); } From e4682d17e53faa9708620bd61d9cda50d89772f9 Mon Sep 17 00:00:00 2001 From: leeyimin Date: Sun, 6 Nov 2016 17:11:22 +0800 Subject: [PATCH 07/11] Add list filter tags test --- .../taskman/logic/logicmanager/ListTests.java | 103 ++++++++++++++++++ .../logicmanager/LogicManagerTestBase.java | 94 ++++++++++++---- 2 files changed, 178 insertions(+), 19 deletions(-) diff --git a/src/test/java/seedu/taskman/logic/logicmanager/ListTests.java b/src/test/java/seedu/taskman/logic/logicmanager/ListTests.java index b132b5061d36..97327e84a865 100644 --- a/src/test/java/seedu/taskman/logic/logicmanager/ListTests.java +++ b/src/test/java/seedu/taskman/logic/logicmanager/ListTests.java @@ -1,6 +1,7 @@ package seedu.taskman.logic.logicmanager; import org.junit.Test; +import seedu.taskman.model.ReadOnlyTaskMan; import seedu.taskman.model.TaskMan; import seedu.taskman.model.event.Activity; import seedu.taskman.model.event.Task; @@ -9,6 +10,7 @@ import java.util.List; import static org.junit.Assert.assertTrue; + //@@author A0140136W public class ListTests extends LogicManagerTestBase { @@ -190,5 +192,106 @@ public void execute_listDeadline_filterKeywordsWithTags() throws Exception { assertTrue(model.getSortedDeadlineList().size() == expectedList.size()); } + private ReadOnlyTaskMan filterListAllSetup() throws Exception { + TestDataHelper helper = new TestDataHelper(); + // setup TaskMan state + helper.addToModel(model, 5); + TaskMan expectedTaskMan = helper.generateTaskMan(5); + + helper.addEventsToModel(model, 3); + helper.addEventsToTaskMan(expectedTaskMan, 3); + + List floatingTasks = helper.generateTaskList(helper.generateFloatingTask(3), + helper.generateFloatingTask(4), + helper.generateFloatingTask(5)); + helper.addToModel(model, floatingTasks); + helper.addToTaskMan(expectedTaskMan, floatingTasks); + + return expectedTaskMan; + } + + private void assert_list_allPanels(String command, ReadOnlyTaskMan expectedTaskMan, + List expectedDeadlineList, + List expectedScheduleList, + List expectedFloatingList) throws Exception { + assertCommandStateChange(command, expectedTaskMan); + //check deadline + assertTrue(model.getSortedDeadlineList().containsAll(expectedDeadlineList)); + assertTrue(model.getSortedDeadlineList().size() == expectedDeadlineList.size()); + //check schedule + assertTrue(model.getSortedScheduleList().containsAll(expectedScheduleList)); + assertTrue(model.getSortedScheduleList().size() == expectedScheduleList.size()); + //check floating + assertTrue(model.getSortedScheduleList().containsAll(expectedScheduleList)); + assertTrue(model.getSortedScheduleList().size() == expectedScheduleList.size()); + + } + + @Test + public void execute_listAll_filterSingleTag() throws Exception { + // setup + ReadOnlyTaskMan expectedTaskMan = filterListAllSetup(); + + TestDataHelper helper = new TestDataHelper(); + // expected lists + // deadline list + List expectedDeadlineList = new ArrayList<>(); + expectedDeadlineList.add(new Activity(helper.generateFullTask(2))); + expectedDeadlineList.add(new Activity(helper.generateFullTask(3))); + // schedule list + // copy items from deadline list (both have schedules) + List expectedScheduleList = new ArrayList<>(expectedDeadlineList); + expectedScheduleList.add(new Activity(helper.generateFullEvent(2))); + expectedScheduleList.add(new Activity(helper.generateFullEvent(3))); + // floating list + List expectedFloatingList = new ArrayList<>(); + expectedFloatingList.add(new Activity(helper.generateFloatingTask(3))); + + // test command + assert_list_allPanels("list t/tag3", expectedTaskMan, + expectedDeadlineList, expectedScheduleList, expectedFloatingList); + } + + @Test + public void execute_listAll_filterNotExistingTag() throws Exception { + // setup + ReadOnlyTaskMan expectedTaskMan = filterListAllSetup(); + + // expected lists + // deadline list + List expectedList = new ArrayList<>(); + + // test command + assert_list_allPanels("list t/tag7", expectedTaskMan, + expectedList, expectedList, expectedList); + } + + @Test + public void execute_listAll_filterMultipleTags() throws Exception { + // setup + ReadOnlyTaskMan expectedTaskMan = filterListAllSetup(); + + TestDataHelper helper = new TestDataHelper(); + // expected lists + // deadline list + List expectedDeadlineList = new ArrayList<>(); + expectedDeadlineList.add(new Activity(helper.generateFullTask(1))); + expectedDeadlineList.add(new Activity(helper.generateFullTask(3))); + expectedDeadlineList.add(new Activity(helper.generateFullTask(4))); + // schedule list + // copy items from deadline list (both have schedules) + List expectedScheduleList = new ArrayList<>(expectedDeadlineList); + expectedScheduleList.add(new Activity(helper.generateFullEvent(1))); + expectedScheduleList.add(new Activity(helper.generateFullEvent(3))); + // floating list + List expectedFloatingList = new ArrayList<>(); + expectedFloatingList.add(new Activity(helper.generateFloatingTask(3))); + expectedFloatingList.add(new Activity(helper.generateFloatingTask(4))); + + // test command + assert_list_allPanels("list t/tag1 t/tag4", expectedTaskMan, + expectedDeadlineList, expectedScheduleList, expectedFloatingList); + } + } \ No newline at end of file diff --git a/src/test/java/seedu/taskman/logic/logicmanager/LogicManagerTestBase.java b/src/test/java/seedu/taskman/logic/logicmanager/LogicManagerTestBase.java index cc600bb53464..23557e0005f9 100644 --- a/src/test/java/seedu/taskman/logic/logicmanager/LogicManagerTestBase.java +++ b/src/test/java/seedu/taskman/logic/logicmanager/LogicManagerTestBase.java @@ -95,6 +95,7 @@ public void teardown() { * Executes the command and confirms that the result message is correct. * Generally for commands which do not mutate the data. * Both the 'TaskMan' and the 'list' are expected to be empty. + * * @see #assertCommandBehavior(String, String, TaskMan, List) */ private void assertCommandBehavior(String inputCommand, String expectedMessage) throws Exception { @@ -104,9 +105,9 @@ private void assertCommandBehavior(String inputCommand, String expectedMessage) /** * Executes the command and confirms that the result message is correct and * also confirms that the following three parts of the LogicManager object's state are as expected: - * - the internal address book data are same as those in the {@code expectedTaskMan} - * - the backing list shown by UI matches the expected list here in the method - * - {@code expectedTaskMan} was saved to the storage file. + * - the internal address book data are same as those in the {@code expectedTaskMan} + * - the backing list shown by UI matches the expected list here in the method + * - {@code expectedTaskMan} was saved to the storage file. */ private void assertCommandBehavior(String inputCommand, String expectedMessage, TaskMan expectedTaskMan, @@ -135,9 +136,9 @@ protected CommandResult assertCommandNoStateChange(String inputCommand) throws E /** * Executes the command and confirms the following three parts of the LogicManager object's state are as expected:
- * - the internal TaskMan data are same as those in the {@code expectedTaskMan}
- * - the backing list shown by UI matches the {@code shownList}
- * - {@code expectedTaskMan} was saved to the storage file.
+ * - the internal TaskMan data are same as those in the {@code expectedTaskMan}
+ * - the backing list shown by UI matches the {@code shownList}
+ * - {@code expectedTaskMan} was saved to the storage file.
* * @return Result of executed command */ @@ -195,7 +196,7 @@ static class TestDataHelper { List tasksToActivity(List tasks) { ArrayList activities = new ArrayList<>(); - for(Task task : tasks) { + for (Task task : tasks) { activities.add(new Activity(task)); } return activities; @@ -212,9 +213,25 @@ Task generateFullTask(int seed) throws Exception { return new Task( new Title("Task " + seed), new UniqueTagList(new Tag("tag" + Math.abs(seed)), new Tag("tag" + Math.abs(seed + 1))), - new Deadline((seed+1) +" Dec " +seed%12 +"am"), - new Schedule(seed +" nov " + (seed%12+1) + "am" + - ", " + seed +" nov " + ((seed+1)%12+1) + "pm" ) + new Deadline((seed + 1) + " Dec " + seed % 12 + "am"), + new Schedule(seed + " nov " + (seed % 12 + 1) + "am" + + ", " + seed + " nov " + ((seed + 1) % 12 + 1) + "pm") + ); + } + + /** + * Generates a valid task using the given seed. + * Running this function with the same parameter values guarantees the returned task will have the same state. + * Each unique seed will generate a unique Task object. + * + * @param seed used to generate the task data field values + */ + Task generateFloatingTask(int seed) throws Exception { + return new Task( + new Title("Floating " + seed), + new UniqueTagList(new Tag("tag" + Math.abs(seed)), new Tag("tag" + Math.abs(seed + 1))), + null, + null ); } @@ -229,8 +246,8 @@ Event generateFullEvent(int seed) throws Exception { return new Event( new Title("Event " + seed), new UniqueTagList(new Tag("tag" + Math.abs(seed)), new Tag("tag" + Math.abs(seed + 1))), - new Schedule(seed +" nov " + (seed%12+1) + "am" + - ", " + seed +" nov " + ((seed+1)%12+1) + "pm" ) + new Schedule(seed + " nov " + (seed % 12 + 1) + "am" + + ", " + seed + " nov " + ((seed + 1) % 12 + 1) + "pm") ); } @@ -242,14 +259,14 @@ String generateAddCommand(Task task) { command.append(task.getTitle().toString()); if (task.getDeadline().isPresent()) { - command.append(" d/"). append(task.getDeadline().get().toFormalString()); + command.append(" d/").append(task.getDeadline().get().toFormalString()); } if (task.getSchedule().isPresent()) { command.append(" s/").append(task.getSchedule().get().toFormalString()); } UniqueTagList tags = task.getTags(); - for(Tag t: tags) { + for (Tag t : tags) { command.append(" t/").append(t.tagName); } @@ -267,7 +284,7 @@ String generateAddECommand(Event event) { } UniqueTagList tags = event.getTags(); - for(Tag t: tags) { + for (Tag t : tags) { command.append(" t/").append(t.tagName); } @@ -339,8 +356,26 @@ void addToTaskMan(TaskMan taskMan, int numGenerated) throws Exception { /** * Adds the given list of Tasks to the given TaskMan */ - void addToTaskMan(TaskMan taskMan, List tasksToAdd) throws Exception{ - for (Task p: tasksToAdd) { + void addToTaskMan(TaskMan taskMan, List tasksToAdd) throws Exception { + for (Task p : tasksToAdd) { + taskMan.addActivity(p); + } + } + + /** + * Adds auto-generated Events objects to the given TaskMan + * + * @param taskMan The TaskMan to which the Events will be added + */ + void addEventsToTaskMan(TaskMan taskMan, int numGenerated) throws Exception { + addEventsToTaskMan(taskMan, generateFullEventList(numGenerated)); + } + + /** + * Adds the given list of Events to the given TaskMan + */ + void addEventsToTaskMan(TaskMan taskMan, List eventsToAdd) throws Exception { + for (Event p : eventsToAdd) { taskMan.addActivity(p); } } @@ -357,12 +392,21 @@ void addToModel(Model model, int numGenerated) throws Exception { /** * Adds the given list of Tasks to the given model */ - void addToModel(Model model, List tasksToAdd) throws Exception{ - for(Task p: tasksToAdd){ + void addToModel(Model model, List tasksToAdd) throws Exception { + for (Event p : tasksToAdd) { model.addActivity(p); } } + /** + * Adds auto-generated Event objects to the given model + * + * @param model The model to which the Events will be added + */ + void addEventsToModel(Model model, int numGenerated) throws Exception { + addToModel(model, generateFullEventList(numGenerated)); + } + /** * Generates a list of Tasks based on the flags. * Each task has all its fields filled. @@ -375,6 +419,18 @@ List generateFullTaskList(int numGenerated) throws Exception { return tasks; } + /** + * Generates a list of Events based on the flags. + * Each event has all its fields filled. + */ + List generateFullEventList(int numGenerated) throws Exception { + List events = new ArrayList<>(); + for (int i = 1; i <= numGenerated; i++) { + events.add(generateFullEvent(i)); + } + return events; + } + ArrayList generateTaskList(Task... tasks) { return new ArrayList<>(Arrays.asList(tasks)); } From 9c318cda796f74e45473e15cb13d3e3322ff62a8 Mon Sep 17 00:00:00 2001 From: leeyimin Date: Sun, 6 Nov 2016 20:03:17 +0800 Subject: [PATCH 08/11] change visibility scope --- .../logicmanager/LogicManagerTestBase.java | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/test/java/seedu/taskman/logic/logicmanager/LogicManagerTestBase.java b/src/test/java/seedu/taskman/logic/logicmanager/LogicManagerTestBase.java index 23557e0005f9..ad8355bc9d7e 100644 --- a/src/test/java/seedu/taskman/logic/logicmanager/LogicManagerTestBase.java +++ b/src/test/java/seedu/taskman/logic/logicmanager/LogicManagerTestBase.java @@ -190,11 +190,11 @@ protected void assertIndexNotFoundBehaviorForCommand(String commandWord) throws /** * A utility class to generate test data. */ - static class TestDataHelper { + protected static class TestDataHelper { public final String STRING_RANDOM = "random"; - List tasksToActivity(List tasks) { + protected List tasksToActivity(List tasks) { ArrayList activities = new ArrayList<>(); for (Task task : tasks) { activities.add(new Activity(task)); @@ -209,7 +209,7 @@ List tasksToActivity(List tasks) { * * @param seed used to generate the task data field values */ - Task generateFullTask(int seed) throws Exception { + protected Task generateFullTask(int seed) throws Exception { return new Task( new Title("Task " + seed), new UniqueTagList(new Tag("tag" + Math.abs(seed)), new Tag("tag" + Math.abs(seed + 1))), @@ -226,7 +226,7 @@ Task generateFullTask(int seed) throws Exception { * * @param seed used to generate the task data field values */ - Task generateFloatingTask(int seed) throws Exception { + protected Task generateFloatingTask(int seed) throws Exception { return new Task( new Title("Floating " + seed), new UniqueTagList(new Tag("tag" + Math.abs(seed)), new Tag("tag" + Math.abs(seed + 1))), @@ -242,7 +242,7 @@ Task generateFloatingTask(int seed) throws Exception { * * @param seed used to generate the task data field values */ - Event generateFullEvent(int seed) throws Exception { + protected Event generateFullEvent(int seed) throws Exception { return new Event( new Title("Event " + seed), new UniqueTagList(new Tag("tag" + Math.abs(seed)), new Tag("tag" + Math.abs(seed + 1))), @@ -252,7 +252,7 @@ Event generateFullEvent(int seed) throws Exception { } @SuppressWarnings("OptionalGetWithoutIsPresent") - String generateAddCommand(Task task) { + protected String generateAddCommand(Task task) { StringBuilder command = new StringBuilder(); command.append("add "); @@ -273,7 +273,7 @@ String generateAddCommand(Task task) { return command.toString(); } - String generateAddECommand(Event event) { + protected String generateAddECommand(Event event) { StringBuilder command = new StringBuilder(); command.append("adde "); @@ -291,7 +291,7 @@ String generateAddECommand(Event event) { return command.toString(); } - String generateEditCommand(Model model, Activity.PanelType panel, int targetIndex, Title title, + protected String generateEditCommand(Model model, Activity.PanelType panel, int targetIndex, Title title, Deadline deadline, Schedule schedule, UniqueTagList tags) { Activity task = model.getActivityListForPanelType(panel).get(targetIndex); StringBuilder command = new StringBuilder(); @@ -329,7 +329,7 @@ String generateEditCommand(Model model, Activity.PanelType panel, int targetInd /** * Generates an TaskMan with auto-generated tasks. */ - TaskMan generateTaskMan(int numGenerated) throws Exception { + protected TaskMan generateTaskMan(int numGenerated) throws Exception { TaskMan taskMan = new TaskMan(); addToTaskMan(taskMan, numGenerated); return taskMan; @@ -338,7 +338,7 @@ TaskMan generateTaskMan(int numGenerated) throws Exception { /** * Generates an TaskMan based on the list of Tasks given. */ - TaskMan generateTaskMan(List tasks) throws Exception { + protected TaskMan generateTaskMan(List tasks) throws Exception { TaskMan taskMan = new TaskMan(); addToTaskMan(taskMan, tasks); return taskMan; @@ -349,14 +349,14 @@ TaskMan generateTaskMan(List tasks) throws Exception { * * @param taskMan The TaskMan to which the Tasks will be added */ - void addToTaskMan(TaskMan taskMan, int numGenerated) throws Exception { + protected void addToTaskMan(TaskMan taskMan, int numGenerated) throws Exception { addToTaskMan(taskMan, generateFullTaskList(numGenerated)); } /** * Adds the given list of Tasks to the given TaskMan */ - void addToTaskMan(TaskMan taskMan, List tasksToAdd) throws Exception { + protected void addToTaskMan(TaskMan taskMan, List tasksToAdd) throws Exception { for (Task p : tasksToAdd) { taskMan.addActivity(p); } @@ -367,14 +367,14 @@ void addToTaskMan(TaskMan taskMan, List tasksToAdd) throws Exception { * * @param taskMan The TaskMan to which the Events will be added */ - void addEventsToTaskMan(TaskMan taskMan, int numGenerated) throws Exception { + protected void addEventsToTaskMan(TaskMan taskMan, int numGenerated) throws Exception { addEventsToTaskMan(taskMan, generateFullEventList(numGenerated)); } /** * Adds the given list of Events to the given TaskMan */ - void addEventsToTaskMan(TaskMan taskMan, List eventsToAdd) throws Exception { + protected void addEventsToTaskMan(TaskMan taskMan, List eventsToAdd) throws Exception { for (Event p : eventsToAdd) { taskMan.addActivity(p); } @@ -385,14 +385,14 @@ void addEventsToTaskMan(TaskMan taskMan, List eventsToAdd) throws Excepti * * @param model The model to which the Tasks will be added */ - void addToModel(Model model, int numGenerated) throws Exception { + protected void addToModel(Model model, int numGenerated) throws Exception { addToModel(model, generateFullTaskList(numGenerated)); } /** * Adds the given list of Tasks to the given model */ - void addToModel(Model model, List tasksToAdd) throws Exception { + protected void addToModel(Model model, List tasksToAdd) throws Exception { for (Event p : tasksToAdd) { model.addActivity(p); } @@ -403,7 +403,7 @@ void addToModel(Model model, List tasksToAdd) throws Exception * * @param model The model to which the Events will be added */ - void addEventsToModel(Model model, int numGenerated) throws Exception { + protected void addEventsToModel(Model model, int numGenerated) throws Exception { addToModel(model, generateFullEventList(numGenerated)); } @@ -411,7 +411,7 @@ void addEventsToModel(Model model, int numGenerated) throws Exception { * Generates a list of Tasks based on the flags. * Each task has all its fields filled. */ - List generateFullTaskList(int numGenerated) throws Exception { + protected List generateFullTaskList(int numGenerated) throws Exception { List tasks = new ArrayList<>(); for (int i = 1; i <= numGenerated; i++) { tasks.add(generateFullTask(i)); @@ -423,7 +423,7 @@ List generateFullTaskList(int numGenerated) throws Exception { * Generates a list of Events based on the flags. * Each event has all its fields filled. */ - List generateFullEventList(int numGenerated) throws Exception { + protected List generateFullEventList(int numGenerated) throws Exception { List events = new ArrayList<>(); for (int i = 1; i <= numGenerated; i++) { events.add(generateFullEvent(i)); @@ -431,14 +431,14 @@ List generateFullEventList(int numGenerated) throws Exception { return events; } - ArrayList generateTaskList(Task... tasks) { + protected ArrayList generateTaskList(Task... tasks) { return new ArrayList<>(Arrays.asList(tasks)); } /** * Generates a Task object with given title. Other fields will have some dummy values. */ - Task generateTaskWithAllFields(String title) throws Exception { + protected Task generateTaskWithAllFields(String title) throws Exception { return new Task( new Title(title), new UniqueTagList(new Tag("t1"), new Tag("t2")), @@ -447,7 +447,7 @@ Task generateTaskWithAllFields(String title) throws Exception { ); } - Task generateTaskWithOnlyDeadline(String title) throws Exception { + protected Task generateTaskWithOnlyDeadline(String title) throws Exception { return new Task( new Title(title), new UniqueTagList(), @@ -456,7 +456,7 @@ Task generateTaskWithOnlyDeadline(String title) throws Exception { ); } - Task generateTaskWithOnlySchedule(String title) throws Exception { + protected Task generateTaskWithOnlySchedule(String title) throws Exception { return new Task( new Title(title), new UniqueTagList(), From 849513676bd7d9ce47a288c6f2239540aa744aa6 Mon Sep 17 00:00:00 2001 From: leeyimin Date: Sun, 6 Nov 2016 20:03:40 +0800 Subject: [PATCH 09/11] test list all with both keywords and tags --- .../taskman/logic/logicmanager/ListTests.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/test/java/seedu/taskman/logic/logicmanager/ListTests.java b/src/test/java/seedu/taskman/logic/logicmanager/ListTests.java index 97327e84a865..a622a7fbf1c4 100644 --- a/src/test/java/seedu/taskman/logic/logicmanager/ListTests.java +++ b/src/test/java/seedu/taskman/logic/logicmanager/ListTests.java @@ -192,6 +192,7 @@ public void execute_listDeadline_filterKeywordsWithTags() throws Exception { assertTrue(model.getSortedDeadlineList().size() == expectedList.size()); } + //@@author A0121299A private ReadOnlyTaskMan filterListAllSetup() throws Exception { TestDataHelper helper = new TestDataHelper(); // setup TaskMan state @@ -222,8 +223,8 @@ private void assert_list_allPanels(String command, ReadOnlyTaskMan expectedTaskM assertTrue(model.getSortedScheduleList().containsAll(expectedScheduleList)); assertTrue(model.getSortedScheduleList().size() == expectedScheduleList.size()); //check floating - assertTrue(model.getSortedScheduleList().containsAll(expectedScheduleList)); - assertTrue(model.getSortedScheduleList().size() == expectedScheduleList.size()); + assertTrue(model.getSortedFloatingList().containsAll(expectedFloatingList)); + assertTrue(model.getSortedFloatingList().size() == expectedFloatingList.size()); } @@ -293,5 +294,29 @@ public void execute_listAll_filterMultipleTags() throws Exception { expectedDeadlineList, expectedScheduleList, expectedFloatingList); } + @Test + public void execute_listAll_filterKeywordsWithTags() throws Exception { + // setup + ReadOnlyTaskMan expectedTaskMan = filterListAllSetup(); + + TestDataHelper helper = new TestDataHelper(); + // expected lists + // deadline list + List expectedDeadlineList = new ArrayList<>(); + expectedDeadlineList.add(new Activity(helper.generateFullTask(2))); + // schedule list + // copy items from deadline list (both have schedules) + List expectedScheduleList = new ArrayList<>(expectedDeadlineList); + expectedScheduleList.add(new Activity(helper.generateFullEvent(2))); + expectedScheduleList.add(new Activity(helper.generateFullEvent(3))); + // floating list + List expectedFloatingList = new ArrayList<>(); + expectedFloatingList.add(new Activity(helper.generateFloatingTask(3))); + expectedFloatingList.add(new Activity(helper.generateFloatingTask(4))); + // test command + assert_list_allPanels("list Floating Event 2 t/tag3 t/tag4", expectedTaskMan, + expectedDeadlineList, expectedScheduleList, expectedFloatingList); + } + } \ No newline at end of file From 2aeed8a01e1d54272c9b6c069215b5abca771b1f Mon Sep 17 00:00:00 2001 From: leeyimin Date: Sun, 6 Nov 2016 21:38:07 +0800 Subject: [PATCH 10/11] Fix validTaskMan data --- src/test/data/XmlUtilTest/validTaskMan.xml | 74 ++++++++----------- .../taskman/commons/util/XmlUtilTest.java | 4 +- 2 files changed, 31 insertions(+), 47 deletions(-) diff --git a/src/test/data/XmlUtilTest/validTaskMan.xml b/src/test/data/XmlUtilTest/validTaskMan.xml index 01fbbc37c576..bfd2c65e4163 100644 --- a/src/test/data/XmlUtilTest/validTaskMan.xml +++ b/src/test/data/XmlUtilTest/validTaskMan.xml @@ -1,58 +1,42 @@ - + - Hans Muster - 9482424 - hans@google.com - "23 June, 24 July" + Contact Hans Muster + 02 Dec 2016 01:00 + complete + 01 Nov 2016 02:00 + 01 Nov 2016 15:00 + Hans + first - Ruth Mueller - 87249245 - ruth@google.com - "23 June, 24 July" + Call Ruth Mueller + 01-02-2016 23:30 + incomplete + 12-05-2015 9pm + 12-06-2015 12am - Heinz Kurz - 95352563 - heinz@yahoo.com - "23 June, 24 July" + Hang out with Lydia Kunz + n + first - Cornelia Meier - 87652533 - cornelia@google.com - "23 June, 24 July" + Marry Anna Best + incomplete + 01-10-2015 10.35am + 01-12-2015 00:01 - Werner Meyer - 9482224 - werner@gmail.com - "23 June, 24 July" - - - Lydia Kunz - 9482427 - lydia@gmail.com - "23 June, 24 July" - - - Anna Best - 9482442 - anna@google.com - "23 June, 24 July" - - - Stefan Meier - 8482424 - stefan@mail.com - "23 June, 24 July" - - - Martin Mueller - 8482131 - hans@google.com - "23 June, 24 July" + Question Stefan Meier + y + 10-10-2017 23:30 + + Hans + + + first + diff --git a/src/test/java/seedu/taskman/commons/util/XmlUtilTest.java b/src/test/java/seedu/taskman/commons/util/XmlUtilTest.java index dfc955ee37df..f7820ccbb264 100644 --- a/src/test/java/seedu/taskman/commons/util/XmlUtilTest.java +++ b/src/test/java/seedu/taskman/commons/util/XmlUtilTest.java @@ -52,8 +52,8 @@ public void getDataFromFile_emptyFile_DataFormatMismatchException() throws Excep @Test public void getDataFromFile_validFile_validResult() throws Exception { XmlSerializableTaskMan dataFromFile = XmlUtil.getDataFromFile(VALID_FILE, XmlSerializableTaskMan.class); - assertEquals(9, dataFromFile.getActivityList().size()); - assertEquals(0, dataFromFile.getTagList().size()); + assertEquals(5, dataFromFile.getActivityList().size()); + assertEquals(2, dataFromFile.getTagList().size()); } @Test From d3b70de58ccaaa800273076d6916d7fdbdeb6b3c Mon Sep 17 00:00:00 2001 From: leeyimin Date: Sun, 6 Nov 2016 21:40:57 +0800 Subject: [PATCH 11/11] Fix todo compare TaskMan equality --- src/test/java/seedu/taskman/commons/util/XmlUtilTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/test/java/seedu/taskman/commons/util/XmlUtilTest.java b/src/test/java/seedu/taskman/commons/util/XmlUtilTest.java index f7820ccbb264..26cae6aa52bc 100644 --- a/src/test/java/seedu/taskman/commons/util/XmlUtilTest.java +++ b/src/test/java/seedu/taskman/commons/util/XmlUtilTest.java @@ -80,14 +80,13 @@ public void saveDataToFile_validFile_dataSaved() throws Exception { XmlSerializableTaskMan dataToWrite = new XmlSerializableTaskMan(new TaskMan()); XmlUtil.saveDataToFile(TEMP_FILE, dataToWrite); XmlSerializableTaskMan dataFromFile = XmlUtil.getDataFromFile(TEMP_FILE, XmlSerializableTaskMan.class); - assertEquals((new TaskMan(dataToWrite)).toString(), (new TaskMan(dataFromFile)).toString()); - //TODO: use equality instead of string comparisons + assertEquals(new TaskMan(dataToWrite), new TaskMan(dataFromFile)); TaskManBuilder builder = new TaskManBuilder(new TaskMan()); dataToWrite = new XmlSerializableTaskMan(builder.withTask(TestUtil.generateSampleTaskData().get(0)).withTag("Friends").build()); XmlUtil.saveDataToFile(TEMP_FILE, dataToWrite); dataFromFile = XmlUtil.getDataFromFile(TEMP_FILE, XmlSerializableTaskMan.class); - assertEquals((new TaskMan(dataToWrite)).toString(), (new TaskMan(dataFromFile)).toString()); + assertEquals(new TaskMan(dataToWrite), new TaskMan(dataFromFile)); } }