forked from nus-cs2103-AY2425S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from Rachael-Chan/find-tags
Update find to find tags
- Loading branch information
Showing
8 changed files
with
396 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,7 +130,7 @@ Examples: | |
|
||
Finds contacts whose names or/and phone numbers or/and address contain any of the given field keywords. | ||
|
||
Format: `find [n/NAMEKEYWORDS] [p/PHONEKEYWORDS] [a/ADDRESSKEYWORDS]` | ||
Format: `find [n/NAMEKEYWORDS] [p/PHONEKEYWORDS] [a/ADDRESSKEYWORDS] [t/TAGKEYWORDS]` | ||
|
||
**NOTE:** At least one field MUST be provided | ||
e.g. `find n/Hans` or `find p/82345678` or `find a/wall street` will work | ||
|
@@ -141,6 +141,8 @@ Format: `find [n/NAMEKEYWORDS] [p/PHONEKEYWORDS] [a/ADDRESSKEYWORDS]` | |
* Contacts matching at least one keyword will be returned (i.e. `OR` search). | ||
e.g. `Hans Bo` will return `Hans Gruber`, `Bo Yang` | ||
* If more than one fields are specified, contacts will be matched by multiple fields (i.e. `AND` search). | ||
* For multiple address or tag keywords, they are separated by "_". e.g `find t/friends_colleague_owes money` or `find a/wall street_michigan` | ||
* For multiple name or phone keywords, they are separated by " ". e.g `find n/andy ben carl` or `find p/98233211 81212899` | ||
|
||
<box type="tip" seamless> | ||
|
||
|
@@ -355,7 +357,7 @@ Action | Format, Examples | |
**Clear** | `clear` | ||
**Delete** | `delete INDEX`<br> e.g., `delete 3` | ||
**Edit** | `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [t/TAG]… [d/DATE_OF_LAST_VISIT] [ec/EMERGENCY_CONTACT] [r/REMARK]` <br> e.g.,`edit 2 n/James Lee e/[email protected]` | ||
**Find** | `find [n/NAMEKEYWORD] [p/PHONEKEYWORD] [a/ADDRESSKEYWORD]`<br> e.g., `find n/James Jake a/clementi street_woodlands` | ||
**Find** | `find [n/NAMEKEYWORD] [p/PHONEKEYWORD] [a/ADDRESSKEYWORD] [t/TAGKEYWORD]`<br> e.g., `find n/James Jake a/clementi street_woodlands` | ||
**List** | `list` | ||
**View** | `view INDEX`<br> e.g.,`view 1` | ||
**Help** | `help` | ||
|
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
46 changes: 46 additions & 0 deletions
46
src/main/java/seedu/address/model/person/TagContainsKeywordsPredicate.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,46 @@ | ||
package seedu.address.model.person; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
|
||
/** | ||
* Tests that a {@code Person}'s {@code Name} matches any of the keywords given. | ||
*/ | ||
public class TagContainsKeywordsPredicate implements Predicate<Person> { | ||
private final List<String> keywords; | ||
|
||
public TagContainsKeywordsPredicate(List<String> keywords) { | ||
this.keywords = keywords; | ||
} | ||
|
||
@Override | ||
public boolean test(Person person) { | ||
// Checks if the string i.e (tags) contains a keyword, allowing partial matching of tags via find command | ||
return keywords.stream() | ||
.anyMatch(keyword -> person.getTags().stream() | ||
.anyMatch(tag -> tag.tagName.toLowerCase().contains(keyword.toLowerCase()))); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof TagContainsKeywordsPredicate) && other != null) { | ||
return false; | ||
} | ||
|
||
TagContainsKeywordsPredicate otherTagContainsKeywordsPredicate = (TagContainsKeywordsPredicate) other; | ||
return keywords.equals(otherTagContainsKeywordsPredicate != null | ||
? otherTagContainsKeywordsPredicate.keywords : null); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this).add("keywords", keywords).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
Oops, something went wrong.