forked from AY2425S1-CS2103T-F15-4/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Find command to parse name prefix
- Loading branch information
Showing
6 changed files
with
144 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/main/java/seedu/address/logic/commands/FindNameCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.NameContainsKeywordsPredicate; | ||
|
||
/** | ||
* Finds and lists all persons in address book whose name contains any of the argument keywords. | ||
* Keyword matching is case-insensitive and allows partial matching. | ||
*/ | ||
public class FindNameCommand extends FindCommand { | ||
|
||
public static final String COMMAND_WORD = "find"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose names contain any of " | ||
+ "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n" | ||
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n" | ||
+ "Example: " + COMMAND_WORD + " alice bob charlie"; | ||
|
||
public static final String MESSAGE_FIND_NAME_PERSON_SUCCESS = "Search for \"%s\" by name was successful. " | ||
+ " Showing results:"; | ||
|
||
public static final String MESSAGE_FIND_NAME_PERSON_UNSUCCESSFUL = "No contacts found."; | ||
|
||
private final NameContainsKeywordsPredicate predicate; | ||
|
||
/** | ||
* Command to filter contacts in WedLinker based on names using partial matching. | ||
* This command allows users to search for contacts by providing one or more keywords. | ||
* The search is case-insensitive and matches any part of the contact names. | ||
* | ||
* @param predicate Keywords used to filter contacts by name. | ||
*/ | ||
public FindNameCommand(NameContainsKeywordsPredicate predicate) { | ||
super(); | ||
this.predicate = predicate; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
requireNonNull(model); | ||
model.updateFilteredPersonList(predicate); | ||
|
||
if (!model.getFilteredPersonList().isEmpty()) { | ||
return new CommandResult(String.format(MESSAGE_FIND_NAME_PERSON_SUCCESS, predicate.getDisplayString())); | ||
} else { | ||
return new CommandResult(MESSAGE_FIND_NAME_PERSON_UNSUCCESSFUL); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof FindNameCommand)) { | ||
return false; | ||
} | ||
|
||
FindNameCommand otherFindCommand = (FindNameCommand) other; | ||
return predicate.equals(otherFindCommand.predicate); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("predicate", predicate) | ||
.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters