Skip to content

Commit

Permalink
Merge pull request AY2324S1-CS2103T-T09-2#133 from waseemingly/find-b…
Browse files Browse the repository at this point in the history
…y-multilevel

Add find by multiple attributes
  • Loading branch information
mingyu-wan authored Oct 31, 2023
2 parents ce5075f + 9ed243d commit 7681bef
Show file tree
Hide file tree
Showing 29 changed files with 737 additions and 365 deletions.
25 changes: 25 additions & 0 deletions src/main/java/seedu/address/commons/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <br>examples:<pre>
* containsPartialWordIgnoreCase("ABc def", "abc") == true
* containsPartialWordIgnoreCase("ABc def", "DEF") == true
* containsPartialWordIgnoreCase("ABc def", "AB") == true
* </pre>
* @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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -11,83 +19,45 @@
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/<Project Name> OR Find r/<Role> OR Find n/<Name>.\n"
+ "Example: " + COMMAND_WORD + " n/ alice bob charlie";

private KeywordPredicate<? extends Person> 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<Client> predicate;

public FindClientCommand(Predicate<Client> predicate) {
this.predicate = predicate;
}

@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredClientList((Predicate<Client>) predicate);
model.updateFilteredClientList(predicate);

int resultCount = model.getFilteredClientList().size();
String message = getMessageClientsListedOverview(resultCount);

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;
}
Expand All @@ -102,4 +72,4 @@ public String toString() {
.add("predicate", predicate)
.toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -10,93 +20,48 @@
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/<Project Name> OR Find r/<Role> OR Find n/<Name>.\n"
+ "Example: " + COMMAND_WORD + " n/ alice bob charlie";

private KeywordPredicate<? extends Person> 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<Developer> predicate;

public FindDeveloperCommand(Predicate<Developer> predicate) {
this.predicate = predicate;
}

@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredDeveloperList((Predicate<Developer>) predicate);
model.updateFilteredDeveloperList(predicate);

int resultCount = model.getFilteredDeveloperList().size();
String message = getMessageDevelopersListedOverview(resultCount);

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;
}
Expand All @@ -111,4 +76,4 @@ public String toString() {
.add("predicate", predicate)
.toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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/<Project Name> OR Find r/<Role> OR Find n/<Name>.\n"
+ "Example: " + COMMAND_WORD + " n/ alice bob charlie";

private KeywordPredicate<Project> 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<Project> predicate;

public FindProjectCommand(DeadlineContainsKeywordsPredicate addressPredicate) {
this.predicate = addressPredicate;
public FindProjectCommand(Predicate<Project> predicate) {
this.predicate = predicate;
}

@Override
Expand All @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -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/");


}
Loading

0 comments on commit 7681bef

Please sign in to comment.