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

FindCommand #3

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
Binary file added .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions doc/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ Format: `list`
Finds persons whose names contain any of the given keywords.<br>
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`<br>
Returns `John Doe` but not `john`
* `find Betsy Tim John`<br>
Returns Any person having names `Betsy`, `Tim`, or `John`
Returns Any person having names `Betsy`, `Tim`, or `John` ignoring the case

### Deleting a person : `delete`
Deletes the specified person from the address book. Irreversible.<br>
Expand Down
Binary file not shown.
3 changes: 3 additions & 0 deletions out/production/addressbook-level2/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: seedu.addressbook.Main

3 changes: 3 additions & 0 deletions src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: seedu.addressbook.Main

1 change: 1 addition & 0 deletions src/seedu/addressbook/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Main {
private TextUi ui;
private StorageFile storage;
private AddressBook addressBook;
private int lol;

/** The list of person shown to the user most recently. */
private List<? extends ReadOnlyPerson> lastShownList = Collections.emptyList();
Expand Down
4 changes: 2 additions & 2 deletions src/seedu/addressbook/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class FindCommand extends Command {
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-sensitive) and displays them as a list with index numbers.\n"
+ "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";

Expand Down Expand Up @@ -49,7 +49,7 @@ public CommandResult execute() {
private List<ReadOnlyPerson> getPersonsWithNameContainingAnyKeyword(Set<String> keywords) {
final List<ReadOnlyPerson> matchedPersons = new ArrayList<>();
for (ReadOnlyPerson person : addressBook.getAllPersons()) {
final Set<String> wordsInName = new HashSet<>(person.getName().getWordsInName());
final Set<String> wordsInName = new HashSet<>(person.getName().getWordsInNameIgnoreCase());
if (!Collections.disjoint(wordsInName, keywords)) {
matchedPersons.add(person);
}
Expand Down
5 changes: 5 additions & 0 deletions src/seedu/addressbook/data/person/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Name {
public static final String MESSAGE_NAME_CONSTRAINTS = "Person names should be spaces or alphabetic characters";
public static final String NAME_VALIDATION_REGEX = "[\\p{Alpha} ]+";
public final String fullName;
public final String fullNameInLowerCase;

/**
* Validates given name.
Expand All @@ -27,6 +28,7 @@ public Name(String name) throws IllegalValueException {
throw new IllegalValueException(MESSAGE_NAME_CONSTRAINTS);
}
this.fullName = trimmedName;
this.fullNameInLowerCase = trimmedName.toLowerCase();
}

/**
Expand All @@ -43,6 +45,9 @@ public List<String> getWordsInName() {
return Arrays.asList(fullName.split("\\s+"));
}

public List<String> getWordsInNameIgnoreCase() {
return Arrays.asList(fullNameInLowerCase.split("\\s+"));
}
@Override
public String toString() {
return fullName;
Expand Down
2 changes: 1 addition & 1 deletion src/seedu/addressbook/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private Command prepareFind(String args) {
}

// keywords delimited by whitespace
final String[] keywords = matcher.group("keywords").split("\\s+");
final String[] keywords = matcher.group("keywords").toLowerCase().split("\\s+");
final Set<String> keywordSet = new HashSet<>(Arrays.asList(keywords));
return new FindCommand(keywordSet);
}
Expand Down
7 changes: 4 additions & 3 deletions test/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
|| Example: delete 1
|| Clears address book permanently.
|| Example: clear
|| find: Finds all persons whose names contain any of the specified keywords (case-sensitive) and displays them as a list with index numbers.
|| find: Finds all persons whose names contain any of the specified keywords (case-insensitive) and displays them as a list with index numbers.
|| Parameters: KEYWORD [MORE_KEYWORDS]...
|| Example: find alice bob charlie
|| list: Displays all persons in the address book as a list with index numbers.
Expand Down Expand Up @@ -200,7 +200,7 @@
|| ===================================================
|| Enter command: || [Command entered: find]
|| Invalid command format!
|| find: Finds all persons whose names contain any of the specified keywords (case-sensitive) and displays them as a list with index numbers.
|| find: Finds all persons whose names contain any of the specified keywords (case-insensitive) and displays them as a list with index numbers.
|| Parameters: KEYWORD [MORE_KEYWORDS]...
|| Example: find alice bob charlie
|| ===================================================
Expand All @@ -213,8 +213,9 @@
|| 0 persons listed!
|| ===================================================
|| Enter command: || [Command entered: find betsy]
|| 1. Betsy Choo Tags: [secretive]
||
|| 0 persons listed!
|| 1 persons listed!
|| ===================================================
|| Enter command: || [Command entered: find Betsy]
|| 1. Betsy Choo Tags: [secretive]
Expand Down
9 changes: 8 additions & 1 deletion test/java/seedu/addressbook/commands/FindCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void execute() throws IllegalValueException {
assertFindCommandBehavior(new String[]{"Amy"}, Arrays.asList(td.amy));

//same word, different case: not matched
assertFindCommandBehavior(new String[]{"aMy"}, Collections.emptyList());
assertFindCommandBehavior(new String[]{"aMy"},Arrays.asList(td.amy));

//partial word: not matched
assertFindCommandBehavior(new String[]{"my"}, Collections.emptyList());
Expand All @@ -49,11 +49,18 @@ public void execute() throws IllegalValueException {
private void assertFindCommandBehavior(String[] keywords, List<ReadOnlyPerson> expectedPersonList) {
FindCommand command = createFindCommand(keywords);
CommandResult result = command.execute();
System.out.println(expectedPersonList.size());

assertEquals(Command.getMessageForPersonListShownSummary(expectedPersonList), result.feedbackToUser);
}

private FindCommand createFindCommand(String[] keywords) {
//final Set<String> keywordSet = new HashSet<>(Arrays.asList(keywords));

for(int i = 0;i<keywords.length;i++)
{
keywords[i]=keywords[i].toLowerCase();
}
final Set<String> keywordSet = new HashSet<>(Arrays.asList(keywords));
FindCommand command = new FindCommand(keywordSet);
command.setData(addressBook, Collections.emptyList());
Expand Down
12 changes: 12 additions & 0 deletions test/java/seedu/addressbook/common/UtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ public void elementsAreUnique() throws Exception {
assertNotUnique(null, "a", "b", null);
}

@Test
public void testIsAnyNullObject() throws Exception {

assertAreNull();
assertAreNull((Object) null);

}
private void assertAreNull(Object... objects) {

assertTrue(Utils.isAnyNull((Object) null));
}

private void assertAreUnique(Object... objects) {
assertTrue(Utils.elementsAreUnique(Arrays.asList(objects)));
}
Expand Down