From b4a210de9ea475da7481cac99797b5e05aa57f25 Mon Sep 17 00:00:00 2001 From: "DESKTOP-2HNCDPM\\Ysabella" Date: Tue, 16 Oct 2018 23:21:41 +0800 Subject: [PATCH 1/4] Update TO_DO_LIST_PREFIX in CliSyntax Add parser for ToDoListAddCommand and WildcardSearchCommand.java Slight change to ToDoList.fxml --- .../logic/commands/ToDoListAddCommand.java | 2 +- .../logic/commands/WildcardSearchCommand.java | 2 +- .../seedu/address/logic/parser/CliSyntax.java | 2 +- .../logic/parser/FinancialDatabaseParser.java | 25 +++++-------- .../parser/ToDoListAddCommandParser.java | 35 ++++++++++++++++++ .../parser/WildcardSearchCommandParser.java | 36 +++++++++++++++++++ src/main/resources/view/ToDoList.fxml | 3 +- 7 files changed, 85 insertions(+), 20 deletions(-) create mode 100644 src/main/java/seedu/address/logic/parser/ToDoListAddCommandParser.java create mode 100644 src/main/java/seedu/address/logic/parser/WildcardSearchCommandParser.java diff --git a/src/main/java/seedu/address/logic/commands/ToDoListAddCommand.java b/src/main/java/seedu/address/logic/commands/ToDoListAddCommand.java index 0b20222f24c6..e780313761fb 100644 --- a/src/main/java/seedu/address/logic/commands/ToDoListAddCommand.java +++ b/src/main/java/seedu/address/logic/commands/ToDoListAddCommand.java @@ -12,7 +12,7 @@ */ public class ToDoListAddCommand extends Command { public static final String COMMAND_WORD = "todo"; - public static final String COMMAND_ALIAS = "td"; + public static final String COMMAND_ALIAS = "toDo"; public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds an action to the user's to-do list. " + "Parameters: " diff --git a/src/main/java/seedu/address/logic/commands/WildcardSearchCommand.java b/src/main/java/seedu/address/logic/commands/WildcardSearchCommand.java index 5140dcf5e408..b09622ae1e2f 100644 --- a/src/main/java/seedu/address/logic/commands/WildcardSearchCommand.java +++ b/src/main/java/seedu/address/logic/commands/WildcardSearchCommand.java @@ -16,7 +16,7 @@ public class WildcardSearchCommand extends Command{ public static final String COMMAND_ALIAS = "wcs"; public static final String MESSAGE_USAGE = COMMAND_WORD + ": Performs a wildcard search on the address book's " - + "contacts based on user's input." + + "contacts based on user's input. " + "Parameters: KEYWORD [MORE_KEYWORDS]...\n" + "Example: " + COMMAND_WORD + " oh"; diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index a4331c998574..8fd160618dec 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -14,5 +14,5 @@ public class CliSyntax { public static final Prefix PREFIX_PERSONID = new Prefix("id/"); public static final Prefix PREFIX_TRANSACTION_AMOUNT = new Prefix("ta/"); public static final Prefix PREFIX_TRANSACTION_TYPE = new Prefix("tt/"); - public static final Prefix PREFIX_TO_DO_LIST = new Prefix("td/"); + public static final Prefix PREFIX_TO_DO_LIST = new Prefix("toDo/"); } diff --git a/src/main/java/seedu/address/logic/parser/FinancialDatabaseParser.java b/src/main/java/seedu/address/logic/parser/FinancialDatabaseParser.java index 8614aa20e1c0..646c9068cca7 100644 --- a/src/main/java/seedu/address/logic/parser/FinancialDatabaseParser.java +++ b/src/main/java/seedu/address/logic/parser/FinancialDatabaseParser.java @@ -8,22 +8,7 @@ import seedu.address.MainApp; import seedu.address.Mode; -import seedu.address.logic.commands.AddCommand; -import seedu.address.logic.commands.AddTransactionCommand; -import seedu.address.logic.commands.ClearCommand; -import seedu.address.logic.commands.Command; -import seedu.address.logic.commands.DeleteCommand; -import seedu.address.logic.commands.EditCommand; -import seedu.address.logic.commands.ExitCommand; -import seedu.address.logic.commands.FindCommand; -import seedu.address.logic.commands.HelpCommand; -import seedu.address.logic.commands.HistoryCommand; -import seedu.address.logic.commands.ListCommand; -import seedu.address.logic.commands.ModeCommand; -import seedu.address.logic.commands.RedoCommand; -import seedu.address.logic.commands.SelectCommand; -import seedu.address.logic.commands.UndoCommand; -import seedu.address.logic.commands.FilterCommand; +import seedu.address.logic.commands.*; import seedu.address.logic.parser.exceptions.ParseException; @@ -115,6 +100,14 @@ public Command parseCommand(String userInput) throws ParseException { case ModeCommand.COMMAND_ALIAS: return new ModeCommand(); + case WildcardSearchCommand.COMMAND_WORD: + case WildcardSearchCommand.COMMAND_ALIAS: + return new WildcardSearchCommandParser().parse(arguments); + + case ToDoListAddCommand.COMMAND_WORD: + case ToDoListAddCommand.COMMAND_ALIAS: + return new ToDoListAddCommandParser().parse(arguments); + default: throw new ParseException(MESSAGE_UNKNOWN_COMMAND); } diff --git a/src/main/java/seedu/address/logic/parser/ToDoListAddCommandParser.java b/src/main/java/seedu/address/logic/parser/ToDoListAddCommandParser.java new file mode 100644 index 000000000000..d15b68b185e1 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/ToDoListAddCommandParser.java @@ -0,0 +1,35 @@ +package seedu.address.logic.parser; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; + +import java.util.Arrays; + +import seedu.address.logic.commands.FindCommand; +import seedu.address.logic.commands.ToDoListAddCommand; +import seedu.address.logic.commands.WildcardSearchCommand; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.person.NameContainsLettersPredicate; + +/** + * + */ + +public class ToDoListAddCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the ToDoListAddCommand + * and returns an ToDoListAddCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + + public ToDoListAddCommand parse(String args) throws ParseException { + if (args.isEmpty()) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, ToDoListAddCommand.MESSAGE_USAGE)); + } + + return new ToDoListAddCommand(args); + } +} + diff --git a/src/main/java/seedu/address/logic/parser/WildcardSearchCommandParser.java b/src/main/java/seedu/address/logic/parser/WildcardSearchCommandParser.java new file mode 100644 index 000000000000..fef6215703fe --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/WildcardSearchCommandParser.java @@ -0,0 +1,36 @@ +package seedu.address.logic.parser; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; + +import java.util.Arrays; + +import seedu.address.logic.commands.FindCommand; +import seedu.address.logic.commands.WildcardSearchCommand; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.person.NameContainsLettersPredicate; + +/** + * + */ + +public class WildcardSearchCommandParser implements Parser{ + + /** + * Parses the given {@code String} of arguments in the context of the WildcardSearchCommand + * and returns an WildcardSearchCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + + public WildcardSearchCommand parse(String args) throws ParseException { + String trimmedArgs = args.trim(); + if (trimmedArgs.isEmpty()) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, WildcardSearchCommand.MESSAGE_USAGE)); + } + + String[] nameKeywords = trimmedArgs.split("\\s+"); + + return new WildcardSearchCommand(new NameContainsLettersPredicate(Arrays.asList(nameKeywords))); + } +} diff --git a/src/main/resources/view/ToDoList.fxml b/src/main/resources/view/ToDoList.fxml index c97cdd937a30..ddcbf24f65e4 100644 --- a/src/main/resources/view/ToDoList.fxml +++ b/src/main/resources/view/ToDoList.fxml @@ -3,13 +3,14 @@ + -