Skip to content

Commit

Permalink
Merge 7390cb5 into fa5849c
Browse files Browse the repository at this point in the history
  • Loading branch information
ChooJeremy committed Nov 1, 2018
2 parents fa5849c + 7390cb5 commit 6f49254
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
9 changes: 7 additions & 2 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,18 @@ Format: `find NAME`

****
* NAME can be any name or parts of name.
* You can use the * character to match any number of characters (0 or more)
* You can also use the _ character to match any single character
* Find is case insensitive
****

Examples:

* `find jian yu`
* `find jian yu`: Displays everyone that has 'jian' or 'yu' in their name

* `find doe`
* `find d*` Displays everyone whose's names start with d.

* 'find T_m' Displays 'Tom' and 'Tim', but not 'Tian'

=== Filter employees by criteria : `filter`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.util.List;
import java.util.function.Predicate;

import seedu.address.commons.util.StringUtil;

/**
* Tests that a {@code Person}'s {@code Name} matches any of the keywords given.
*/
Expand All @@ -17,8 +15,16 @@ public NameContainsKeywordsPredicate(List<String> keywords) {

@Override
public boolean test(Person person) {
return keywords.stream()
.anyMatch(keyword -> StringUtil.containsWordIgnoreCase(person.getName().fullName, keyword));

for (String aKeyword : keywords) {
String newKeyword = aKeyword.toLowerCase()
.replace('_', '.').replace("*", ".*");
newKeyword = ".*" + newKeyword + ".*";
if (person.getName().fullName.toLowerCase().matches(newKeyword)) {
return true;
}
}
return false;
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/systemtests/FindCommandSystemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public void find() {
assertCommandSuccess(command, expectedModel);
assertSelectedCardUnchanged();

/* Case: find person in address book, keyword is substring of name -> 0 persons found */
/* Case: find person in address book, keyword is substring of name -> 2 persons found */
command = FindCommand.COMMAND_WORD + " Mei";
ModelHelper.setFilteredList(expectedModel);
ModelHelper.setFilteredList(expectedModel, BENSON, DANIEL);
assertCommandSuccess(command, expectedModel);
assertSelectedCardUnchanged();

Expand Down

0 comments on commit 6f49254

Please sign in to comment.