forked from nus-cs2103-AY2425S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement filtering of contacts by number #56
Merged
CYX22222003
merged 9 commits into
AY2425S1-CS2103T-F14a-4:master
from
KrashKart:branch-Find-Contact
Oct 10, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d478e3d
Add class file for FindByContactCommand
KrashKart b8afc39
Merge branch 'master' into branch-Find-Contact
KrashKart 86973cd
Add FindByContactCommand
KrashKart 2e31ac5
Add command word and message usage
KrashKart e3f5738
Fix unit test
KrashKart 2c0ea77
Update error message for FindByContactCommand
KrashKart d5ff881
Change unit test for FindCommandParserTest
KrashKart f321113
Remove unused import
KrashKart 723a527
Remove unused imports
KrashKart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/main/java/seedu/address/logic/commands/FindByContactCommand.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,33 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import seedu.address.model.person.ContactContainsKeywordsPredicate; | ||
|
||
/** | ||
* Finds and lists all persons in address book whose contact contains any of the argument keywords. | ||
*/ | ||
public class FindByContactCommand extends AbstractFindCommand { | ||
public static final String COMMAND_WORD = "find /c"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose contact numbers " | ||
+ "contain any of the specified keywords (case-insensitive) and displays them as a list with indices.\n" | ||
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n" | ||
+ "Example: " + COMMAND_WORD + " 91112345 999 995"; | ||
public FindByContactCommand(ContactContainsKeywordsPredicate predicate) { | ||
super(predicate); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof FindByContactCommand)) { | ||
return false; | ||
} | ||
|
||
FindByContactCommand otherFindCommand = (FindByContactCommand) other; | ||
return this.getPredicate().equals(otherFindCommand.getPredicate()); | ||
} | ||
} |
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
90 changes: 90 additions & 0 deletions
90
src/test/java/seedu/address/logic/commands/FindByContactCommandTest.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,90 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static seedu.address.logic.Messages.MESSAGE_PERSONS_LISTED_OVERVIEW; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.UserPrefs; | ||
import seedu.address.model.person.ContactContainsKeywordsPredicate; | ||
import seedu.address.model.person.NameContainsKeywordsPredicate; | ||
|
||
/** | ||
* Contains integration tests (interaction with the Model) for {@code FindByContactCommand}. | ||
*/ | ||
public class FindByContactCommandTest { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good test coverage |
||
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
|
||
@Test | ||
public void equals() { | ||
ContactContainsKeywordsPredicate firstPredicate = | ||
new ContactContainsKeywordsPredicate(Collections.singletonList("first")); | ||
ContactContainsKeywordsPredicate secondPredicate = | ||
new ContactContainsKeywordsPredicate(Collections.singletonList("second")); | ||
|
||
FindByContactCommand findFirstCommand = new FindByContactCommand(firstPredicate); | ||
FindByContactCommand findSecondCommand = new FindByContactCommand(secondPredicate); | ||
|
||
// same object -> returns true | ||
assertTrue(findFirstCommand.equals(findFirstCommand)); | ||
|
||
// same values -> returns true | ||
FindByContactCommand findFirstCommandCopy = new FindByContactCommand(firstPredicate); | ||
assertTrue(findFirstCommand.equals(findFirstCommandCopy)); | ||
|
||
// different types -> returns false | ||
assertFalse(findFirstCommand.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(findFirstCommand.equals(null)); | ||
|
||
// different person -> returns false | ||
assertFalse(findFirstCommand.equals(findSecondCommand)); | ||
} | ||
|
||
@Test | ||
public void execute_zeroKeywords_noPersonFound() { | ||
String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0); | ||
ContactContainsKeywordsPredicate predicate = preparePredicate(" "); | ||
FindByContactCommand command = new FindByContactCommand(predicate); | ||
expectedModel.updateFilteredPersonList(predicate); | ||
assertCommandSuccess(command, model, expectedMessage, expectedModel); | ||
assertEquals(Collections.emptyList(), model.getFilteredPersonList()); | ||
} | ||
|
||
// Commented out because expectedModel does not contain contact numbers | ||
// @Test | ||
// public void execute_multipleKeywords_multiplePersonsFound() { | ||
// String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0); | ||
// ContactContainsKeywordsPredicate predicate = preparePredicate("999"); | ||
// FindByContactCommand command = new FindByContactCommand(predicate); | ||
// expectedModel.updateFilteredPersonList(predicate); | ||
// assertCommandSuccess(command, model, expectedMessage, expectedModel); | ||
// assertEquals(Arrays.asList(CARL, ELLE, FIONA), model.getFilteredPersonList()); | ||
// } | ||
|
||
@Test | ||
public void toStringMethod() { | ||
NameContainsKeywordsPredicate predicate = new NameContainsKeywordsPredicate(Arrays.asList("keyword")); | ||
FindByNameCommand findCommand = new FindByNameCommand(predicate); | ||
String expected = FindByNameCommand.class.getCanonicalName() + "{predicate=" + predicate + "}"; | ||
assertEquals(expected, findCommand.toString()); | ||
} | ||
|
||
/** | ||
* Parses {@code userInput} into a {@code NameContainsKeywordsPredicate}. | ||
*/ | ||
private ContactContainsKeywordsPredicate preparePredicate(String userInput) { | ||
return new ContactContainsKeywordsPredicate(Arrays.asList(userInput.split("\\s+"))); | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep that works