diff --git a/src/main/java/seedu/address/logic/commands/HelpCommand.java b/src/main/java/seedu/address/logic/commands/HelpCommand.java index 3bf9bdd4edc..2ae35c01065 100644 --- a/src/main/java/seedu/address/logic/commands/HelpCommand.java +++ b/src/main/java/seedu/address/logic/commands/HelpCommand.java @@ -1,5 +1,10 @@ package seedu.address.logic.commands; +import seedu.address.logic.commands.contact.AddContactCommand; +import seedu.address.logic.commands.contact.DeleteContactCommand; +import seedu.address.logic.commands.contact.EditContactCommand; +import seedu.address.logic.commands.contact.FindContactCommand; +import seedu.address.logic.commands.contact.ListContactCommand; import seedu.address.model.Model; /** diff --git a/src/main/java/seedu/address/logic/commands/AddContactCommand.java b/src/main/java/seedu/address/logic/commands/contact/AddContactCommand.java similarity index 94% rename from src/main/java/seedu/address/logic/commands/AddContactCommand.java rename to src/main/java/seedu/address/logic/commands/contact/AddContactCommand.java index 66ca8ce9243..b6c3fa0f0c5 100644 --- a/src/main/java/seedu/address/logic/commands/AddContactCommand.java +++ b/src/main/java/seedu/address/logic/commands/contact/AddContactCommand.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.contact; import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; @@ -7,6 +7,8 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.person.Person; diff --git a/src/main/java/seedu/address/logic/commands/DeleteContactCommand.java b/src/main/java/seedu/address/logic/commands/contact/DeleteContactCommand.java similarity index 93% rename from src/main/java/seedu/address/logic/commands/DeleteContactCommand.java rename to src/main/java/seedu/address/logic/commands/contact/DeleteContactCommand.java index 18fc1f6231a..15a6556ddd2 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteContactCommand.java +++ b/src/main/java/seedu/address/logic/commands/contact/DeleteContactCommand.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.contact; import static java.util.Objects.requireNonNull; @@ -6,6 +6,8 @@ import seedu.address.commons.core.Messages; import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.person.Person; diff --git a/src/main/java/seedu/address/logic/commands/EditContactCommand.java b/src/main/java/seedu/address/logic/commands/contact/EditContactCommand.java similarity index 98% rename from src/main/java/seedu/address/logic/commands/EditContactCommand.java rename to src/main/java/seedu/address/logic/commands/contact/EditContactCommand.java index a9826252170..628e59c120e 100644 --- a/src/main/java/seedu/address/logic/commands/EditContactCommand.java +++ b/src/main/java/seedu/address/logic/commands/contact/EditContactCommand.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.contact; import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; @@ -17,6 +17,8 @@ import seedu.address.commons.core.Messages; import seedu.address.commons.core.index.Index; import seedu.address.commons.util.CollectionUtil; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.person.Address; diff --git a/src/main/java/seedu/address/logic/commands/FindContactCommand.java b/src/main/java/seedu/address/logic/commands/contact/FindContactCommand.java similarity index 79% rename from src/main/java/seedu/address/logic/commands/FindContactCommand.java rename to src/main/java/seedu/address/logic/commands/contact/FindContactCommand.java index 84cfff1d3c2..e8910c80940 100644 --- a/src/main/java/seedu/address/logic/commands/FindContactCommand.java +++ b/src/main/java/seedu/address/logic/commands/contact/FindContactCommand.java @@ -1,10 +1,12 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.contact; import static java.util.Objects.requireNonNull; import seedu.address.commons.core.Messages; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.model.Model; -import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.person.PersonContainsKeywordsPredicate; /** * Finds and lists all persons in address book whose name contains any of the argument keywords. @@ -19,9 +21,9 @@ public class FindContactCommand extends Command { + "Parameters: KEYWORD [MORE_KEYWORDS]...\n" + "Example: " + COMMAND_WORD + " alice bob charlie"; - private final NameContainsKeywordsPredicate predicate; + private final PersonContainsKeywordsPredicate predicate; - public FindContactCommand(NameContainsKeywordsPredicate predicate) { + public FindContactCommand(PersonContainsKeywordsPredicate predicate) { this.predicate = predicate; } diff --git a/src/main/java/seedu/address/logic/commands/ListContactCommand.java b/src/main/java/seedu/address/logic/commands/contact/ListContactCommand.java similarity index 81% rename from src/main/java/seedu/address/logic/commands/ListContactCommand.java rename to src/main/java/seedu/address/logic/commands/contact/ListContactCommand.java index bdf69bc67a6..6325c79d0bc 100644 --- a/src/main/java/seedu/address/logic/commands/ListContactCommand.java +++ b/src/main/java/seedu/address/logic/commands/contact/ListContactCommand.java @@ -1,8 +1,10 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.contact; import static java.util.Objects.requireNonNull; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.model.Model; /** diff --git a/src/main/java/seedu/address/logic/commands/AddTagCommand.java b/src/main/java/seedu/address/logic/commands/tag/AddTagCommand.java similarity index 98% rename from src/main/java/seedu/address/logic/commands/AddTagCommand.java rename to src/main/java/seedu/address/logic/commands/tag/AddTagCommand.java index 4a90243913a..8efcbbcf087 100644 --- a/src/main/java/seedu/address/logic/commands/AddTagCommand.java +++ b/src/main/java/seedu/address/logic/commands/tag/AddTagCommand.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.tag; import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; @@ -13,6 +13,8 @@ import seedu.address.commons.core.Messages; import seedu.address.commons.core.index.Index; import seedu.address.commons.util.CollectionUtil; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.person.Address; diff --git a/src/main/java/seedu/address/logic/commands/DeleteTagCommand.java b/src/main/java/seedu/address/logic/commands/tag/DeleteTagCommand.java similarity index 98% rename from src/main/java/seedu/address/logic/commands/DeleteTagCommand.java rename to src/main/java/seedu/address/logic/commands/tag/DeleteTagCommand.java index 169186ad22d..db0270e20f1 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteTagCommand.java +++ b/src/main/java/seedu/address/logic/commands/tag/DeleteTagCommand.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.tag; import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; @@ -13,6 +13,8 @@ import seedu.address.commons.core.Messages; import seedu.address.commons.core.index.Index; import seedu.address.commons.util.CollectionUtil; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.person.Address; diff --git a/src/main/java/seedu/address/logic/commands/AddTaskCommand.java b/src/main/java/seedu/address/logic/commands/task/AddTaskCommand.java similarity index 92% rename from src/main/java/seedu/address/logic/commands/AddTaskCommand.java rename to src/main/java/seedu/address/logic/commands/task/AddTaskCommand.java index 8db25b64c86..b709e36a5c6 100644 --- a/src/main/java/seedu/address/logic/commands/AddTaskCommand.java +++ b/src/main/java/seedu/address/logic/commands/task/AddTaskCommand.java @@ -1,9 +1,11 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.task; import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_TASK_DEADLINE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TASK_DESCRIPTION; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.task.Task; diff --git a/src/main/java/seedu/address/logic/commands/ListTaskCommand.java b/src/main/java/seedu/address/logic/commands/task/ListTaskCommand.java similarity index 80% rename from src/main/java/seedu/address/logic/commands/ListTaskCommand.java rename to src/main/java/seedu/address/logic/commands/task/ListTaskCommand.java index 41d1c9f2403..a4e1a7b153f 100644 --- a/src/main/java/seedu/address/logic/commands/ListTaskCommand.java +++ b/src/main/java/seedu/address/logic/commands/task/ListTaskCommand.java @@ -1,8 +1,10 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.task; import static java.util.Objects.requireNonNull; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_TASKS; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.model.Model; /** diff --git a/src/main/java/seedu/address/logic/commands/MarkTaskCommand.java b/src/main/java/seedu/address/logic/commands/task/MarkTaskCommand.java similarity index 92% rename from src/main/java/seedu/address/logic/commands/MarkTaskCommand.java rename to src/main/java/seedu/address/logic/commands/task/MarkTaskCommand.java index 06d163df18c..afce0df08a5 100644 --- a/src/main/java/seedu/address/logic/commands/MarkTaskCommand.java +++ b/src/main/java/seedu/address/logic/commands/task/MarkTaskCommand.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.task; import static java.util.Objects.requireNonNull; @@ -6,6 +6,8 @@ import seedu.address.commons.core.Messages; import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.task.Task; diff --git a/src/main/java/seedu/address/logic/commands/UnmarkTaskCommand.java b/src/main/java/seedu/address/logic/commands/task/UnmarkTaskCommand.java similarity index 92% rename from src/main/java/seedu/address/logic/commands/UnmarkTaskCommand.java rename to src/main/java/seedu/address/logic/commands/task/UnmarkTaskCommand.java index 73f04ef06cb..414b7238401 100644 --- a/src/main/java/seedu/address/logic/commands/UnmarkTaskCommand.java +++ b/src/main/java/seedu/address/logic/commands/task/UnmarkTaskCommand.java @@ -1,4 +1,4 @@ -package seedu.address.logic.commands; +package seedu.address.logic.commands.task; import static java.util.Objects.requireNonNull; @@ -6,6 +6,8 @@ import seedu.address.commons.core.Messages; import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.task.Task; diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 84010dac096..14380611554 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -6,21 +6,29 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import seedu.address.logic.commands.AddContactCommand; -import seedu.address.logic.commands.AddTagCommand; import seedu.address.logic.commands.ClearCommand; import seedu.address.logic.commands.Command; -import seedu.address.logic.commands.DeleteContactCommand; -import seedu.address.logic.commands.DeleteTagCommand; -import seedu.address.logic.commands.EditContactCommand; import seedu.address.logic.commands.ExitCommand; -import seedu.address.logic.commands.FindContactCommand; import seedu.address.logic.commands.HelpCommand; -import seedu.address.logic.commands.ListContactCommand; -import seedu.address.logic.commands.ListTaskCommand; -import seedu.address.logic.commands.MarkTaskCommand; -import seedu.address.logic.commands.UnmarkTaskCommand; +import seedu.address.logic.commands.contact.AddContactCommand; +import seedu.address.logic.commands.contact.DeleteContactCommand; +import seedu.address.logic.commands.contact.EditContactCommand; +import seedu.address.logic.commands.contact.FindContactCommand; +import seedu.address.logic.commands.contact.ListContactCommand; +import seedu.address.logic.commands.tag.AddTagCommand; +import seedu.address.logic.commands.tag.DeleteTagCommand; +import seedu.address.logic.commands.task.ListTaskCommand; +import seedu.address.logic.commands.task.MarkTaskCommand; +import seedu.address.logic.commands.task.UnmarkTaskCommand; +import seedu.address.logic.parser.contact.AddContactCommandParser; +import seedu.address.logic.parser.contact.DeleteContactCommandParser; +import seedu.address.logic.parser.contact.EditContactCommandParser; +import seedu.address.logic.parser.contact.FindContactCommandParser; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.logic.parser.tag.AddTagCommandParser; +import seedu.address.logic.parser.tag.DeleteTagCommandParser; +import seedu.address.logic.parser.task.MarkTaskCommandParser; +import seedu.address.logic.parser.task.UnmarkTaskCommandParser; /** * Parses user input. diff --git a/src/main/java/seedu/address/logic/parser/FindContactCommandParser.java b/src/main/java/seedu/address/logic/parser/FindContactCommandParser.java deleted file mode 100644 index 9271ab39dca..00000000000 --- a/src/main/java/seedu/address/logic/parser/FindContactCommandParser.java +++ /dev/null @@ -1,33 +0,0 @@ -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.FindContactCommand; -import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.NameContainsKeywordsPredicate; - -/** - * Parses input arguments and creates a new FindContactCommand object - */ -public class FindContactCommandParser implements Parser { - - /** - * Parses the given {@code String} of arguments in the context of the FindContactCommand - * and returns a FindContactCommand object for execution. - * @throws ParseException if the user input does not conform the expected format - */ - public FindContactCommand parse(String args) throws ParseException { - String trimmedArgs = args.trim(); - if (trimmedArgs.isEmpty()) { - throw new ParseException( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindContactCommand.MESSAGE_USAGE)); - } - - String[] nameKeywords = trimmedArgs.split("\\s+"); - - return new FindContactCommand(new NameContainsKeywordsPredicate(Arrays.asList(nameKeywords))); - } - -} diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index a77f42b2c5f..508736647c7 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -2,8 +2,10 @@ import static java.util.Objects.requireNonNull; +import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.List; import java.util.Set; import seedu.address.commons.core.index.Index; @@ -51,6 +53,26 @@ public static Name parseName(String name) throws ParseException { return new Name(trimmedName); } + /** + * Parses a string of {@code String names} into a list of {@code String names}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if any {@code name} is invalid. + */ + public static List parseNames(String names) throws ParseException { + requireNonNull(names); + String trimmedNames = names.trim(); + String[] nameArr = trimmedNames.split(" "); + ArrayList nameList = new ArrayList<>(); + for (String name : nameArr) { + if (!Name.isValidName(name)) { + throw new ParseException(Name.MESSAGE_CONSTRAINTS); + } + nameList.add(new Name(name)); + } + return nameList; + } + /** * Parses a {@code String phone} into a {@code Phone}. * Leading and trailing whitespaces will be trimmed. @@ -66,6 +88,26 @@ public static Phone parsePhone(String phone) throws ParseException { return new Phone(trimmedPhone); } + /** + * Parses a string of {@code String phones} into a list of {@code String phones}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if any {@code phone} is invalid. + */ + public static List parsePhones(String phones) throws ParseException { + requireNonNull(phones); + String trimmedNames = phones.trim(); + String[] phoneArr = trimmedNames.split(" "); + ArrayList phoneList = new ArrayList<>(); + for (String phone : phoneArr) { + if (!Phone.isValidPhone(phone)) { + throw new ParseException(Phone.MESSAGE_CONSTRAINTS); + } + phoneList.add(new Phone(phone)); + } + return phoneList; + } + /** * Parses a {@code String address} into an {@code Address}. * Leading and trailing whitespaces will be trimmed. @@ -81,6 +123,26 @@ public static Address parseAddress(String address) throws ParseException { return new Address(trimmedAddress); } + /** + * Parses a string of {@code String addresses} into a list of {@code String addresses}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if any {@code address} is invalid. + */ + public static List
parseAddresses(String addresses) throws ParseException { + requireNonNull(addresses); + String trimmedNames = addresses.trim(); + String[] addressArr = trimmedNames.split(" "); + ArrayList
addressList = new ArrayList<>(); + for (String address : addressArr) { + if (!Address.isValidAddress(address)) { + throw new ParseException(Address.MESSAGE_CONSTRAINTS); + } + addressList.add(new Address(address)); + } + return addressList; + } + /** * Parses a {@code String email} into an {@code Email}. * Leading and trailing whitespaces will be trimmed. @@ -96,6 +158,26 @@ public static Email parseEmail(String email) throws ParseException { return new Email(trimmedEmail); } + /** + * Parses a string of {@code String emails} into a list of {@code String emails}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if any {@code email} is invalid. + */ + public static List parseEmails(String emails) throws ParseException { + requireNonNull(emails); + String trimmedNames = emails.trim(); + String[] emailArr = trimmedNames.split(" "); + ArrayList emailList = new ArrayList<>(); + for (String email : emailArr) { + if (!Email.isValidEmail(email)) { + throw new ParseException(Email.MESSAGE_CONSTRAINTS); + } + emailList.add(new Email(email)); + } + return emailList; + } + /** * Parses a {@code String tag} into a {@code Tag}. * Leading and trailing whitespaces will be trimmed. diff --git a/src/main/java/seedu/address/logic/parser/AddContactCommandParser.java b/src/main/java/seedu/address/logic/parser/contact/AddContactCommandParser.java similarity index 88% rename from src/main/java/seedu/address/logic/parser/AddContactCommandParser.java rename to src/main/java/seedu/address/logic/parser/contact/AddContactCommandParser.java index b3db32c6cbd..65b385dc391 100644 --- a/src/main/java/seedu/address/logic/parser/AddContactCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/contact/AddContactCommandParser.java @@ -1,4 +1,4 @@ -package seedu.address.logic.parser; +package seedu.address.logic.parser.contact; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; @@ -10,7 +10,12 @@ import java.util.Set; import java.util.stream.Stream; -import seedu.address.logic.commands.AddContactCommand; +import seedu.address.logic.commands.contact.AddContactCommand; +import seedu.address.logic.parser.ArgumentMultimap; +import seedu.address.logic.parser.ArgumentTokenizer; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.ParserUtil; +import seedu.address.logic.parser.Prefix; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.person.Address; import seedu.address.model.person.Email; diff --git a/src/main/java/seedu/address/logic/parser/DeleteContactCommandParser.java b/src/main/java/seedu/address/logic/parser/contact/DeleteContactCommandParser.java similarity index 83% rename from src/main/java/seedu/address/logic/parser/DeleteContactCommandParser.java rename to src/main/java/seedu/address/logic/parser/contact/DeleteContactCommandParser.java index 6d348f2e5b6..33e6dee20f7 100644 --- a/src/main/java/seedu/address/logic/parser/DeleteContactCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/contact/DeleteContactCommandParser.java @@ -1,9 +1,11 @@ -package seedu.address.logic.parser; +package seedu.address.logic.parser.contact; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.DeleteContactCommand; +import seedu.address.logic.commands.contact.DeleteContactCommand; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.ParserUtil; import seedu.address.logic.parser.exceptions.ParseException; /** diff --git a/src/main/java/seedu/address/logic/parser/EditContactCommandParser.java b/src/main/java/seedu/address/logic/parser/contact/EditContactCommandParser.java similarity index 89% rename from src/main/java/seedu/address/logic/parser/EditContactCommandParser.java rename to src/main/java/seedu/address/logic/parser/contact/EditContactCommandParser.java index 2fcdbf84aaa..e360e1998da 100644 --- a/src/main/java/seedu/address/logic/parser/EditContactCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/contact/EditContactCommandParser.java @@ -1,4 +1,4 @@ -package seedu.address.logic.parser; +package seedu.address.logic.parser.contact; import static java.util.Objects.requireNonNull; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; @@ -14,8 +14,12 @@ import java.util.Set; import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.EditContactCommand; -import seedu.address.logic.commands.EditContactCommand.EditPersonDescriptor; +import seedu.address.logic.commands.contact.EditContactCommand; +import seedu.address.logic.commands.contact.EditContactCommand.EditPersonDescriptor; +import seedu.address.logic.parser.ArgumentMultimap; +import seedu.address.logic.parser.ArgumentTokenizer; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.ParserUtil; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.tag.Tag; diff --git a/src/main/java/seedu/address/logic/parser/contact/FindContactCommandParser.java b/src/main/java/seedu/address/logic/parser/contact/FindContactCommandParser.java new file mode 100644 index 00000000000..5b6c886cb62 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/contact/FindContactCommandParser.java @@ -0,0 +1,92 @@ +package seedu.address.logic.parser.contact; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + +import seedu.address.logic.commands.contact.FindContactCommand; +import seedu.address.logic.parser.ArgumentMultimap; +import seedu.address.logic.parser.ArgumentTokenizer; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.ParserUtil; +import seedu.address.logic.parser.Prefix; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.person.Address; +import seedu.address.model.person.Email; +import seedu.address.model.person.Name; +import seedu.address.model.person.PersonContainsKeywordsPredicate; +import seedu.address.model.person.Phone; + +/** + * Parses input arguments and creates a new FindContactCommand object + */ +public class FindContactCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the FindContactCommand + * and returns a FindContactCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public FindContactCommand parse(String args) throws ParseException { + ArgumentMultimap argMultimap = + ArgumentTokenizer.tokenize(args, PREFIX_NAME, + PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS); + + if (arePrefixesEmpty(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, + PREFIX_PHONE, PREFIX_EMAIL) + || !argMultimap.getPreamble().isEmpty()) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, + FindContactCommand.MESSAGE_USAGE)); + } + + List names = getNames(argMultimap); + List phones = getPhones(argMultimap); + List emails = getEmails(argMultimap); + List
addresses = getAddresses(argMultimap); + + return new FindContactCommand(new PersonContainsKeywordsPredicate(names, phones, emails, addresses)); + } + + private List getNames(ArgumentMultimap argMultimap) throws ParseException { + if (argMultimap.getValue(PREFIX_NAME).isEmpty()) { + return new ArrayList<>(); + } + return ParserUtil.parseNames(argMultimap.getValue(PREFIX_NAME).get()); + } + + private List getPhones(ArgumentMultimap argMultimap) throws ParseException { + if (argMultimap.getValue(PREFIX_PHONE).isEmpty()) { + return new ArrayList<>(); + } + return ParserUtil.parsePhones(argMultimap.getValue(PREFIX_PHONE).get()); + } + + private List getEmails(ArgumentMultimap argMultimap) throws ParseException { + if (argMultimap.getValue(PREFIX_EMAIL).isEmpty()) { + return new ArrayList<>(); + } + return ParserUtil.parseEmails(argMultimap.getValue(PREFIX_EMAIL).get()); + } + + private List
getAddresses(ArgumentMultimap argMultimap) throws ParseException { + if (argMultimap.getValue(PREFIX_ADDRESS).isEmpty()) { + return new ArrayList<>(); + } + return ParserUtil.parseAddresses(argMultimap.getValue(PREFIX_ADDRESS).get()); + } + + /** + * Returns true if all the prefixes contains empty {@code Optional} values in the given + * {@code ArgumentMultimap}. + */ + private static boolean arePrefixesEmpty(ArgumentMultimap argumentMultimap, Prefix... prefixes) { + return Stream.of(prefixes).noneMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); + } +} diff --git a/src/main/java/seedu/address/logic/parser/AddTagCommandParser.java b/src/main/java/seedu/address/logic/parser/tag/AddTagCommandParser.java similarity index 90% rename from src/main/java/seedu/address/logic/parser/AddTagCommandParser.java rename to src/main/java/seedu/address/logic/parser/tag/AddTagCommandParser.java index 7e563f15723..d687e353a68 100644 --- a/src/main/java/seedu/address/logic/parser/AddTagCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/tag/AddTagCommandParser.java @@ -1,4 +1,4 @@ -package seedu.address.logic.parser; +package seedu.address.logic.parser.tag; import static java.util.Objects.requireNonNull; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; @@ -14,8 +14,12 @@ import java.util.Set; import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.AddTagCommand; -import seedu.address.logic.commands.AddTagCommand.EditPersonDescriptor; +import seedu.address.logic.commands.tag.AddTagCommand; +import seedu.address.logic.commands.tag.AddTagCommand.EditPersonDescriptor; +import seedu.address.logic.parser.ArgumentMultimap; +import seedu.address.logic.parser.ArgumentTokenizer; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.ParserUtil; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.tag.Tag; diff --git a/src/main/java/seedu/address/logic/parser/DeleteTagCommandParser.java b/src/main/java/seedu/address/logic/parser/tag/DeleteTagCommandParser.java similarity index 88% rename from src/main/java/seedu/address/logic/parser/DeleteTagCommandParser.java rename to src/main/java/seedu/address/logic/parser/tag/DeleteTagCommandParser.java index 58256ff1452..5c0980077c1 100644 --- a/src/main/java/seedu/address/logic/parser/DeleteTagCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/tag/DeleteTagCommandParser.java @@ -1,4 +1,4 @@ -package seedu.address.logic.parser; +package seedu.address.logic.parser.tag; import static java.util.Objects.requireNonNull; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; @@ -14,9 +14,13 @@ import java.util.Set; import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.AddTagCommand; -import seedu.address.logic.commands.DeleteTagCommand; -import seedu.address.logic.commands.DeleteTagCommand.EditPersonDescriptor; +import seedu.address.logic.commands.tag.AddTagCommand; +import seedu.address.logic.commands.tag.DeleteTagCommand; +import seedu.address.logic.commands.tag.DeleteTagCommand.EditPersonDescriptor; +import seedu.address.logic.parser.ArgumentMultimap; +import seedu.address.logic.parser.ArgumentTokenizer; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.ParserUtil; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.tag.Tag; diff --git a/src/main/java/seedu/address/logic/parser/AddTaskCommandParser.java b/src/main/java/seedu/address/logic/parser/task/AddTaskCommandParser.java similarity index 84% rename from src/main/java/seedu/address/logic/parser/AddTaskCommandParser.java rename to src/main/java/seedu/address/logic/parser/task/AddTaskCommandParser.java index 69823640c58..28599890964 100644 --- a/src/main/java/seedu/address/logic/parser/AddTaskCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/task/AddTaskCommandParser.java @@ -1,4 +1,4 @@ -package seedu.address.logic.parser; +package seedu.address.logic.parser.task; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.parser.CliSyntax.PREFIX_TASK_DEADLINE; @@ -6,7 +6,12 @@ import java.util.stream.Stream; -import seedu.address.logic.commands.AddTaskCommand; +import seedu.address.logic.commands.task.AddTaskCommand; +import seedu.address.logic.parser.ArgumentMultimap; +import seedu.address.logic.parser.ArgumentTokenizer; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.ParserUtil; +import seedu.address.logic.parser.Prefix; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.task.Description; import seedu.address.model.task.Task; diff --git a/src/main/java/seedu/address/logic/parser/MarkTaskCommandParser.java b/src/main/java/seedu/address/logic/parser/task/MarkTaskCommandParser.java similarity index 83% rename from src/main/java/seedu/address/logic/parser/MarkTaskCommandParser.java rename to src/main/java/seedu/address/logic/parser/task/MarkTaskCommandParser.java index 7638b822640..3961cf4d3c4 100644 --- a/src/main/java/seedu/address/logic/parser/MarkTaskCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/task/MarkTaskCommandParser.java @@ -1,9 +1,11 @@ -package seedu.address.logic.parser; +package seedu.address.logic.parser.task; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.MarkTaskCommand; +import seedu.address.logic.commands.task.MarkTaskCommand; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.ParserUtil; import seedu.address.logic.parser.exceptions.ParseException; /** diff --git a/src/main/java/seedu/address/logic/parser/UnmarkTaskCommandParser.java b/src/main/java/seedu/address/logic/parser/task/UnmarkTaskCommandParser.java similarity index 83% rename from src/main/java/seedu/address/logic/parser/UnmarkTaskCommandParser.java rename to src/main/java/seedu/address/logic/parser/task/UnmarkTaskCommandParser.java index c807f2116b4..043885e913d 100644 --- a/src/main/java/seedu/address/logic/parser/UnmarkTaskCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/task/UnmarkTaskCommandParser.java @@ -1,9 +1,11 @@ -package seedu.address.logic.parser; +package seedu.address.logic.parser.task; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.UnmarkTaskCommand; +import seedu.address.logic.commands.task.UnmarkTaskCommand; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.ParserUtil; import seedu.address.logic.parser.exceptions.ParseException; /** diff --git a/src/main/java/seedu/address/model/person/PersonContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/person/PersonContainsKeywordsPredicate.java new file mode 100644 index 00000000000..c3034a44540 --- /dev/null +++ b/src/main/java/seedu/address/model/person/PersonContainsKeywordsPredicate.java @@ -0,0 +1,63 @@ +package seedu.address.model.person; + +import java.util.List; +import java.util.function.Predicate; + +import seedu.address.commons.util.StringUtil; + +/** + * Tests that a {@code Person}'s {@code Name} and/or {@code Phone} and/or {@code Email} and/or {@code Address} + * matches any of the keywords given. + */ +public class PersonContainsKeywordsPredicate implements Predicate { + private final List nameKeywords; + private final List phoneKeywords; + private final List emailKeywords; + private final List
addressKeywords; + + /** + * Constructs an {@code PersonContainsKeywordsPredicate}. + * + * @param nameKeywords A list containing keywords for {@code Name}. + * @param phoneKeywords A list containing keywords for {@code Phone}. + * @param emailKeywords A list containing keywords for {@code Email}. + * @param addressKeywords A list containing keywords for {@code Address}. + */ + public PersonContainsKeywordsPredicate(List nameKeywords, + List phoneKeywords, List emailKeywords, List
addressKeywords) { + this.nameKeywords = nameKeywords; + this.phoneKeywords = phoneKeywords; + this.emailKeywords = emailKeywords; + this.addressKeywords = addressKeywords; + } + + @Override + public boolean test(Person person) { + return (nameKeywords.isEmpty() || nameKeywords.stream().anyMatch(keyword -> + StringUtil.containsWordIgnoreCase(person.getName().fullName, keyword.toString()))) + && (phoneKeywords.isEmpty() || phoneKeywords.stream().anyMatch(keyword -> + StringUtil.containsWordIgnoreCase(person.getPhone().value, keyword.toString()))) + && (emailKeywords.isEmpty() || emailKeywords.stream().anyMatch(keyword -> + StringUtil.containsWordIgnoreCase(person.getEmail().value, keyword.toString()))) + && (addressKeywords.isEmpty() || addressKeywords.stream().anyMatch(keyword -> + StringUtil.containsWordIgnoreCase(person.getAddress().value, keyword.toString()))); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + if (!(other instanceof PersonContainsKeywordsPredicate)) { + return false; + } + + PersonContainsKeywordsPredicate castedOther = (PersonContainsKeywordsPredicate) other; + + return nameKeywords.equals(castedOther.nameKeywords) + && phoneKeywords.equals(castedOther.phoneKeywords) + && emailKeywords.equals(castedOther.emailKeywords) + && addressKeywords.equals(castedOther.addressKeywords); + } +} diff --git a/src/test/java/seedu/address/logic/LogicManagerTest.java b/src/test/java/seedu/address/logic/LogicManagerTest.java index 044fb38ebae..f88d2a5f75f 100644 --- a/src/test/java/seedu/address/logic/LogicManagerTest.java +++ b/src/test/java/seedu/address/logic/LogicManagerTest.java @@ -17,9 +17,9 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import seedu.address.logic.commands.AddContactCommand; import seedu.address.logic.commands.CommandResult; -import seedu.address.logic.commands.ListContactCommand; +import seedu.address.logic.commands.contact.AddContactCommand; +import seedu.address.logic.commands.contact.ListContactCommand; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.Model; diff --git a/src/test/java/seedu/address/logic/commands/AddContactCommandIntegrationTest.java b/src/test/java/seedu/address/logic/commands/AddContactCommandIntegrationTest.java index 310f001d975..2e8d9a76cbf 100644 --- a/src/test/java/seedu/address/logic/commands/AddContactCommandIntegrationTest.java +++ b/src/test/java/seedu/address/logic/commands/AddContactCommandIntegrationTest.java @@ -7,6 +7,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import seedu.address.logic.commands.contact.AddContactCommand; import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; diff --git a/src/test/java/seedu/address/logic/commands/AddContactCommandTest.java b/src/test/java/seedu/address/logic/commands/AddContactCommandTest.java index 6d5f235a77a..5c9a38b958b 100644 --- a/src/test/java/seedu/address/logic/commands/AddContactCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddContactCommandTest.java @@ -15,6 +15,7 @@ import javafx.collections.ObservableList; import seedu.address.commons.core.GuiSettings; +import seedu.address.logic.commands.contact.AddContactCommand; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.AddressBook; import seedu.address.model.Model; diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index da3c961f9a5..c425ffda731 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -14,6 +14,7 @@ import java.util.List; import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.contact.EditContactCommand; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.AddressBook; import seedu.address.model.Model; diff --git a/src/test/java/seedu/address/logic/commands/DeleteContactCommandTest.java b/src/test/java/seedu/address/logic/commands/DeleteContactCommandTest.java index 488c5ea81e4..61256ad37ed 100644 --- a/src/test/java/seedu/address/logic/commands/DeleteContactCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/DeleteContactCommandTest.java @@ -13,6 +13,7 @@ import seedu.address.commons.core.Messages; import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.contact.DeleteContactCommand; import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; diff --git a/src/test/java/seedu/address/logic/commands/EditContactCommandTest.java b/src/test/java/seedu/address/logic/commands/EditContactCommandTest.java index ab4371301e0..7783ecef3c8 100644 --- a/src/test/java/seedu/address/logic/commands/EditContactCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/EditContactCommandTest.java @@ -18,7 +18,8 @@ import seedu.address.commons.core.Messages; import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.EditContactCommand.EditPersonDescriptor; +import seedu.address.logic.commands.contact.EditContactCommand; +import seedu.address.logic.commands.contact.EditContactCommand.EditPersonDescriptor; import seedu.address.model.AddressBook; import seedu.address.model.Model; import seedu.address.model.ModelManager; diff --git a/src/test/java/seedu/address/logic/commands/EditPersonDescriptorTest.java b/src/test/java/seedu/address/logic/commands/EditPersonDescriptorTest.java index 9c6a3229db4..df031dc4353 100644 --- a/src/test/java/seedu/address/logic/commands/EditPersonDescriptorTest.java +++ b/src/test/java/seedu/address/logic/commands/EditPersonDescriptorTest.java @@ -12,7 +12,7 @@ import org.junit.jupiter.api.Test; -import seedu.address.logic.commands.EditContactCommand.EditPersonDescriptor; +import seedu.address.logic.commands.contact.EditContactCommand.EditPersonDescriptor; import seedu.address.testutil.EditPersonDescriptorBuilder; public class EditPersonDescriptorTest { diff --git a/src/test/java/seedu/address/logic/commands/FindContactCommandTest.java b/src/test/java/seedu/address/logic/commands/FindContactCommandTest.java index 57f5e6bb99c..ae875d2a3fd 100644 --- a/src/test/java/seedu/address/logic/commands/FindContactCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/FindContactCommandTest.java @@ -5,20 +5,25 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.commons.core.Messages.MESSAGE_PERSONS_LISTED_OVERVIEW; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.address.testutil.TypicalPersons.CARL; -import static seedu.address.testutil.TypicalPersons.ELLE; -import static seedu.address.testutil.TypicalPersons.FIONA; +import static seedu.address.testutil.TypicalPersons.ALICE; +import static seedu.address.testutil.TypicalPersons.BENSON; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; +import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; +import java.util.List; import org.junit.jupiter.api.Test; +import seedu.address.logic.commands.contact.FindContactCommand; import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; -import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.person.Address; +import seedu.address.model.person.Email; +import seedu.address.model.person.Name; +import seedu.address.model.person.PersonContainsKeywordsPredicate; +import seedu.address.model.person.Phone; /** * Contains integration tests (interaction with the Model) for {@code FindContactCommand}. @@ -27,12 +32,34 @@ public class FindContactCommandTest { private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + private final String nameKeyword1 = "Alice"; + private final String nameKeyword2 = "Benson"; + private final String phoneKeyword1 = "999"; + private final String phoneKeyword2 = "62353535"; + private final String emailKeyword1 = "john@gmail.com"; + private final String emailKeyword2 = "colonel-sanders-123@kfc.co.uk"; + private final String addressKeyword1 = "17A Lower Kent Ridge Road, #01-01, S(119081)"; + private final String addressKeyword2 = "17A Lower Kent Ridge Road, c/o reception@sally, #01-01, S(119081)"; + + private final List nameKeywords = Arrays.asList(new Name(nameKeyword1), new Name(nameKeyword2)); + private final List phoneKeywords = Arrays.asList(new Phone(phoneKeyword1), new Phone(phoneKeyword2)); + private final List emailKeywords = Arrays.asList(new Email(emailKeyword1), new Email(emailKeyword2)); + private final List
addressKeywords = Arrays.asList(new Address(addressKeyword1), + new Address(addressKeyword2)); + + private final List emptyNameKeywords = new ArrayList<>(); + private final List emptyPhoneKeywords = new ArrayList<>(); + private final List emptyEmailKeywords = new ArrayList<>(); + private final List
emptyAddressKeywords = new ArrayList<>(); + @Test public void equals() { - NameContainsKeywordsPredicate firstPredicate = - new NameContainsKeywordsPredicate(Collections.singletonList("first")); - NameContainsKeywordsPredicate secondPredicate = - new NameContainsKeywordsPredicate(Collections.singletonList("second")); + PersonContainsKeywordsPredicate firstPredicate = + new PersonContainsKeywordsPredicate(nameKeywords, phoneKeywords, + emailKeywords, addressKeywords); + PersonContainsKeywordsPredicate secondPredicate = + new PersonContainsKeywordsPredicate(nameKeywords, emptyPhoneKeywords, + emptyEmailKeywords, emptyAddressKeywords); FindContactCommand findFirstCommand = new FindContactCommand(firstPredicate); FindContactCommand findSecondCommand = new FindContactCommand(secondPredicate); @@ -55,29 +82,19 @@ public void equals() { } @Test - public void execute_zeroKeywords_noPersonFound() { - String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0); - NameContainsKeywordsPredicate predicate = preparePredicate(" "); - FindContactCommand command = new FindContactCommand(predicate); - expectedModel.updateFilteredPersonList(predicate); - assertCommandSuccess(command, model, expectedMessage, expectedModel); - assertEquals(Collections.emptyList(), model.getFilteredPersonList()); + public void execute_zeroMatchingKeywords_noPersonFound() { + // TODO } @Test public void execute_multipleKeywords_multiplePersonsFound() { - String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 3); - NameContainsKeywordsPredicate predicate = preparePredicate("Kurz Elle Kunz"); + String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 2); + PersonContainsKeywordsPredicate predicate = + new PersonContainsKeywordsPredicate(nameKeywords, emptyPhoneKeywords, + emptyEmailKeywords, emptyAddressKeywords); FindContactCommand command = new FindContactCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); - assertEquals(Arrays.asList(CARL, ELLE, FIONA), model.getFilteredPersonList()); - } - - /** - * Parses {@code userInput} into a {@code NameContainsKeywordsPredicate}. - */ - private NameContainsKeywordsPredicate preparePredicate(String userInput) { - return new NameContainsKeywordsPredicate(Arrays.asList(userInput.split("\\s+"))); + assertEquals(Arrays.asList(ALICE, BENSON), model.getFilteredPersonList()); } } diff --git a/src/test/java/seedu/address/logic/commands/ListContactCommandTest.java b/src/test/java/seedu/address/logic/commands/ListContactCommandTest.java index 81f4f5db7fb..91c22cce98f 100644 --- a/src/test/java/seedu/address/logic/commands/ListContactCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/ListContactCommandTest.java @@ -8,6 +8,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import seedu.address.logic.commands.contact.ListContactCommand; import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; diff --git a/src/test/java/seedu/address/logic/parser/AddContactCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddContactCommandParserTest.java index c06bda3c6c0..6fb7c909ae4 100644 --- a/src/test/java/seedu/address/logic/parser/AddContactCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddContactCommandParserTest.java @@ -31,7 +31,8 @@ import org.junit.jupiter.api.Test; -import seedu.address.logic.commands.AddContactCommand; +import seedu.address.logic.commands.contact.AddContactCommand; +import seedu.address.logic.parser.contact.AddContactCommandParser; import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index 6da70cc2568..39cd6340349 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -7,23 +7,17 @@ import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - import org.junit.jupiter.api.Test; -import seedu.address.logic.commands.AddContactCommand; import seedu.address.logic.commands.ClearCommand; -import seedu.address.logic.commands.DeleteContactCommand; -import seedu.address.logic.commands.EditContactCommand; -import seedu.address.logic.commands.EditContactCommand.EditPersonDescriptor; import seedu.address.logic.commands.ExitCommand; -import seedu.address.logic.commands.FindContactCommand; import seedu.address.logic.commands.HelpCommand; -import seedu.address.logic.commands.ListContactCommand; +import seedu.address.logic.commands.contact.AddContactCommand; +import seedu.address.logic.commands.contact.DeleteContactCommand; +import seedu.address.logic.commands.contact.EditContactCommand; +import seedu.address.logic.commands.contact.EditContactCommand.EditPersonDescriptor; +import seedu.address.logic.commands.contact.ListContactCommand; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.NameContainsKeywordsPredicate; import seedu.address.model.person.Person; import seedu.address.testutil.EditPersonDescriptorBuilder; import seedu.address.testutil.PersonBuilder; @@ -70,10 +64,7 @@ public void parseCommand_exit() throws Exception { @Test public void parseCommand_find() throws Exception { - List keywords = Arrays.asList("foo", "bar", "baz"); - FindContactCommand command = (FindContactCommand) parser.parseCommand( - FindContactCommand.COMMAND_WORD + " " + keywords.stream().collect(Collectors.joining(" "))); - assertEquals(new FindContactCommand(new NameContainsKeywordsPredicate(keywords)), command); + // TODO } @Test diff --git a/src/test/java/seedu/address/logic/parser/DeleteCommandParserTest.java b/src/test/java/seedu/address/logic/parser/DeleteCommandParserTest.java index 7de2535395b..c0d7d1df32a 100644 --- a/src/test/java/seedu/address/logic/parser/DeleteCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/DeleteCommandParserTest.java @@ -7,7 +7,8 @@ import org.junit.jupiter.api.Test; -import seedu.address.logic.commands.DeleteContactCommand; +import seedu.address.logic.commands.contact.DeleteContactCommand; +import seedu.address.logic.parser.contact.DeleteContactCommandParser; /** * As we are only doing white-box testing, our test cases do not cover path variations diff --git a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java index 781da9a8f1b..512db21a335 100644 --- a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java @@ -34,8 +34,9 @@ import org.junit.jupiter.api.Test; import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.EditContactCommand; -import seedu.address.logic.commands.EditContactCommand.EditPersonDescriptor; +import seedu.address.logic.commands.contact.EditContactCommand; +import seedu.address.logic.commands.contact.EditContactCommand.EditPersonDescriptor; +import seedu.address.logic.parser.contact.EditContactCommandParser; import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; diff --git a/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java index 28d30b53ba2..a83af3e2eab 100644 --- a/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/FindCommandParserTest.java @@ -2,14 +2,19 @@ import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; -import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; import java.util.Arrays; +import java.util.List; import org.junit.jupiter.api.Test; -import seedu.address.logic.commands.FindContactCommand; -import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.logic.commands.contact.FindContactCommand; +import seedu.address.logic.parser.contact.FindContactCommandParser; +import seedu.address.model.person.Address; +import seedu.address.model.person.Email; +import seedu.address.model.person.Name; +import seedu.address.model.person.PersonContainsKeywordsPredicate; +import seedu.address.model.person.Phone; public class FindCommandParserTest { @@ -23,13 +28,30 @@ public void parse_emptyArg_throwsParseException() { @Test public void parse_validArgs_returnsFindCommand() { - // no leading and trailing whitespaces - FindContactCommand expectedFindCommand = - new FindContactCommand(new NameContainsKeywordsPredicate(Arrays.asList("Alice", "Bob"))); - assertParseSuccess(parser, "Alice Bob", expectedFindCommand); + String nameKeyword1 = "ali"; + String nameKeyword2 = "baba"; + String phoneKeyword1 = "999"; + String phoneKeyword2 = "62353535"; + String emailKeyword1 = "john@gmail.com"; + String emailKeyword2 = "colonel-sanders-123@kfc.co.uk"; + String addressKeyword1 = "17A Lower Kent Ridge Road, #01-01, S(119081)"; + String addressKeyword2 = "17A Lower Kent Ridge Road, c/o reception@sally, #01-01, S(119081)"; + + List nameKeywords = Arrays.asList(new Name(nameKeyword1), new Name(nameKeyword2)); + List phoneKeywords = Arrays.asList(new Phone(phoneKeyword1), new Phone(phoneKeyword2)); + List emailKeywords = Arrays.asList(new Email(emailKeyword1), new Email(emailKeyword2)); + List
addressKeywords = Arrays.asList(new Address(addressKeyword1), new Address(addressKeyword2)); + + FindContactCommand expectedFindCommand = new FindContactCommand(new PersonContainsKeywordsPredicate( + nameKeywords, phoneKeywords, emailKeywords, addressKeywords)); // multiple whitespaces between keywords - assertParseSuccess(parser, " \n Alice \n \t Bob \t", expectedFindCommand); - } + // TODO: Add test case + + // no prefix + // TODO: throw error + // repeated prefixes + // TODO: throw error + } } diff --git a/src/test/java/seedu/address/model/person/PersonContainsKeywordsPredicateTest.java b/src/test/java/seedu/address/model/person/PersonContainsKeywordsPredicateTest.java new file mode 100644 index 00000000000..764fb9a2459 --- /dev/null +++ b/src/test/java/seedu/address/model/person/PersonContainsKeywordsPredicateTest.java @@ -0,0 +1,60 @@ +package seedu.address.model.person; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.jupiter.api.Test; + +public class PersonContainsKeywordsPredicateTest { + + private final String nameKeyword1 = "Alice"; + private final String nameKeyword2 = "Benson"; + private final String phoneKeyword1 = "999"; + private final String phoneKeyword2 = "62353535"; + private final String emailKeyword1 = "john@gmail.com"; + private final String emailKeyword2 = "colonel-sanders-123@kfc.co.uk"; + private final String addressKeyword1 = "17A Lower Kent Ridge Road, #01-01, S(119081)"; + private final String addressKeyword2 = "17A Lower Kent Ridge Road, c/o reception@sally, #01-01, S(119081)"; + + private final List nameKeywords = Arrays.asList(new Name(nameKeyword1), new Name(nameKeyword2)); + private final List phoneKeywords = Arrays.asList(new Phone(phoneKeyword1), new Phone(phoneKeyword2)); + private final List emailKeywords = Arrays.asList(new Email(emailKeyword1), new Email(emailKeyword2)); + private final List
addressKeywords = Arrays.asList(new Address(addressKeyword1), + new Address(addressKeyword2)); + + private final List emptyNameKeywords = new ArrayList<>(); + private final List emptyPhoneKeywords = new ArrayList<>(); + private final List emptyEmailKeywords = new ArrayList<>(); + private final List
emptyAddressKeywords = new ArrayList<>(); + + @Test + public void equals() { + + PersonContainsKeywordsPredicate firstPredicate = + new PersonContainsKeywordsPredicate(nameKeywords, phoneKeywords, + emailKeywords, addressKeywords); + PersonContainsKeywordsPredicate secondPredicate = + new PersonContainsKeywordsPredicate(nameKeywords, emptyPhoneKeywords, + emptyEmailKeywords, emptyAddressKeywords); + // same object -> returns true + assertTrue(firstPredicate.equals(firstPredicate)); + + // same values -> returns true + PersonContainsKeywordsPredicate firstPredicateCopy = new PersonContainsKeywordsPredicate( + nameKeywords, phoneKeywords, emailKeywords, addressKeywords); + assertTrue(firstPredicate.equals(firstPredicateCopy)); + + // different types -> returns false + assertFalse(firstPredicate.equals(1)); + + // null -> returns false + assertFalse(firstPredicate.equals(null)); + + // different person -> returns false + assertFalse(firstPredicate.equals(secondPredicate)); + } +} diff --git a/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java b/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java index a9b1eda8e66..f6bcce9e42f 100644 --- a/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java +++ b/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java @@ -4,7 +4,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import seedu.address.logic.commands.EditContactCommand.EditPersonDescriptor; +import seedu.address.logic.commands.contact.EditContactCommand.EditPersonDescriptor; import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; diff --git a/src/test/java/seedu/address/testutil/PersonUtil.java b/src/test/java/seedu/address/testutil/PersonUtil.java index b6098f78505..6dfca9a9b17 100644 --- a/src/test/java/seedu/address/testutil/PersonUtil.java +++ b/src/test/java/seedu/address/testutil/PersonUtil.java @@ -8,8 +8,8 @@ import java.util.Set; -import seedu.address.logic.commands.AddContactCommand; -import seedu.address.logic.commands.EditContactCommand.EditPersonDescriptor; +import seedu.address.logic.commands.contact.AddContactCommand; +import seedu.address.logic.commands.contact.EditContactCommand.EditPersonDescriptor; import seedu.address.model.person.Person; import seedu.address.model.tag.Tag;