From b75fa8f8c1367ad8dccd3a0be4388f0c28e917a9 Mon Sep 17 00:00:00 2001 From: waseem Date: Wed, 1 Nov 2023 01:04:23 +0800 Subject: [PATCH] Add find by multiple attributes Users can now find developers, clients and projects by more than 1 attribute --- .../address/commons/util/StringUtil.java | 25 +++ .../commands/find/FindClientCommand.java | 82 +++------- .../commands/find/FindDeveloperCommand.java | 95 ++++------- .../commands/find/FindProjectCommand.java | 34 ++-- .../seedu/address/logic/parser/CliSyntax.java | 2 - .../parser/find/FindClientCommandParser.java | 103 ++++++++---- .../find/FindDeveloperCommandParser.java | 148 +++++++++++------- .../parser/find/FindProjectCommandParser.java | 50 ++++-- ...ddressClientContainsKeywordsPredicate.java | 43 +++++ .../EmailClientContainsKeywordsPredicate.java | 44 ++++++ .../NameClientContainsKeywordsPredicate.java | 44 ++++++ .../PhoneClientContainsKeywordsPredicate.java | 44 ++++++ ...rojectClientContainsKeywordsPredicate.java | 44 ++++++ .../RoleClientContainsKeywordsPredicate.java | 44 ++++++ ...ssDeveloperContainsKeywordsPredicate.java} | 18 +-- .../developer/CombinedDeveloperPredicate.java | 52 ++++++ ...ilDeveloperContainsKeywordsPredicate.java} | 18 +-- ...meDeveloperContainsKeywordsPredicate.java} | 18 +-- ...neDeveloperContainsKeywordsPredicate.java} | 20 +-- ...ectDeveloperContainsKeywordsPredicate.java | 44 ++++++ ...leDeveloperContainsKeywordsPredicate.java} | 16 +- .../model/person/KeywordPredicateFactory.java | 8 + .../ProjectContainsKeywordsPredicate.java | 45 ------ .../logic/commands/CommandTestUtil.java | 4 +- .../logic/commands/FindCommandTest.java | 20 +-- .../logic/parser/AddressBookParserTest.java | 4 +- .../FindDeveloperCommandParserTest.java | 4 +- .../seedu/address/model/ModelManagerTest.java | 4 +- .../NameContainsKeywordsPredicateTest.java | 25 +-- 29 files changed, 737 insertions(+), 365 deletions(-) create mode 100644 src/main/java/seedu/address/model/client/AddressClientContainsKeywordsPredicate.java create mode 100644 src/main/java/seedu/address/model/client/EmailClientContainsKeywordsPredicate.java create mode 100644 src/main/java/seedu/address/model/client/NameClientContainsKeywordsPredicate.java create mode 100644 src/main/java/seedu/address/model/client/PhoneClientContainsKeywordsPredicate.java create mode 100644 src/main/java/seedu/address/model/client/ProjectClientContainsKeywordsPredicate.java create mode 100644 src/main/java/seedu/address/model/client/RoleClientContainsKeywordsPredicate.java rename src/main/java/seedu/address/model/{person/AddressContainsKeywordsPredicate.java => developer/AddressDeveloperContainsKeywordsPredicate.java} (55%) create mode 100644 src/main/java/seedu/address/model/developer/CombinedDeveloperPredicate.java rename src/main/java/seedu/address/model/{person/EmailContainsKeywordsPredicate.java => developer/EmailDeveloperContainsKeywordsPredicate.java} (55%) rename src/main/java/seedu/address/model/{person/NameContainsKeywordsPredicate.java => developer/NameDeveloperContainsKeywordsPredicate.java} (59%) rename src/main/java/seedu/address/model/{person/PhoneContainsKeywordsPredicate.java => developer/PhoneDeveloperContainsKeywordsPredicate.java} (55%) create mode 100644 src/main/java/seedu/address/model/developer/ProjectDeveloperContainsKeywordsPredicate.java rename src/main/java/seedu/address/model/{person/RoleContainsKeywordsPredicate.java => developer/RoleDeveloperContainsKeywordsPredicate.java} (59%) create mode 100644 src/main/java/seedu/address/model/person/KeywordPredicateFactory.java delete mode 100644 src/main/java/seedu/address/model/person/ProjectContainsKeywordsPredicate.java diff --git a/src/main/java/seedu/address/commons/util/StringUtil.java b/src/main/java/seedu/address/commons/util/StringUtil.java index 61cc8c9a1cb..70173b20c7b 100644 --- a/src/main/java/seedu/address/commons/util/StringUtil.java +++ b/src/main/java/seedu/address/commons/util/StringUtil.java @@ -38,6 +38,31 @@ public static boolean containsWordIgnoreCase(String sentence, String word) { .anyMatch(preppedWord::equalsIgnoreCase); } + /** + * Returns true if the {@code sentence} contains the {@code word} as a partial word match. + * Ignores case, and it matches the word even if it's only a part of a larger word. + *
examples:
+     * containsPartialWordIgnoreCase("ABc def", "abc") == true
+     * containsPartialWordIgnoreCase("ABc def", "DEF") == true
+     * containsPartialWordIgnoreCase("ABc def", "AB") == true
+     * 
+ * @param sentence cannot be null + * @param word cannot be null, cannot be empty + */ + public static boolean containsPartialWordIgnoreCase(String sentence, String word) { + requireNonNull(sentence); + requireNonNull(word); + + String preppedWord = word.trim(); + checkArgument(!preppedWord.isEmpty(), "Word parameter cannot be empty"); + + String preppedSentence = sentence; + String[] wordsInPreppedSentence = preppedSentence.split("\\s+"); + + return Arrays.stream(wordsInPreppedSentence) + .anyMatch(wordInSentence -> wordInSentence.toLowerCase().contains(preppedWord.toLowerCase())); + } + /** * Returns a detailed message of the t, including the stack trace. */ diff --git a/src/main/java/seedu/address/logic/commands/find/FindClientCommand.java b/src/main/java/seedu/address/logic/commands/find/FindClientCommand.java index 87b51b58375..bdd239b821f 100644 --- a/src/main/java/seedu/address/logic/commands/find/FindClientCommand.java +++ b/src/main/java/seedu/address/logic/commands/find/FindClientCommand.java @@ -2,6 +2,14 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.Messages.getMessageClientsListedOverview; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DOCUMENT; +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_ORGANISATION; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ROLE; import java.util.function.Predicate; @@ -11,68 +19,32 @@ import seedu.address.logic.commands.TabIndex; import seedu.address.model.Model; import seedu.address.model.client.Client; -import seedu.address.model.client.DocumentContainsKeywordsPredicate; -import seedu.address.model.client.OrganisationContainsKeywordsPredicate; -import seedu.address.model.person.AddressContainsKeywordsPredicate; -import seedu.address.model.person.EmailContainsKeywordsPredicate; -import seedu.address.model.person.KeywordPredicate; -import seedu.address.model.person.NameContainsKeywordsPredicate; -import seedu.address.model.person.Person; -import seedu.address.model.person.PhoneContainsKeywordsPredicate; -import seedu.address.model.person.ProjectContainsKeywordsPredicate; -import seedu.address.model.person.RoleContainsKeywordsPredicate; -/** - * Finds and lists all persons in address book whose name contains any of the argument keywords. - * Keyword matching is case insensitive. - */ public class FindClientCommand extends Command { public static final String COMMAND_WORD = "find-client"; - - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Please Find with the correct input " - + "Find pr/ OR Find r/ OR Find n/.\n" - + "Example: " + COMMAND_WORD + " n/ alice bob charlie"; - - private KeywordPredicate predicate; - - public FindClientCommand(NameContainsKeywordsPredicate namePredicate) { - this.predicate = namePredicate; - } - - public FindClientCommand(RoleContainsKeywordsPredicate rolePredicate) { - this.predicate = rolePredicate; - } - - public FindClientCommand(AddressContainsKeywordsPredicate addressPredicate) { - this.predicate = addressPredicate; - } - - public FindClientCommand(EmailContainsKeywordsPredicate emailPredicate) { - this.predicate = emailPredicate; - } - - public FindClientCommand(PhoneContainsKeywordsPredicate phonePredicate) { - this.predicate = phonePredicate; - } - - - public FindClientCommand(ProjectContainsKeywordsPredicate projectPredicate) { - this.predicate = projectPredicate; - } - - public FindClientCommand(DocumentContainsKeywordsPredicate documentPredicate) { - this.predicate = documentPredicate; - } - - public FindClientCommand(OrganisationContainsKeywordsPredicate organisationPredicate) { - this.predicate = organisationPredicate; + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Find clients based on various attributes.\n" + + "Parameters: " + + "[" + PREFIX_NAME + "NAME_KEYWORDS] " + + "[" + PREFIX_ROLE + "ROLE_KEYWORDS] " + + "[" + PREFIX_ADDRESS + "ADDRESS_KEYWORDS] " + + "[" + PREFIX_EMAIL + "EMAIL_KEYWORDS] " + + "[" + PREFIX_PHONE + "PHONE_KEYWORDS] " + + "[" + PREFIX_PROJECT + "PROJECT_KEYWORDS] " + + "[" + PREFIX_DOCUMENT + "DOCUMENT_KEYWORDS] " + + "[" + PREFIX_ORGANISATION + "ORGANISATION_KEYWORDS]\n" + + "Example: " + COMMAND_WORD + " n/John r/client\n"; + + private Predicate predicate; + + public FindClientCommand(Predicate predicate) { + this.predicate = predicate; } @Override public CommandResult execute(Model model) { requireNonNull(model); - model.updateFilteredClientList((Predicate) predicate); + model.updateFilteredClientList(predicate); int resultCount = model.getFilteredClientList().size(); String message = getMessageClientsListedOverview(resultCount); @@ -80,14 +52,12 @@ public CommandResult execute(Model model) { return new CommandResult(message, TabIndex.Client); } - @Override public boolean equals(Object other) { if (other == this) { return true; } - // instanceof handles nulls if (!(other instanceof FindClientCommand)) { return false; } @@ -102,4 +72,4 @@ public String toString() { .add("predicate", predicate) .toString(); } -} +} \ No newline at end of file diff --git a/src/main/java/seedu/address/logic/commands/find/FindDeveloperCommand.java b/src/main/java/seedu/address/logic/commands/find/FindDeveloperCommand.java index 10b9fefe401..40495b252e5 100644 --- a/src/main/java/seedu/address/logic/commands/find/FindDeveloperCommand.java +++ b/src/main/java/seedu/address/logic/commands/find/FindDeveloperCommand.java @@ -2,6 +2,16 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.Messages.getMessageDevelopersListedOverview; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DATEJOINED; +import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; +import static seedu.address.logic.parser.CliSyntax.PREFIX_GITHUBID; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_RATING; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ROLE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_SALARY; import java.util.function.Predicate; @@ -10,78 +20,35 @@ import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.TabIndex; import seedu.address.model.Model; -import seedu.address.model.developer.DateJoinedContainsKeywordsPredicate; import seedu.address.model.developer.Developer; -import seedu.address.model.developer.GithubIdContainsKeywordsPredicate; -import seedu.address.model.developer.RatingContainsKeywordsPredicate; -import seedu.address.model.developer.SalaryContainsKeywordsPredicate; -import seedu.address.model.person.AddressContainsKeywordsPredicate; -import seedu.address.model.person.EmailContainsKeywordsPredicate; -import seedu.address.model.person.KeywordPredicate; -import seedu.address.model.person.NameContainsKeywordsPredicate; -import seedu.address.model.person.Person; -import seedu.address.model.person.PhoneContainsKeywordsPredicate; -import seedu.address.model.person.ProjectContainsKeywordsPredicate; -import seedu.address.model.person.RoleContainsKeywordsPredicate; -/** - * Finds and lists all persons in address book whose name contains any of the argument keywords. - * Keyword matching is case insensitive. - */ public class FindDeveloperCommand extends Command { public static final String COMMAND_WORD = "find-developer"; - - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Please Find with the correct input " - + "Find pr/ OR Find r/ OR Find n/.\n" - + "Example: " + COMMAND_WORD + " n/ alice bob charlie"; - - private KeywordPredicate predicate; - - public FindDeveloperCommand(NameContainsKeywordsPredicate namePredicate) { - this.predicate = namePredicate; - } - - public FindDeveloperCommand(RoleContainsKeywordsPredicate rolePredicate) { - this.predicate = rolePredicate; - } - - public FindDeveloperCommand(AddressContainsKeywordsPredicate addressPredicate) { - this.predicate = addressPredicate; - } - - public FindDeveloperCommand(DateJoinedContainsKeywordsPredicate dateJoinedPredicate) { - this.predicate = dateJoinedPredicate; - } - - public FindDeveloperCommand(EmailContainsKeywordsPredicate emailPredicate) { - this.predicate = emailPredicate; - } - - public FindDeveloperCommand(PhoneContainsKeywordsPredicate phonePredicate) { - this.predicate = phonePredicate; - } - - public FindDeveloperCommand(SalaryContainsKeywordsPredicate salaryPredicate) { - this.predicate = salaryPredicate; - } - - - public FindDeveloperCommand(ProjectContainsKeywordsPredicate projectPredicate) { - this.predicate = projectPredicate; - } - - public FindDeveloperCommand(RatingContainsKeywordsPredicate projectPredicate) { - this.predicate = projectPredicate; - } - public FindDeveloperCommand(GithubIdContainsKeywordsPredicate projectPredicate) { - this.predicate = projectPredicate; + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Find developers based on various attributes.\n" + + "Parameters: " + + "[" + PREFIX_NAME + "NAME_KEYWORDS] " + + "[" + PREFIX_ROLE + "ROLE_KEYWORDS] " + + "[" + PREFIX_ADDRESS + "ADDRESS_KEYWORDS] " + + "[" + PREFIX_DATEJOINED + "DATE_JOINED_KEYWORDS] " + + "[" + PREFIX_EMAIL + "EMAIL_KEYWORDS] " + + "[" + PREFIX_PHONE + "PHONE_KEYWORDS] " + + "[" + PREFIX_PROJECT + "PROJECT_KEYWORDS] " + + "[" + PREFIX_SALARY + "SALARY_KEYWORDS] " + + "[" + PREFIX_RATING + "RATING_KEYWORDS] " + + "[" + PREFIX_GITHUBID + "GITHUBID_KEYWORDS]\n" + + "Example: " + COMMAND_WORD + " n/John r/developer\n"; + + private Predicate predicate; + + public FindDeveloperCommand(Predicate predicate) { + this.predicate = predicate; } @Override public CommandResult execute(Model model) { requireNonNull(model); - model.updateFilteredDeveloperList((Predicate) predicate); + model.updateFilteredDeveloperList(predicate); int resultCount = model.getFilteredDeveloperList().size(); String message = getMessageDevelopersListedOverview(resultCount); @@ -89,14 +56,12 @@ public CommandResult execute(Model model) { return new CommandResult(message, TabIndex.Developer); } - @Override public boolean equals(Object other) { if (other == this) { return true; } - // instanceof handles nulls if (!(other instanceof FindDeveloperCommand)) { return false; } @@ -111,4 +76,4 @@ public String toString() { .add("predicate", predicate) .toString(); } -} +} \ No newline at end of file diff --git a/src/main/java/seedu/address/logic/commands/find/FindProjectCommand.java b/src/main/java/seedu/address/logic/commands/find/FindProjectCommand.java index d31958dd136..3059a62dc61 100644 --- a/src/main/java/seedu/address/logic/commands/find/FindProjectCommand.java +++ b/src/main/java/seedu/address/logic/commands/find/FindProjectCommand.java @@ -2,17 +2,18 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.Messages.getMessageProjectsListedOverview; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DEADLINE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT; + +import java.util.function.Predicate; import seedu.address.commons.util.ToStringBuilder; import seedu.address.logic.commands.Command; import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.TabIndex; import seedu.address.model.Model; -import seedu.address.model.person.KeywordPredicate; -import seedu.address.model.project.DeadlineContainsKeywordsPredicate; -import seedu.address.model.project.DescriptionContainsKeywordsPredicate; import seedu.address.model.project.Project; -import seedu.address.model.project.ProjectNameContainsKeywordsPredicate; /** * Finds and lists all persons in address book whose name contains any of the argument keywords. @@ -22,22 +23,17 @@ public class FindProjectCommand extends Command { public static final String COMMAND_WORD = "find-project"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Please Find with the correct input " - + "Find pr/ OR Find r/ OR Find n/.\n" - + "Example: " + COMMAND_WORD + " n/ alice bob charlie"; - - private KeywordPredicate predicate; - - public FindProjectCommand(ProjectNameContainsKeywordsPredicate namePredicate) { - this.predicate = namePredicate; - } + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Find projects based on various attributes.\n" + + "Parameters: " + + "[" + PREFIX_PROJECT + "PROJECT_NAME_KEYWORDS] " + + "[" + PREFIX_DESCRIPTION + "DESCRIPTION_KEYWORDS] " + + "[" + PREFIX_DEADLINE + "DEADLINE_KEYWORDS]\n" + + "Example: " + COMMAND_WORD + " pr/MyProject\n"; - public FindProjectCommand(DescriptionContainsKeywordsPredicate rolePredicate) { - this.predicate = rolePredicate; - } + private Predicate predicate; - public FindProjectCommand(DeadlineContainsKeywordsPredicate addressPredicate) { - this.predicate = addressPredicate; + public FindProjectCommand(Predicate predicate) { + this.predicate = predicate; } @Override @@ -51,14 +47,12 @@ public CommandResult execute(Model model) { return new CommandResult(message, TabIndex.Project); } - @Override public boolean equals(Object other) { if (other == this) { return true; } - // instanceof handles nulls if (!(other instanceof FindProjectCommand)) { return false; } diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 9ffe46aa2d2..f73044ed647 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -20,6 +20,4 @@ public class CliSyntax { public static final Prefix PREFIX_DOCUMENT = new Prefix("do/"); public static final Prefix PREFIX_DESCRIPTION = new Prefix("dr/"); public static final Prefix PREFIX_DEADLINE = new Prefix("dl/"); - - } diff --git a/src/main/java/seedu/address/logic/parser/find/FindClientCommandParser.java b/src/main/java/seedu/address/logic/parser/find/FindClientCommandParser.java index 8f00c522134..eadc2ee5ea9 100644 --- a/src/main/java/seedu/address/logic/parser/find/FindClientCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/find/FindClientCommandParser.java @@ -1,20 +1,32 @@ package seedu.address.logic.parser.find; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DOCUMENT; +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_ORGANISATION; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ROLE; import java.util.Arrays; +import java.util.function.Predicate; import seedu.address.logic.commands.find.FindClientCommand; +import seedu.address.logic.parser.ArgumentMultimap; +import seedu.address.logic.parser.ArgumentTokenizer; import seedu.address.logic.parser.Parser; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.client.AddressClientContainsKeywordsPredicate; +import seedu.address.model.client.Client; import seedu.address.model.client.DocumentContainsKeywordsPredicate; +import seedu.address.model.client.EmailClientContainsKeywordsPredicate; +import seedu.address.model.client.NameClientContainsKeywordsPredicate; import seedu.address.model.client.OrganisationContainsKeywordsPredicate; -import seedu.address.model.person.AddressContainsKeywordsPredicate; -import seedu.address.model.person.EmailContainsKeywordsPredicate; -import seedu.address.model.person.NameContainsKeywordsPredicate; -import seedu.address.model.person.PhoneContainsKeywordsPredicate; -import seedu.address.model.person.ProjectContainsKeywordsPredicate; -import seedu.address.model.person.RoleContainsKeywordsPredicate; +import seedu.address.model.client.PhoneClientContainsKeywordsPredicate; +import seedu.address.model.client.ProjectClientContainsKeywordsPredicate; +import seedu.address.model.client.RoleClientContainsKeywordsPredicate; /** * Parses input arguments and creates a new FindClientCommand object @@ -32,33 +44,62 @@ public FindClientCommand parse(String args) throws ParseException { String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindClientCommand.MESSAGE_USAGE)); } - if (trimmedArgs.startsWith("n/")) { - String[] nameKeywords = trimmedArgs.replaceFirst("n/", "").split("\\s+"); - return new FindClientCommand(new NameContainsKeywordsPredicate(Arrays.asList(nameKeywords))); - } else if (trimmedArgs.startsWith("r/")) { - String[] roleKeywords = trimmedArgs.replaceFirst("r/", "").split("\\s+"); - return new FindClientCommand(new RoleContainsKeywordsPredicate(Arrays.asList(roleKeywords))); - } else if (trimmedArgs.startsWith("a/")) { - String[] addressKeywords = trimmedArgs.replaceFirst("a/", "").split("\\s+"); - return new FindClientCommand(new AddressContainsKeywordsPredicate(Arrays.asList(addressKeywords))); - } else if (trimmedArgs.startsWith("e/")) { - String[] emailKeywords = trimmedArgs.replaceFirst("e/", "").split("\\s+"); - return new FindClientCommand(new EmailContainsKeywordsPredicate(Arrays.asList(emailKeywords))); - } else if (trimmedArgs.startsWith("ph/")) { - String[] phoneKeywords = trimmedArgs.replaceFirst("ph/", "").split("\\s+"); - return new FindClientCommand(new PhoneContainsKeywordsPredicate(Arrays.asList(phoneKeywords))); - } else if (trimmedArgs.startsWith("pr/")) { - String[] projectKeywords = trimmedArgs.replaceFirst("pr/", "").split("\\s+"); - return new FindClientCommand(new ProjectContainsKeywordsPredicate(Arrays.asList(projectKeywords))); - } else if (trimmedArgs.startsWith("d/")) { - String[] nameKeywords = trimmedArgs.replaceFirst("d/", "").split("\\s+"); - return new FindClientCommand(new DocumentContainsKeywordsPredicate(Arrays.asList(nameKeywords))); - } else if (trimmedArgs.startsWith("o/")) { - String[] phoneKeywords = trimmedArgs.replaceFirst("o/", "").split("\\s+"); - return new FindClientCommand(new OrganisationContainsKeywordsPredicate(Arrays.asList(phoneKeywords))); - } else { + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_ROLE, PREFIX_ADDRESS, + PREFIX_EMAIL, PREFIX_PHONE, PREFIX_PROJECT, PREFIX_DOCUMENT, PREFIX_ORGANISATION); + + if (!argMultimap.getPreamble().isEmpty()) { throw new ParseException( String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindClientCommand.MESSAGE_USAGE)); } + + Predicate finalPredicate = buildPredicate(argMultimap); + + return new FindClientCommand(finalPredicate); + } + + private Predicate buildPredicate(ArgumentMultimap argMultimap) { + Predicate finalPredicate = client -> true; + + if (argMultimap.getValue(PREFIX_NAME).isPresent()) { + String[] nameKeywords = argMultimap.getValue(PREFIX_NAME).get().split("\\s+"); + finalPredicate = finalPredicate.and(new NameClientContainsKeywordsPredicate(Arrays.asList(nameKeywords))); + } + + if (argMultimap.getValue(PREFIX_ROLE).isPresent()) { + String[] roleKeywords = argMultimap.getValue(PREFIX_ROLE).get().split("\\s+"); + finalPredicate = finalPredicate.and(new RoleClientContainsKeywordsPredicate(Arrays.asList(roleKeywords))); + } + + if (argMultimap.getValue(PREFIX_ADDRESS).isPresent()) { + String[] addressKeywords = argMultimap.getValue(PREFIX_ADDRESS).get().split("\\s+"); + finalPredicate = finalPredicate.and(new AddressClientContainsKeywordsPredicate(Arrays.asList(addressKeywords))); + } + + if (argMultimap.getValue(PREFIX_EMAIL).isPresent()) { + String[] emailKeywords = argMultimap.getValue(PREFIX_EMAIL).get().split("\\s+"); + finalPredicate = finalPredicate.and(new EmailClientContainsKeywordsPredicate(Arrays.asList(emailKeywords))); + } + + if (argMultimap.getValue(PREFIX_PHONE).isPresent()) { + String[] phoneKeywords = argMultimap.getValue(PREFIX_PHONE).get().split("\\s+"); + finalPredicate = finalPredicate.and(new PhoneClientContainsKeywordsPredicate(Arrays.asList(phoneKeywords))); + } + + if (argMultimap.getValue(PREFIX_PROJECT).isPresent()) { + String[] projectKeywords = argMultimap.getValue(PREFIX_PROJECT).get().split("\\s+"); + finalPredicate = finalPredicate.and(new ProjectClientContainsKeywordsPredicate(Arrays.asList(projectKeywords))); + } + + if (argMultimap.getValue(PREFIX_DOCUMENT).isPresent()) { + String[] documentKeywords = argMultimap.getValue(PREFIX_DOCUMENT).get().split("\\s+"); + finalPredicate = finalPredicate.and(new DocumentContainsKeywordsPredicate(Arrays.asList(documentKeywords))); + } + + if (argMultimap.getValue(PREFIX_ORGANISATION).isPresent()) { + String[] organisationKeywords = argMultimap.getValue(PREFIX_ORGANISATION).get().split("\\s+"); + finalPredicate = finalPredicate.and(new OrganisationContainsKeywordsPredicate(Arrays.asList(organisationKeywords))); + } + + return finalPredicate; } } \ No newline at end of file diff --git a/src/main/java/seedu/address/logic/parser/find/FindDeveloperCommandParser.java b/src/main/java/seedu/address/logic/parser/find/FindDeveloperCommandParser.java index 97061fe9bf1..617c8735772 100644 --- a/src/main/java/seedu/address/logic/parser/find/FindDeveloperCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/find/FindDeveloperCommandParser.java @@ -1,73 +1,109 @@ package seedu.address.logic.parser.find; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DATEJOINED; +import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; +import static seedu.address.logic.parser.CliSyntax.PREFIX_GITHUBID; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_RATING; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ROLE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_SALARY; import java.util.Arrays; +import java.util.function.Predicate; import seedu.address.logic.commands.find.FindDeveloperCommand; +import seedu.address.logic.parser.ArgumentMultimap; +import seedu.address.logic.parser.ArgumentTokenizer; import seedu.address.logic.parser.Parser; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.developer.DateJoinedContainsKeywordsPredicate; +import seedu.address.model.developer.Developer; import seedu.address.model.developer.GithubIdContainsKeywordsPredicate; import seedu.address.model.developer.RatingContainsKeywordsPredicate; import seedu.address.model.developer.SalaryContainsKeywordsPredicate; -import seedu.address.model.person.AddressContainsKeywordsPredicate; -import seedu.address.model.person.EmailContainsKeywordsPredicate; -import seedu.address.model.person.NameContainsKeywordsPredicate; -import seedu.address.model.person.PhoneContainsKeywordsPredicate; -import seedu.address.model.person.ProjectContainsKeywordsPredicate; -import seedu.address.model.person.RoleContainsKeywordsPredicate; - -/** - * Parses input arguments and creates a new FindDeveloperCommand object - */ +import seedu.address.model.developer.AddressDeveloperContainsKeywordsPredicate; +import seedu.address.model.developer.EmailDeveloperContainsKeywordsPredicate; +import seedu.address.model.developer.NameDeveloperContainsKeywordsPredicate; +import seedu.address.model.developer.PhoneDeveloperContainsKeywordsPredicate; +import seedu.address.model.developer.ProjectDeveloperContainsKeywordsPredicate; +import seedu.address.model.developer.RoleDeveloperContainsKeywordsPredicate; + public class FindDeveloperCommandParser implements Parser { - /** - * Parses the given {@code String} of arguments in the context of the FindDeveloperCommand - * and returns a FindDeveloperCommand object for execution. - * @throws ParseException if the user input does not conform the expected format - */ - public FindDeveloperCommand parse(String args) throws ParseException { - String trimmedArgs = args.trim(); - if (trimmedArgs.isEmpty()) { - throw new ParseException( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindDeveloperCommand.MESSAGE_USAGE)); - } - - if (trimmedArgs.startsWith("n/")) { - String[] nameKeywords = trimmedArgs.replaceFirst("n/", "").split("\\s+"); - return new FindDeveloperCommand(new NameContainsKeywordsPredicate(Arrays.asList(nameKeywords))); - } else if (trimmedArgs.startsWith("ro/")) { - String[] roleKeywords = trimmedArgs.replaceFirst("r/", "").split("\\s+"); - return new FindDeveloperCommand(new RoleContainsKeywordsPredicate(Arrays.asList(roleKeywords))); - } else if (trimmedArgs.startsWith("a/")) { - String[] addressKeywords = trimmedArgs.replaceFirst("a/", "").split("\\s+"); - return new FindDeveloperCommand(new AddressContainsKeywordsPredicate(Arrays.asList(addressKeywords))); - } else if (trimmedArgs.startsWith("d/")) { - String[] dateJoinedKeywords = trimmedArgs.replaceFirst("d/", "").split("\\s+"); - return new FindDeveloperCommand(new DateJoinedContainsKeywordsPredicate(Arrays.asList(dateJoinedKeywords))); - } else if (trimmedArgs.startsWith("e/")) { - String[] emailKeywords = trimmedArgs.replaceFirst("e/", "").split("\\s+"); - return new FindDeveloperCommand(new EmailContainsKeywordsPredicate(Arrays.asList(emailKeywords))); - } else if (trimmedArgs.startsWith("ph/")) { - String[] phoneKeywords = trimmedArgs.replaceFirst("ph/", "").split("\\s+"); - return new FindDeveloperCommand(new PhoneContainsKeywordsPredicate(Arrays.asList(phoneKeywords))); - } else if (trimmedArgs.startsWith("pr/")) { - String[] projectKeywords = trimmedArgs.replaceFirst("pr/", "").split("\\s+"); - return new FindDeveloperCommand(new ProjectContainsKeywordsPredicate(Arrays.asList(projectKeywords))); - } else if (trimmedArgs.startsWith("s/")) { - String[] salaryKeywords = trimmedArgs.replaceFirst("s/", "").split("\\s+"); - return new FindDeveloperCommand(new SalaryContainsKeywordsPredicate(Arrays.asList(salaryKeywords))); - } else if (trimmedArgs.startsWith("ra/")) { - String[] ratingKeywords = trimmedArgs.replaceFirst("ra/", "").split("\\s+"); - return new FindDeveloperCommand(new RatingContainsKeywordsPredicate(Arrays.asList(ratingKeywords))); - } else if (trimmedArgs.startsWith("g/")) { - String[] githubKeywords = trimmedArgs.replaceFirst("g/", "").split("\\s+"); - return new FindDeveloperCommand(new GithubIdContainsKeywordsPredicate(Arrays.asList(githubKeywords))); - } else { - throw new ParseException( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindDeveloperCommand.MESSAGE_USAGE)); - } + public FindDeveloperCommand parse(String args) throws ParseException { + String trimmedArgs = args.trim(); + if (trimmedArgs.isEmpty()) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindDeveloperCommand.MESSAGE_USAGE)); + } + + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_ROLE, PREFIX_ADDRESS, + PREFIX_EMAIL, PREFIX_GITHUBID, PREFIX_DATEJOINED, PREFIX_PROJECT, PREFIX_PHONE, PREFIX_SALARY, PREFIX_RATING); + + if (!argMultimap.getPreamble().isEmpty()) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindDeveloperCommand.MESSAGE_USAGE)); + } + + Predicate finalPredicate = buildPredicate(argMultimap); + + return new FindDeveloperCommand(finalPredicate); + } + + private Predicate buildPredicate(ArgumentMultimap argMultimap) { + Predicate finalPredicate = developer -> true; + + if (argMultimap.getValue(PREFIX_NAME).isPresent()) { + String[] nameKeywords = argMultimap.getValue(PREFIX_NAME).get().split("\\s+"); + finalPredicate = finalPredicate.and(new NameDeveloperContainsKeywordsPredicate(Arrays.asList(nameKeywords))); + } + + if (argMultimap.getValue(PREFIX_ROLE).isPresent()) { + String[] roleKeywords = argMultimap.getValue(PREFIX_ROLE).get().split("\\s+"); + finalPredicate = finalPredicate.and(new RoleDeveloperContainsKeywordsPredicate(Arrays.asList(roleKeywords))); + } + + if (argMultimap.getValue(PREFIX_ADDRESS).isPresent()) { + String[] addressKeywords = argMultimap.getValue(PREFIX_ADDRESS).get().split("\\s+"); + finalPredicate = finalPredicate.and(new AddressDeveloperContainsKeywordsPredicate(Arrays.asList(addressKeywords))); + } + + if (argMultimap.getValue(PREFIX_DATEJOINED).isPresent()) { + String[] dateJoinedKeywords = argMultimap.getValue(PREFIX_DATEJOINED).get().split("\\s+"); + finalPredicate = finalPredicate.and(new DateJoinedContainsKeywordsPredicate(Arrays.asList(dateJoinedKeywords))); + } + + if (argMultimap.getValue(PREFIX_EMAIL).isPresent()) { + String[] emailKeywords = argMultimap.getValue(PREFIX_EMAIL).get().split("\\s+"); + finalPredicate = finalPredicate.and(new EmailDeveloperContainsKeywordsPredicate(Arrays.asList(emailKeywords))); + } + + if (argMultimap.getValue(PREFIX_PHONE).isPresent()) { + String[] phoneKeywords = argMultimap.getValue(PREFIX_PHONE).get().split("\\s+"); + finalPredicate = finalPredicate.and(new PhoneDeveloperContainsKeywordsPredicate(Arrays.asList(phoneKeywords))); + } + + if (argMultimap.getValue(PREFIX_PROJECT).isPresent()) { + String[] projectKeywords = argMultimap.getValue(PREFIX_PROJECT).get().split("\\s+"); + finalPredicate = finalPredicate.and(new ProjectDeveloperContainsKeywordsPredicate(Arrays.asList(projectKeywords))); + } + + if (argMultimap.getValue(PREFIX_SALARY).isPresent()) { + String[] salaryKeywords = argMultimap.getValue(PREFIX_SALARY).get().split("\\s+"); + finalPredicate = finalPredicate.and(new SalaryContainsKeywordsPredicate(Arrays.asList(salaryKeywords))); + } + + if (argMultimap.getValue(PREFIX_RATING).isPresent()) { + String[] ratingKeywords = argMultimap.getValue(PREFIX_RATING).get().split("\\s+"); + finalPredicate = finalPredicate.and(new RatingContainsKeywordsPredicate(Arrays.asList(ratingKeywords))); + } + + if (argMultimap.getValue(PREFIX_GITHUBID).isPresent()) { + String[] githubKeywords = argMultimap.getValue(PREFIX_GITHUBID).get().split("\\s+"); + finalPredicate = finalPredicate.and(new GithubIdContainsKeywordsPredicate(Arrays.asList(githubKeywords))); } + return finalPredicate; + } } \ No newline at end of file diff --git a/src/main/java/seedu/address/logic/parser/find/FindProjectCommandParser.java b/src/main/java/seedu/address/logic/parser/find/FindProjectCommandParser.java index a3a9eac9597..29caf9accc8 100644 --- a/src/main/java/seedu/address/logic/parser/find/FindProjectCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/find/FindProjectCommandParser.java @@ -1,25 +1,27 @@ package seedu.address.logic.parser.find; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DEADLINE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT; import java.util.Arrays; +import java.util.function.Predicate; import seedu.address.logic.commands.find.FindProjectCommand; +import seedu.address.logic.parser.ArgumentMultimap; +import seedu.address.logic.parser.ArgumentTokenizer; import seedu.address.logic.parser.Parser; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.project.DeadlineContainsKeywordsPredicate; import seedu.address.model.project.DescriptionContainsKeywordsPredicate; +import seedu.address.model.project.Project; import seedu.address.model.project.ProjectNameContainsKeywordsPredicate; /** * Parses input arguments and creates a new FindProjectCommand object */ public class FindProjectCommandParser implements Parser { - /** - * Parses the given {@code String} of arguments in the context of the FindProjectCommand - * and returns a FindProjectCommand object for execution. - * @throws ParseException if the user input does not conform the expected format - */ public FindProjectCommand parse(String args) throws ParseException { String trimmedArgs = args.trim(); if (trimmedArgs.isEmpty()) { @@ -27,18 +29,36 @@ public FindProjectCommand parse(String args) throws ParseException { String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindProjectCommand.MESSAGE_USAGE)); } - if (trimmedArgs.startsWith("n/")) { - String[] projectNameKeywords = trimmedArgs.replaceFirst("n/", "").split("\\s+"); - return new FindProjectCommand(new ProjectNameContainsKeywordsPredicate(Arrays.asList(projectNameKeywords))); - } else if (trimmedArgs.startsWith("dr/")) { - String[] descriptionKeywords = trimmedArgs.replaceFirst("r/", "").split("\\s+"); - return new FindProjectCommand(new DescriptionContainsKeywordsPredicate(Arrays.asList(descriptionKeywords))); - } else if (trimmedArgs.startsWith("dl/")) { - String[] deadlineKeywords = trimmedArgs.replaceFirst("a/", "").split("\\s+"); - return new FindProjectCommand(new DeadlineContainsKeywordsPredicate(Arrays.asList(deadlineKeywords))); - } else { + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_DEADLINE, PREFIX_DESCRIPTION, PREFIX_PROJECT); + + if (!argMultimap.getPreamble().isEmpty()) { throw new ParseException( String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindProjectCommand.MESSAGE_USAGE)); } + + Predicate finalPredicate = buildPredicate(argMultimap); + + return new FindProjectCommand(finalPredicate); + } + + private Predicate buildPredicate(ArgumentMultimap argMultimap) { + Predicate finalPredicate = project -> true; + + if (argMultimap.getValue(PREFIX_PROJECT).isPresent()) { + String[] projectNameKeywords = argMultimap.getValue(PREFIX_PROJECT).get().split("\\s+"); + finalPredicate = finalPredicate.and(new ProjectNameContainsKeywordsPredicate(Arrays.asList(projectNameKeywords))); + } + + if (argMultimap.getValue(PREFIX_DESCRIPTION).isPresent()) { + String[] descriptionKeywords = argMultimap.getValue(PREFIX_DESCRIPTION).get().split("\\s+"); + finalPredicate = finalPredicate.and(new DescriptionContainsKeywordsPredicate(Arrays.asList(descriptionKeywords))); + } + + if (argMultimap.getValue(PREFIX_DEADLINE).isPresent()) { + String[] deadlineKeywords = argMultimap.getValue(PREFIX_DEADLINE).get().split("\\s+"); + finalPredicate = finalPredicate.and(new DeadlineContainsKeywordsPredicate(Arrays.asList(deadlineKeywords))); + } + + return finalPredicate; } } \ No newline at end of file diff --git a/src/main/java/seedu/address/model/client/AddressClientContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/client/AddressClientContainsKeywordsPredicate.java new file mode 100644 index 00000000000..723980f360f --- /dev/null +++ b/src/main/java/seedu/address/model/client/AddressClientContainsKeywordsPredicate.java @@ -0,0 +1,43 @@ +package seedu.address.model.client; + +import java.util.List; +import seedu.address.commons.util.StringUtil; +import seedu.address.commons.util.ToStringBuilder; +import seedu.address.model.person.KeywordPredicate; + +/** + * Tests that a {@code client}'s {@code Address} matches any of the keywords given. + */ +public class AddressClientContainsKeywordsPredicate implements KeywordPredicate { + private final List keywords; + + public AddressClientContainsKeywordsPredicate(List keywords) { + this.keywords = keywords; + } + + @Override + public boolean test(Client client) { + return keywords.stream() + .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(client.getAddress().value, keyword)); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof AddressClientContainsKeywordsPredicate)) { + return false; + } + + AddressClientContainsKeywordsPredicate otherPredicate = (AddressClientContainsKeywordsPredicate) other; + return keywords.equals(otherPredicate.keywords); + } + + @Override + public String toString() { + return new ToStringBuilder(this).add("keywords", keywords).toString(); + } +} \ No newline at end of file diff --git a/src/main/java/seedu/address/model/client/EmailClientContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/client/EmailClientContainsKeywordsPredicate.java new file mode 100644 index 00000000000..d46ecbd4bd0 --- /dev/null +++ b/src/main/java/seedu/address/model/client/EmailClientContainsKeywordsPredicate.java @@ -0,0 +1,44 @@ +package seedu.address.model.client; + +import java.util.List; + +import seedu.address.commons.util.StringUtil; +import seedu.address.commons.util.ToStringBuilder; +import seedu.address.model.person.KeywordPredicate; + +/** + * Tests that a {@code Client}'s {@code Email} matches any of the keywords given. + */ +public class EmailClientContainsKeywordsPredicate implements KeywordPredicate { + private final List keywords; + + public EmailClientContainsKeywordsPredicate(List keywords) { + this.keywords = keywords; + } + + @Override + public boolean test(Client client) { + return keywords.stream() + .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(client.getEmail().value, keyword)); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof seedu.address.model.client.EmailClientContainsKeywordsPredicate)) { + return false; + } + + seedu.address.model.client.EmailClientContainsKeywordsPredicate otherPredicate = (seedu.address.model.client.EmailClientContainsKeywordsPredicate) other; + return keywords.equals(otherPredicate.keywords); + } + + @Override + public String toString() { + return new ToStringBuilder(this).add("keywords", keywords).toString(); + } +} diff --git a/src/main/java/seedu/address/model/client/NameClientContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/client/NameClientContainsKeywordsPredicate.java new file mode 100644 index 00000000000..78d8023b16c --- /dev/null +++ b/src/main/java/seedu/address/model/client/NameClientContainsKeywordsPredicate.java @@ -0,0 +1,44 @@ +package seedu.address.model.client; + +import java.util.List; + +import seedu.address.commons.util.StringUtil; +import seedu.address.commons.util.ToStringBuilder; +import seedu.address.model.person.KeywordPredicate; + +/** + * Tests that a {@code Client}'s {@code Name} matches any of the keywords given. + */ +public class NameClientContainsKeywordsPredicate implements KeywordPredicate { + private final List keywords; + + public NameClientContainsKeywordsPredicate(List keywords) { + this.keywords = keywords; + } + + @Override + public boolean test(Client client) { + return keywords.stream() + .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(client.getName().fullName, keyword)); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof seedu.address.model.client.NameClientContainsKeywordsPredicate)) { + return false; + } + + seedu.address.model.client.NameClientContainsKeywordsPredicate otherNameContainsKeywordsPredicate = (seedu.address.model.client.NameClientContainsKeywordsPredicate) other; + return keywords.equals(otherNameContainsKeywordsPredicate.keywords); + } + + @Override + public String toString() { + return new ToStringBuilder(this).add("keywords", keywords).toString(); + } +} diff --git a/src/main/java/seedu/address/model/client/PhoneClientContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/client/PhoneClientContainsKeywordsPredicate.java new file mode 100644 index 00000000000..d07cec66c61 --- /dev/null +++ b/src/main/java/seedu/address/model/client/PhoneClientContainsKeywordsPredicate.java @@ -0,0 +1,44 @@ +package seedu.address.model.client; + +import java.util.List; + +import seedu.address.commons.util.StringUtil; +import seedu.address.commons.util.ToStringBuilder; +import seedu.address.model.person.KeywordPredicate; + +/** + * Tests that a {@code Client}'s {@code Phone} matches any of the keywords given. + */ +public class PhoneClientContainsKeywordsPredicate implements KeywordPredicate { + private final List keywords; + + public PhoneClientContainsKeywordsPredicate(List keywords) { + this.keywords = keywords; + } + + @Override + public boolean test(Client client) { + return keywords.stream() + .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(client.getPhone().value, keyword)); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof seedu.address.model.client.PhoneClientContainsKeywordsPredicate)) { + return false; + } + + seedu.address.model.client.PhoneClientContainsKeywordsPredicate otherPredicate = (seedu.address.model.client.PhoneClientContainsKeywordsPredicate) other; + return keywords.equals(otherPredicate.keywords); + } + + @Override + public String toString() { + return new ToStringBuilder(this).add("keywords", keywords).toString(); + } +} diff --git a/src/main/java/seedu/address/model/client/ProjectClientContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/client/ProjectClientContainsKeywordsPredicate.java new file mode 100644 index 00000000000..d1af625ea17 --- /dev/null +++ b/src/main/java/seedu/address/model/client/ProjectClientContainsKeywordsPredicate.java @@ -0,0 +1,44 @@ +package seedu.address.model.client; + +import java.util.List; + +import seedu.address.commons.util.StringUtil; +import seedu.address.commons.util.ToStringBuilder; +import seedu.address.model.person.KeywordPredicate; + +/** + * Tests that a {@code Client}'s associated {@code Project} names match any of the keywords given. + */ +public class ProjectClientContainsKeywordsPredicate implements KeywordPredicate { + private final List keywords; + + public ProjectClientContainsKeywordsPredicate(List keywords) { + this.keywords = keywords; + } + + @Override + public boolean test(Client client) { + return keywords.stream() + .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(client.getProjects().toString(), keyword)); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof seedu.address.model.client.ProjectClientContainsKeywordsPredicate)) { + return false; + } + + seedu.address.model.client.ProjectClientContainsKeywordsPredicate otherPredicate = (seedu.address.model.client.ProjectClientContainsKeywordsPredicate) other; + return keywords.equals(otherPredicate.keywords); + } + + @Override + public String toString() { + return new ToStringBuilder(this).add("keywords", keywords).toString(); + } +} diff --git a/src/main/java/seedu/address/model/client/RoleClientContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/client/RoleClientContainsKeywordsPredicate.java new file mode 100644 index 00000000000..8f55a1ab385 --- /dev/null +++ b/src/main/java/seedu/address/model/client/RoleClientContainsKeywordsPredicate.java @@ -0,0 +1,44 @@ +package seedu.address.model.client; + +import java.util.List; + +import seedu.address.commons.util.StringUtil; +import seedu.address.commons.util.ToStringBuilder; +import seedu.address.model.person.KeywordPredicate; + +/** + * Tests that a {@code Client}'s {@code Role} matches any of the keywords given. + */ +public class RoleClientContainsKeywordsPredicate implements KeywordPredicate { + private final List keywords; + + public RoleClientContainsKeywordsPredicate(List keywords) { + this.keywords = keywords; + } + + @Override + public boolean test(Client client) { + return keywords.stream() + .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(client.getRole().toString(), keyword)); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof RoleClientContainsKeywordsPredicate)) { + return false; + } + + RoleClientContainsKeywordsPredicate otherRoleContainsKeywordsPredicate = (RoleClientContainsKeywordsPredicate) other; + return keywords.equals(otherRoleContainsKeywordsPredicate.keywords); + } + + @Override + public String toString() { + return new ToStringBuilder(this).add("keywords", keywords).toString(); + } +} diff --git a/src/main/java/seedu/address/model/person/AddressContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/developer/AddressDeveloperContainsKeywordsPredicate.java similarity index 55% rename from src/main/java/seedu/address/model/person/AddressContainsKeywordsPredicate.java rename to src/main/java/seedu/address/model/developer/AddressDeveloperContainsKeywordsPredicate.java index da9fe1ed6db..9eb3a753a14 100644 --- a/src/main/java/seedu/address/model/person/AddressContainsKeywordsPredicate.java +++ b/src/main/java/seedu/address/model/developer/AddressDeveloperContainsKeywordsPredicate.java @@ -1,24 +1,24 @@ -package seedu.address.model.person; +package seedu.address.model.developer; import java.util.List; - import seedu.address.commons.util.StringUtil; import seedu.address.commons.util.ToStringBuilder; +import seedu.address.model.person.KeywordPredicate; /** * Tests that a {@code Developer}'s {@code Address} matches any of the keywords given. */ -public class AddressContainsKeywordsPredicate implements KeywordPredicate { +public class AddressDeveloperContainsKeywordsPredicate implements KeywordPredicate { private final List keywords; - public AddressContainsKeywordsPredicate(List keywords) { + public AddressDeveloperContainsKeywordsPredicate(List keywords) { this.keywords = keywords; } @Override - public boolean test(Person person) { + public boolean test(Developer developer) { return keywords.stream() - .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(person.getAddress().toString(), keyword)); + .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(developer.getAddress().value, keyword)); } @Override @@ -28,12 +28,12 @@ public boolean equals(Object other) { } // instanceof handles nulls - if (!(other instanceof AddressContainsKeywordsPredicate)) { + if (!(other instanceof AddressDeveloperContainsKeywordsPredicate)) { return false; } - AddressContainsKeywordsPredicate otherAddressContainsKeywordsPredicate = (AddressContainsKeywordsPredicate) other; - return keywords.equals(otherAddressContainsKeywordsPredicate.keywords); + AddressDeveloperContainsKeywordsPredicate otherPredicate = (AddressDeveloperContainsKeywordsPredicate) other; + return keywords.equals(otherPredicate.keywords); } @Override diff --git a/src/main/java/seedu/address/model/developer/CombinedDeveloperPredicate.java b/src/main/java/seedu/address/model/developer/CombinedDeveloperPredicate.java new file mode 100644 index 00000000000..7b780f2c0cb --- /dev/null +++ b/src/main/java/seedu/address/model/developer/CombinedDeveloperPredicate.java @@ -0,0 +1,52 @@ +package seedu.address.model.developer; + +import java.util.function.Predicate; + +public class CombinedDeveloperPredicate implements Predicate { + private final Predicate namePredicate; + private final Predicate rolePredicate; + private final Predicate addressPredicate; + private final Predicate dateJoinedPredicate; + private final Predicate emailPredicate; + private final Predicate phonePredicate; + private final Predicate projectPredicate; + private final Predicate salaryPredicate; + private final Predicate ratingPredicate; + private final Predicate githubIdPredicate; + + public CombinedDeveloperPredicate(Predicate namePredicate, + Predicate rolePredicate, + Predicate addressPredicate, + Predicate dateJoinedPredicate, + Predicate emailPredicate, + Predicate phonePredicate, + Predicate projectPredicate, + Predicate salaryPredicate, + Predicate ratingPredicate, + Predicate githubIdPredicate) { + this.namePredicate = namePredicate; + this.rolePredicate = rolePredicate; + this.addressPredicate = addressPredicate; + this.dateJoinedPredicate = dateJoinedPredicate; + this.emailPredicate = emailPredicate; + this.phonePredicate = phonePredicate; + this.projectPredicate = projectPredicate; + this.salaryPredicate = salaryPredicate; + this.ratingPredicate = ratingPredicate; + this.githubIdPredicate = githubIdPredicate; + } + + @Override + public boolean test(Developer developer) { + return namePredicate.test(developer) && + rolePredicate.test(developer) && + addressPredicate.test(developer) && + dateJoinedPredicate.test(developer) && + emailPredicate.test(developer) && + phonePredicate.test(developer) && + projectPredicate.test(developer) && + salaryPredicate.test(developer) && + ratingPredicate.test(developer) && + githubIdPredicate.test(developer); + } +} \ No newline at end of file diff --git a/src/main/java/seedu/address/model/person/EmailContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/developer/EmailDeveloperContainsKeywordsPredicate.java similarity index 55% rename from src/main/java/seedu/address/model/person/EmailContainsKeywordsPredicate.java rename to src/main/java/seedu/address/model/developer/EmailDeveloperContainsKeywordsPredicate.java index 5400ae0cd3d..74d3b37db1e 100644 --- a/src/main/java/seedu/address/model/person/EmailContainsKeywordsPredicate.java +++ b/src/main/java/seedu/address/model/developer/EmailDeveloperContainsKeywordsPredicate.java @@ -1,24 +1,24 @@ -package seedu.address.model.person; +package seedu.address.model.developer; import java.util.List; - import seedu.address.commons.util.StringUtil; import seedu.address.commons.util.ToStringBuilder; +import seedu.address.model.person.KeywordPredicate; /** * Tests that a {@code Developer}'s {@code Email} matches any of the keywords given. */ -public class EmailContainsKeywordsPredicate implements KeywordPredicate { +public class EmailDeveloperContainsKeywordsPredicate implements KeywordPredicate { private final List keywords; - public EmailContainsKeywordsPredicate(List keywords) { + public EmailDeveloperContainsKeywordsPredicate(List keywords) { this.keywords = keywords; } @Override - public boolean test(Person person) { + public boolean test(Developer developer) { return keywords.stream() - .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(person.getEmail().value, keyword)); + .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(developer.getEmail().value, keyword)); } @Override @@ -28,12 +28,12 @@ public boolean equals(Object other) { } // instanceof handles nulls - if (!(other instanceof EmailContainsKeywordsPredicate)) { + if (!(other instanceof EmailDeveloperContainsKeywordsPredicate)) { return false; } - EmailContainsKeywordsPredicate otherEmailContainsKeywordsPredicate = (EmailContainsKeywordsPredicate) other; - return keywords.equals(otherEmailContainsKeywordsPredicate.keywords); + EmailDeveloperContainsKeywordsPredicate otherPredicate = (EmailDeveloperContainsKeywordsPredicate) other; + return keywords.equals(otherPredicate.keywords); } @Override diff --git a/src/main/java/seedu/address/model/person/NameContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/developer/NameDeveloperContainsKeywordsPredicate.java similarity index 59% rename from src/main/java/seedu/address/model/person/NameContainsKeywordsPredicate.java rename to src/main/java/seedu/address/model/developer/NameDeveloperContainsKeywordsPredicate.java index 885126e6e8c..77e758ae19e 100644 --- a/src/main/java/seedu/address/model/person/NameContainsKeywordsPredicate.java +++ b/src/main/java/seedu/address/model/developer/NameDeveloperContainsKeywordsPredicate.java @@ -1,24 +1,24 @@ -package seedu.address.model.person; +package seedu.address.model.developer; import java.util.List; - import seedu.address.commons.util.StringUtil; import seedu.address.commons.util.ToStringBuilder; +import seedu.address.model.person.KeywordPredicate; /** * Tests that a {@code Developer}'s {@code Name} matches any of the keywords given. */ -public class NameContainsKeywordsPredicate implements KeywordPredicate { +public class NameDeveloperContainsKeywordsPredicate implements KeywordPredicate { private final List keywords; - public NameContainsKeywordsPredicate(List keywords) { + public NameDeveloperContainsKeywordsPredicate(List keywords) { this.keywords = keywords; } @Override - public boolean test(Person person) { + public boolean test(Developer developer) { return keywords.stream() - .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(person.getName().fullName, keyword)); + .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(developer.getName().fullName, keyword)); } @Override @@ -28,11 +28,11 @@ public boolean equals(Object other) { } // instanceof handles nulls - if (!(other instanceof NameContainsKeywordsPredicate)) { + if (!(other instanceof NameDeveloperContainsKeywordsPredicate)) { return false; } - NameContainsKeywordsPredicate otherNameContainsKeywordsPredicate = (NameContainsKeywordsPredicate) other; + NameDeveloperContainsKeywordsPredicate otherNameContainsKeywordsPredicate = (NameDeveloperContainsKeywordsPredicate) other; return keywords.equals(otherNameContainsKeywordsPredicate.keywords); } @@ -40,4 +40,4 @@ public boolean equals(Object other) { public String toString() { return new ToStringBuilder(this).add("keywords", keywords).toString(); } -} +} \ No newline at end of file diff --git a/src/main/java/seedu/address/model/person/PhoneContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/developer/PhoneDeveloperContainsKeywordsPredicate.java similarity index 55% rename from src/main/java/seedu/address/model/person/PhoneContainsKeywordsPredicate.java rename to src/main/java/seedu/address/model/developer/PhoneDeveloperContainsKeywordsPredicate.java index 7e423d85dbf..0b73f19f87e 100644 --- a/src/main/java/seedu/address/model/person/PhoneContainsKeywordsPredicate.java +++ b/src/main/java/seedu/address/model/developer/PhoneDeveloperContainsKeywordsPredicate.java @@ -1,24 +1,24 @@ -package seedu.address.model.person; +package seedu.address.model.developer; import java.util.List; - import seedu.address.commons.util.StringUtil; import seedu.address.commons.util.ToStringBuilder; +import seedu.address.model.person.KeywordPredicate; /** * Tests that a {@code Developer}'s {@code Phone} matches any of the keywords given. */ -public class PhoneContainsKeywordsPredicate implements KeywordPredicate { +public class PhoneDeveloperContainsKeywordsPredicate implements KeywordPredicate { private final List keywords; - public PhoneContainsKeywordsPredicate(List keywords) { + public PhoneDeveloperContainsKeywordsPredicate(List keywords) { this.keywords = keywords; } @Override - public boolean test(Person person) { + public boolean test(Developer developer) { return keywords.stream() - .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(person.getPhone().value, keyword)); + .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(developer.getPhone().value, keyword)); } @Override @@ -28,16 +28,16 @@ public boolean equals(Object other) { } // instanceof handles nulls - if (!(other instanceof PhoneContainsKeywordsPredicate)) { + if (!(other instanceof PhoneDeveloperContainsKeywordsPredicate)) { return false; } - PhoneContainsKeywordsPredicate otherPhoneContainsKeywordsPredicate = (PhoneContainsKeywordsPredicate) other; - return keywords.equals(otherPhoneContainsKeywordsPredicate.keywords); + PhoneDeveloperContainsKeywordsPredicate otherPredicate = (PhoneDeveloperContainsKeywordsPredicate) other; + return keywords.equals(otherPredicate.keywords); } @Override public String toString() { return new ToStringBuilder(this).add("keywords", keywords).toString(); } -} +} \ No newline at end of file diff --git a/src/main/java/seedu/address/model/developer/ProjectDeveloperContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/developer/ProjectDeveloperContainsKeywordsPredicate.java new file mode 100644 index 00000000000..512cb91fdc6 --- /dev/null +++ b/src/main/java/seedu/address/model/developer/ProjectDeveloperContainsKeywordsPredicate.java @@ -0,0 +1,44 @@ +package seedu.address.model.developer; + +import java.util.List; + +import seedu.address.commons.util.StringUtil; +import seedu.address.commons.util.ToStringBuilder; +import seedu.address.model.person.KeywordPredicate; + +/** + * Tests that a {@code Developer}'s associated {@code Project} names match any of the keywords given. + */ +public class ProjectDeveloperContainsKeywordsPredicate implements KeywordPredicate { + private final List keywords; + + public ProjectDeveloperContainsKeywordsPredicate(List keywords) { + this.keywords = keywords; + } + + @Override + public boolean test(Developer developer) { + return keywords.stream() + .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(developer.getProjects().toString(), keyword)); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof ProjectDeveloperContainsKeywordsPredicate)) { + return false; + } + + ProjectDeveloperContainsKeywordsPredicate otherPredicate = (ProjectDeveloperContainsKeywordsPredicate) other; + return keywords.equals(otherPredicate.keywords); + } + + @Override + public String toString() { + return new ToStringBuilder(this).add("keywords", keywords).toString(); + } +} \ No newline at end of file diff --git a/src/main/java/seedu/address/model/person/RoleContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/developer/RoleDeveloperContainsKeywordsPredicate.java similarity index 59% rename from src/main/java/seedu/address/model/person/RoleContainsKeywordsPredicate.java rename to src/main/java/seedu/address/model/developer/RoleDeveloperContainsKeywordsPredicate.java index 1d2ff6e455f..5731deab69f 100644 --- a/src/main/java/seedu/address/model/person/RoleContainsKeywordsPredicate.java +++ b/src/main/java/seedu/address/model/developer/RoleDeveloperContainsKeywordsPredicate.java @@ -1,24 +1,24 @@ -package seedu.address.model.person; +package seedu.address.model.developer; import java.util.List; - import seedu.address.commons.util.StringUtil; import seedu.address.commons.util.ToStringBuilder; +import seedu.address.model.person.KeywordPredicate; /** * Tests that a {@code Developer}'s {@code Role} matches any of the keywords given. */ -public class RoleContainsKeywordsPredicate implements KeywordPredicate { +public class RoleDeveloperContainsKeywordsPredicate implements KeywordPredicate { private final List keywords; - public RoleContainsKeywordsPredicate(List keywords) { + public RoleDeveloperContainsKeywordsPredicate(List keywords) { this.keywords = keywords; } @Override - public boolean test(Person person) { + public boolean test(Developer developer) { return keywords.stream() - .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(person.getRole().toString(), keyword)); + .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(developer.getRole().toString(), keyword)); } @Override @@ -28,11 +28,11 @@ public boolean equals(Object other) { } // instanceof handles nulls - if (!(other instanceof RoleContainsKeywordsPredicate)) { + if (!(other instanceof RoleDeveloperContainsKeywordsPredicate)) { return false; } - RoleContainsKeywordsPredicate otherRoleContainsKeywordsPredicate = (RoleContainsKeywordsPredicate) other; + RoleDeveloperContainsKeywordsPredicate otherRoleContainsKeywordsPredicate = (RoleDeveloperContainsKeywordsPredicate) other; return keywords.equals(otherRoleContainsKeywordsPredicate.keywords); } diff --git a/src/main/java/seedu/address/model/person/KeywordPredicateFactory.java b/src/main/java/seedu/address/model/person/KeywordPredicateFactory.java new file mode 100644 index 00000000000..a2623d42c3e --- /dev/null +++ b/src/main/java/seedu/address/model/person/KeywordPredicateFactory.java @@ -0,0 +1,8 @@ +package seedu.address.model.person; + +import java.util.List; + +@FunctionalInterface +public interface KeywordPredicateFactory { + KeywordPredicate createPredicate(List keywords); +} diff --git a/src/main/java/seedu/address/model/person/ProjectContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/person/ProjectContainsKeywordsPredicate.java deleted file mode 100644 index f6f5779ce7e..00000000000 --- a/src/main/java/seedu/address/model/person/ProjectContainsKeywordsPredicate.java +++ /dev/null @@ -1,45 +0,0 @@ -package seedu.address.model.person; - -import java.util.List; - -import seedu.address.commons.util.StringUtil; -import seedu.address.commons.util.ToStringBuilder; - -/** - * Tests that a {@code Developer}'s {@code Project} matches any of the keywords given. - */ -public class ProjectContainsKeywordsPredicate implements KeywordPredicate { - private final List keywords; - - public ProjectContainsKeywordsPredicate(List keywords) { - this.keywords = keywords; - } - - @Override - public boolean test(Person person) { - // Assuming that the Developer class has a getProject() method that returns a Project object - // and that Project object has a method called asString() which returns the string representation of the project. - return keywords.stream() - .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(person.getProjects().toString(), keyword)); - } - - @Override - public boolean equals(Object other) { - if (other == this) { - return true; - } - - // instanceof handles nulls - if (!(other instanceof ProjectContainsKeywordsPredicate)) { - return false; - } - - ProjectContainsKeywordsPredicate otherProjectContainsKeywordsPredicate = (ProjectContainsKeywordsPredicate) other; - return keywords.equals(otherProjectContainsKeywordsPredicate.keywords); - } - - @Override - public String toString() { - return new ToStringBuilder(this).add("keywords", keywords).toString(); - } -} \ No newline at end of file diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index f22f4a5d9b8..8cfa1cf8f5b 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -17,7 +17,7 @@ import seedu.address.model.AddressBook; import seedu.address.model.Model; import seedu.address.model.person.Developer; -import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.developer.NameDeveloperContainsKeywordsPredicate; import seedu.address.testutil.EditPersonDescriptorBuilder; /** @@ -116,7 +116,7 @@ public static void showPersonAtIndex(Model model, Index targetIndex) { Developer developer = model.getFilteredPersonList().get(targetIndex.getZeroBased()); final String[] splitName = developer.getName().fullName.split("\\s+"); - model.updateFilteredPersonList(new NameContainsKeywordsPredicate(Arrays.asList(splitName[0]))); + model.updateFilteredPersonList(new NameDeveloperContainsKeywordsPredicate(Arrays.asList(splitName[0]))); assertEquals(1, model.getFilteredPersonList().size()); } diff --git a/src/test/java/seedu/address/logic/commands/FindCommandTest.java b/src/test/java/seedu/address/logic/commands/FindCommandTest.java index d94b17403cc..0bbeea1afa5 100644 --- a/src/test/java/seedu/address/logic/commands/FindCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/FindCommandTest.java @@ -19,7 +19,7 @@ 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.developer.NameDeveloperContainsKeywordsPredicate; /** * Contains integration tests (interaction with the Model) for {@code FindDeveloperCommand}. @@ -30,10 +30,10 @@ public class FindDeveloperCommandTest { @Test public void equals() { - NameContainsKeywordsPredicate firstPredicate = - new NameContainsKeywordsPredicate(Collections.singletonList("first")); - NameContainsKeywordsPredicate secondPredicate = - new NameContainsKeywordsPredicate(Collections.singletonList("second")); + NameDeveloperContainsKeywordsPredicate firstPredicate = + new NameDeveloperContainsKeywordsPredicate(Collections.singletonList("first")); + NameDeveloperContainsKeywordsPredicate secondPredicate = + new NameDeveloperContainsKeywordsPredicate(Collections.singletonList("second")); FindDeveloperCommand findFirstCommand = new FindDeveloperCommand(firstPredicate); FindDeveloperCommand findSecondCommand = new FindDeveloperCommand(secondPredicate); @@ -58,7 +58,7 @@ public void equals() { @Test public void execute_zeroKeywords_noPersonFound() { String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0); - NameContainsKeywordsPredicate predicate = preparePredicate(" "); + NameDeveloperContainsKeywordsPredicate predicate = preparePredicate(" "); FindDeveloperCommand command = new FindDeveloperCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -68,7 +68,7 @@ public void execute_zeroKeywords_noPersonFound() { @Test public void execute_multipleKeywords_multiplePersonsFound() { String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 3); - NameContainsKeywordsPredicate predicate = preparePredicate("Kurz Elle Kunz"); + NameDeveloperContainsKeywordsPredicate predicate = preparePredicate("Kurz Elle Kunz"); FindDeveloperCommand command = new FindDeveloperCommand(predicate); expectedModel.updateFilteredPersonList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -77,7 +77,7 @@ public void execute_multipleKeywords_multiplePersonsFound() { @Test public void toStringMethod() { - NameContainsKeywordsPredicate predicate = new NameContainsKeywordsPredicate(Arrays.asList("keyword")); + NameDeveloperContainsKeywordsPredicate predicate = new NameDeveloperContainsKeywordsPredicate(Arrays.asList("keyword")); FindDeveloperCommand findDeveloperCommand = new FindDeveloperCommand(predicate); String expected = FindDeveloperCommand.class.getCanonicalName() + "{predicate=" + predicate + "}"; assertEquals(expected, findDeveloperCommand.toString()); @@ -86,7 +86,7 @@ public void toStringMethod() { /** * Parses {@code userInput} into a {@code NameContainsKeywordsPredicate}. */ - private NameContainsKeywordsPredicate preparePredicate(String userInput) { - return new NameContainsKeywordsPredicate(Arrays.asList(userInput.split("\\s+"))); + private NameDeveloperContainsKeywordsPredicate preparePredicate(String userInput) { + return new NameDeveloperContainsKeywordsPredicate(Arrays.asList(userInput.split("\\s+"))); } } diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index e3b7cb20d3f..8263ce92fb6 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -21,7 +21,7 @@ import seedu.address.logic.commands.HelpCommand; import seedu.address.logic.commands.ListClientCommand; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.developer.NameDeveloperContainsKeywordsPredicate; import seedu.address.model.developer.Developer; import seedu.address.testutil.EditPersonDescriptorBuilder; import seedu.address.testutil.PersonBuilder; @@ -71,7 +71,7 @@ public void parseCommand_find() throws Exception { List keywords = Arrays.asList("foo", "bar", "baz"); FindDeveloperCommand command = (FindDeveloperCommand) parser.parseCommand( FindDeveloperCommand.COMMAND_WORD + " " + keywords.stream().collect(Collectors.joining(" "))); - assertEquals(new FindDeveloperCommand(new NameContainsKeywordsPredicate(keywords)), command); + assertEquals(new FindDeveloperCommand(new NameDeveloperContainsKeywordsPredicate(keywords)), command); } @Test diff --git a/src/test/java/seedu/address/logic/parser/FindDeveloperCommandParserTest.java b/src/test/java/seedu/address/logic/parser/FindDeveloperCommandParserTest.java index 67935ddf928..8fb9b56bf34 100644 --- a/src/test/java/seedu/address/logic/parser/FindDeveloperCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/FindDeveloperCommandParserTest.java @@ -10,7 +10,7 @@ import seedu.address.logic.commands.find.FindDeveloperCommand; import seedu.address.logic.parser.find.FindDeveloperCommandParser; -import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.developer.NameDeveloperContainsKeywordsPredicate; public class FindDeveloperCommandParserTest { @@ -25,7 +25,7 @@ public void parse_emptyArg_throwsParseException() { public void parse_validArgs_returnsFindDeveloperCommand() { // no leading and trailing whitespaces FindDeveloperCommand expectedFindDeveloperCommand = - new FindDeveloperCommand(new NameContainsKeywordsPredicate(Arrays.asList("Alice", "Bob"))); + new FindDeveloperCommand(new NameDeveloperContainsKeywordsPredicate(Arrays.asList("Alice", "Bob"))); assertParseSuccess(parser, "Alice Bob", expectedFindDeveloperCommand); // multiple whitespaces between keywords diff --git a/src/test/java/seedu/address/model/ModelManagerTest.java b/src/test/java/seedu/address/model/ModelManagerTest.java index 2cf1418d116..697e69bfdde 100644 --- a/src/test/java/seedu/address/model/ModelManagerTest.java +++ b/src/test/java/seedu/address/model/ModelManagerTest.java @@ -15,7 +15,7 @@ import org.junit.jupiter.api.Test; import seedu.address.commons.core.GuiSettings; -import seedu.address.model.person.NameContainsKeywordsPredicate; +import seedu.address.model.developer.NameDeveloperContainsKeywordsPredicate; import seedu.address.testutil.AddressBookBuilder; public class ModelManagerTest { @@ -118,7 +118,7 @@ public void equals() { // different filteredList -> returns false String[] keywords = ALICE.getName().fullName.split("\\s+"); - modelManager.updateFilteredPersonList(new NameContainsKeywordsPredicate(Arrays.asList(keywords))); + modelManager.updateFilteredPersonList(new NameDeveloperContainsKeywordsPredicate(Arrays.asList(keywords))); assertFalse(modelManager.equals(new ModelManager(addressBook, userPrefs))); // resets modelManager to initial state for upcoming tests diff --git a/src/test/java/seedu/address/model/person/NameContainsKeywordsPredicateTest.java b/src/test/java/seedu/address/model/person/NameContainsKeywordsPredicateTest.java index 2e6460eee96..f4c7243b826 100644 --- a/src/test/java/seedu/address/model/person/NameContainsKeywordsPredicateTest.java +++ b/src/test/java/seedu/address/model/person/NameContainsKeywordsPredicateTest.java @@ -10,6 +10,7 @@ import org.junit.jupiter.api.Test; +import seedu.address.model.developer.NameDeveloperContainsKeywordsPredicate; import seedu.address.testutil.PersonBuilder; public class NameContainsKeywordsPredicateTest { @@ -19,14 +20,14 @@ public void equals() { List firstPredicateKeywordList = Collections.singletonList("first"); List secondPredicateKeywordList = Arrays.asList("first", "second"); - NameContainsKeywordsPredicate firstPredicate = new NameContainsKeywordsPredicate(firstPredicateKeywordList); - NameContainsKeywordsPredicate secondPredicate = new NameContainsKeywordsPredicate(secondPredicateKeywordList); + NameDeveloperContainsKeywordsPredicate firstPredicate = new NameDeveloperContainsKeywordsPredicate(firstPredicateKeywordList); + NameDeveloperContainsKeywordsPredicate secondPredicate = new NameDeveloperContainsKeywordsPredicate(secondPredicateKeywordList); // same object -> returns true assertTrue(firstPredicate.equals(firstPredicate)); // same values -> returns true - NameContainsKeywordsPredicate firstPredicateCopy = new NameContainsKeywordsPredicate(firstPredicateKeywordList); + NameDeveloperContainsKeywordsPredicate firstPredicateCopy = new NameDeveloperContainsKeywordsPredicate(firstPredicateKeywordList); assertTrue(firstPredicate.equals(firstPredicateCopy)); // different types -> returns false @@ -42,34 +43,34 @@ public void equals() { @Test public void test_nameContainsKeywords_returnsTrue() { // One keyword - NameContainsKeywordsPredicate predicate = new NameContainsKeywordsPredicate(Collections.singletonList("Alice")); + NameDeveloperContainsKeywordsPredicate predicate = new NameDeveloperContainsKeywordsPredicate(Collections.singletonList("Alice")); assertTrue(predicate.test(new PersonBuilder().withName("Alice Bob").build())); // Multiple keywords - predicate = new NameContainsKeywordsPredicate(Arrays.asList("Alice", "Bob")); + predicate = new NameDeveloperContainsKeywordsPredicate(Arrays.asList("Alice", "Bob")); assertTrue(predicate.test(new PersonBuilder().withName("Alice Bob").build())); // Only one matching keyword - predicate = new NameContainsKeywordsPredicate(Arrays.asList("Bob", "Carol")); + predicate = new NameDeveloperContainsKeywordsPredicate(Arrays.asList("Bob", "Carol")); assertTrue(predicate.test(new PersonBuilder().withName("Alice Carol").build())); // Mixed-case keywords - predicate = new NameContainsKeywordsPredicate(Arrays.asList("aLIce", "bOB")); + predicate = new NameDeveloperContainsKeywordsPredicate(Arrays.asList("aLIce", "bOB")); assertTrue(predicate.test(new PersonBuilder().withName("Alice Bob").build())); } @Test public void test_nameDoesNotContainKeywords_returnsFalse() { // Zero keywords - NameContainsKeywordsPredicate predicate = new NameContainsKeywordsPredicate(Collections.emptyList()); + NameDeveloperContainsKeywordsPredicate predicate = new NameDeveloperContainsKeywordsPredicate(Collections.emptyList()); assertFalse(predicate.test(new PersonBuilder().withName("Alice").build())); // Non-matching keyword - predicate = new NameContainsKeywordsPredicate(Arrays.asList("Carol")); + predicate = new NameDeveloperContainsKeywordsPredicate(Arrays.asList("Carol")); assertFalse(predicate.test(new PersonBuilder().withName("Alice Bob").build())); // Keywords match phone, email and address, but does not match name - predicate = new NameContainsKeywordsPredicate(Arrays.asList("12345", "alice@email.com", "Main", "Street")); + predicate = new NameDeveloperContainsKeywordsPredicate(Arrays.asList("12345", "alice@email.com", "Main", "Street")); assertFalse(predicate.test(new PersonBuilder().withName("Alice").withPhone("12345") .withEmail("alice@email.com").withAddress("Main Street").build())); } @@ -77,9 +78,9 @@ public void test_nameDoesNotContainKeywords_returnsFalse() { @Test public void toStringMethod() { List keywords = List.of("keyword1", "keyword2"); - NameContainsKeywordsPredicate predicate = new NameContainsKeywordsPredicate(keywords); + NameDeveloperContainsKeywordsPredicate predicate = new NameDeveloperContainsKeywordsPredicate(keywords); - String expected = NameContainsKeywordsPredicate.class.getCanonicalName() + "{keywords=" + keywords + "}"; + String expected = NameDeveloperContainsKeywordsPredicate.class.getCanonicalName() + "{keywords=" + keywords + "}"; assertEquals(expected, predicate.toString()); } }