Skip to content
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

[W3.3][F09-A2]Shi Tian #16

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ Format: `list`
> Finds persons that match given keywords

Format: `find KEYWORD [MORE_KEYWORDS]`
> The search is case sensitive, the order of the keywords does not matter, only the name is searched,
> The search is case insensitive, the order of the keywords does not matter, only the name is searched,
and persons matching at least one keyword will be returned (i.e. `OR` search).

Examples:
* `find John`
> Returns `John Doe` but not `john`
* `find John` or `find john`
> Returns `John Doe`

* `find Betsy Tim John`
> Returns Any person having names `Betsy`, `Tim`, or `John`
Expand Down Expand Up @@ -468,4 +468,4 @@ The full list of contributors for se-edu can be found [here](https://se-edu.gith
* If you would like to contact us, refer to [our website](https://se-edu.github.io/#contact).

[coding-standard]: https://github.com/oss-generic/process/blob/master/codingStandards/CodingStandard-Java.md "Java Coding Standard"
[code-quality]: https://se-edu.github.io/se-book/codeQuality/ "Code Quality Best Practices"
[code-quality]: https://se-edu.github.io/se-book/codeQuality/ "Code Quality Best Practices"
14 changes: 11 additions & 3 deletions src/seedu/addressbook/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public class AddressBook {

private static final String COMMAND_FIND_WORD = "find";
private static final String COMMAND_FIND_DESC = "Finds all persons whose names contain any of the specified "
+ "keywords (case-sensitive) and displays them as a list with index numbers.";
+ "keywords (case-insensitive) and displays them as a list with index numbers.";
private static final String COMMAND_FIND_PARAMETERS = "KEYWORD [MORE_KEYWORDS]";
private static final String COMMAND_FIND_EXAMPLE = COMMAND_FIND_WORD + " alice bob charlie";

Expand Down Expand Up @@ -485,14 +485,22 @@ private static Set<String> extractKeywordsFromFindPersonArgs(String findPersonCo
private static ArrayList<String[]> getPersonsWithNameContainingAnyKeyword(Collection<String> keywords) {
final ArrayList<String[]> matchedPersons = new ArrayList<>();
for (String[] person : getAllPersonsInAddressBook()) {
final Set<String> wordsInName = new HashSet<>(splitByWhitespace(getNameFromPerson(person)));
if (!Collections.disjoint(wordsInName, keywords)) {
final Set<String> wordsInName = new HashSet<>(splitByWhitespace(getNameFromPerson(person).toLowerCase()));
if (!Collections.disjoint(wordsInName, toLowerCaseKeywords(keywords))) {
matchedPersons.add(person);
}
}
return matchedPersons;
}

private static Collection<String> toLowerCaseKeywords(Collection<String> keywords) {
ArrayList<String> lowerCaseKeywords = new ArrayList<String>();
for (String keyword : keywords) {
lowerCaseKeywords.add(keyword.toLowerCase());
}
return lowerCaseKeywords;
}

/**
* Deletes person identified using last displayed index.
*
Expand Down
3 changes: 2 additions & 1 deletion test/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@
|| 0 persons found!
|| ===================================================
|| Enter command: || [Command entered: find betsy]
|| 1. Betsy Choo Phone Number: 222222 Email: [email protected]
||
|| 0 persons found!
|| 1 persons found!
|| ===================================================
|| Enter command: || [Command entered: find Betsy]
|| 1. Betsy Choo Phone Number: 222222 Email: [email protected]
Expand Down
4 changes: 2 additions & 2 deletions test/input.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
find bet
# does not match if none have keyword
find 23912039120
# matching should be case-sensitive
# matching should no longer be case-sensitive
find betsy

# find unique keyword
Expand Down Expand Up @@ -105,4 +105,4 @@

# exits properly
exit
list
list