From 60b1263c3dbf1e6d0ceb255089760f78c7b55a30 Mon Sep 17 00:00:00 2001 From: Melvin Date: Sat, 4 Feb 2017 02:58:15 +0800 Subject: [PATCH 1/4] Add DS_Store to gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 3a6578be..90b008a9 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ test/actual.txt test/localrun.bat test/data/ /bin/ + +# DS_Store +.DS_Store From 4560511f1f14f8a9154f39f474f441a9e42278dd Mon Sep 17 00:00:00 2001 From: Melvin Date: Sat, 4 Feb 2017 07:45:22 +0800 Subject: [PATCH 2/4] Allow find in non-case-sensitive manner --- src/seedu/addressbook/AddressBook.java | 18 +++++++++++++++++- test/expected.txt | 3 ++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/seedu/addressbook/AddressBook.java b/src/seedu/addressbook/AddressBook.java index 5a158b67..bd3a8cff 100644 --- a/src/seedu/addressbook/AddressBook.java +++ b/src/seedu/addressbook/AddressBook.java @@ -19,9 +19,11 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Optional; import java.util.Scanner; import java.util.Set; +import java.util.stream.Collectors; /* * NOTE : ============================================================= @@ -483,10 +485,12 @@ private static Set extractKeywordsFromFindPersonArgs(String findPersonCo * @return list of persons in full model with name containing some of the keywords */ private static ArrayList getPersonsWithNameContainingAnyKeyword(Collection keywords) { + List keywordsInLowercase = getStringCollectionInLowercase(keywords); final ArrayList matchedPersons = new ArrayList<>(); for (String[] person : getAllPersonsInAddressBook()) { final Set wordsInName = new HashSet<>(splitByWhitespace(getNameFromPerson(person))); - if (!Collections.disjoint(wordsInName, keywords)) { + List wordsInNameInLowercase = getStringCollectionInLowercase(wordsInName); + if (!Collections.disjoint(wordsInNameInLowercase, keywordsInLowercase)) { matchedPersons.add(person); } } @@ -546,6 +550,18 @@ private static int extractTargetIndexFromDeletePersonArgs(String rawArgs) { private static boolean isDisplayIndexValidForLastPersonListingView(int index) { return index >= DISPLAYED_INDEX_OFFSET && index < latestPersonListingView.size() + DISPLAYED_INDEX_OFFSET; } + + /** + * Convert all strings from a collection to lowercase. + * + * @param collection of string + * @return list of string in lowercase + */ + private static List getStringCollectionInLowercase(Collection collection) { + return collection.stream() + .map(String::toLowerCase) + .collect(Collectors.toList()); + } /** * Constructs a feedback message for a successful delete person command execution. diff --git a/test/expected.txt b/test/expected.txt index f18922ac..60bda0b2 100644 --- a/test/expected.txt +++ b/test/expected.txt @@ -184,8 +184,9 @@ || 0 persons found! || =================================================== || Enter command: || [Command entered: find betsy] +|| 1. Betsy Choo Phone Number: 222222 Email: benchoo@nus.edu.sg || -|| 0 persons found! +|| 1 persons found! || =================================================== || Enter command: || [Command entered: find Betsy] || 1. Betsy Choo Phone Number: 222222 Email: benchoo@nus.edu.sg From af4e8c6b255f12989bec5d9a7f111667691e8138 Mon Sep 17 00:00:00 2001 From: Melvin Date: Sat, 4 Feb 2017 12:48:52 +0800 Subject: [PATCH 3/4] Add command sort to display people in sorted order, by name --- src/seedu/addressbook/AddressBook.java | 21 ++++++ test/expected.txt | 89 +++++++++++++++++++++++++- test/input.txt | 19 +++++- 3 files changed, 125 insertions(+), 4 deletions(-) diff --git a/src/seedu/addressbook/AddressBook.java b/src/seedu/addressbook/AddressBook.java index bd3a8cff..4517218d 100644 --- a/src/seedu/addressbook/AddressBook.java +++ b/src/seedu/addressbook/AddressBook.java @@ -18,6 +18,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Optional; @@ -116,6 +117,10 @@ public class AddressBook { private static final String COMMAND_LIST_WORD = "list"; private static final String COMMAND_LIST_DESC = "Displays all persons as a list with index numbers."; private static final String COMMAND_LIST_EXAMPLE = COMMAND_LIST_WORD; + + private static final String COMMAND_SORT_WORD = "sort"; + private static final String COMMAND_SORT_DESC = "Displays all persons as a list with index numbers, sorted by name."; + private static final String COMMAND_SORT_EXAMPLE = COMMAND_SORT_WORD; private static final String COMMAND_DELETE_WORD = "delete"; private static final String COMMAND_DELETE_DESC = "Deletes a person identified by the index number used in " @@ -377,6 +382,8 @@ private static String executeCommand(String userInputString) { return executeFindPersons(commandArgs); case COMMAND_LIST_WORD: return executeListAllPersonsInAddressBook(); + case COMMAND_SORT_WORD: + return executeListAllPersonsInAddressBookSortedByName(); case COMMAND_DELETE_WORD: return executeDeletePerson(commandArgs); case COMMAND_CLEAR_WORD: @@ -594,6 +601,20 @@ private static String executeListAllPersonsInAddressBook() { showToUser(toBeDisplayed); return getMessageForPersonsDisplayedSummary(toBeDisplayed); } + + /** + * Displays all persons in the address book to the user; in sorted order by name. + * + * @return feedback display message for the operation result + */ + private static String executeListAllPersonsInAddressBookSortedByName() { + ArrayList allPersons = getAllPersonsInAddressBook(); + // Creates a copy of allPersons for sorting so ALL_PERSONS do not mutate. + ArrayList toBeDisplayed = new ArrayList(allPersons); + Collections.sort(toBeDisplayed, (person1, person2) -> person1[0].compareTo(person2[0])); + showToUser(toBeDisplayed); + return getMessageForPersonsDisplayedSummary(toBeDisplayed); + } /** * Requests to terminate the program. diff --git a/test/expected.txt b/test/expected.txt index 60bda0b2..29272c96 100644 --- a/test/expected.txt +++ b/test/expected.txt @@ -171,6 +171,77 @@ || || 5 persons found! || =================================================== +|| Enter command: || [Command entered: add John Doe p/98765432 e/johnd@gmail.com] +|| New person added: John Doe, Phone: 98765432, Email: johnd@gmail.com +|| =================================================== +|| Enter command: || [Command entered: sort] +|| 1. Adam Brown Phone Number: 111111 Email: adam@gmail.com +|| 2. Betsy Choo Phone Number: 222222 Email: benchoo@nus.edu.sg +|| 3. Charlie Dickson Phone Number: 333333 Email: charlie.d@nus.edu.sg +|| 4. Dickson Ee Phone Number: 444444 Email: dickson@nus.edu.sg +|| 5. Esther Potato Phone Number: 555555 Email: esther@notreal.potato +|| 6. John Doe Phone Number: 98765432 Email: johnd@gmail.com +|| +|| 6 persons found! +|| =================================================== +|| Enter command: || [Command entered: add Catie Parry p/12345678 e/catiep@hotmail.com] +|| New person added: Catie Parry, Phone: 12345678, Email: catiep@hotmail.com +|| =================================================== +|| Enter command: || [Command entered: sort] +|| 1. Adam Brown Phone Number: 111111 Email: adam@gmail.com +|| 2. Betsy Choo Phone Number: 222222 Email: benchoo@nus.edu.sg +|| 3. Catie Parry Phone Number: 12345678 Email: catiep@hotmail.com +|| 4. Charlie Dickson Phone Number: 333333 Email: charlie.d@nus.edu.sg +|| 5. Dickson Ee Phone Number: 444444 Email: dickson@nus.edu.sg +|| 6. Esther Potato Phone Number: 555555 Email: esther@notreal.potato +|| 7. John Doe Phone Number: 98765432 Email: johnd@gmail.com +|| +|| 7 persons found! +|| =================================================== +|| Enter command: || [Command entered: add Betty p/92837465 e/betty@gmail.com] +|| New person added: Betty, Phone: 92837465, Email: betty@gmail.com +|| =================================================== +|| Enter command: || [Command entered: sort] +|| 1. Adam Brown Phone Number: 111111 Email: adam@gmail.com +|| 2. Betsy Choo Phone Number: 222222 Email: benchoo@nus.edu.sg +|| 3. Betty Phone Number: 92837465 Email: betty@gmail.com +|| 4. Catie Parry Phone Number: 12345678 Email: catiep@hotmail.com +|| 5. Charlie Dickson Phone Number: 333333 Email: charlie.d@nus.edu.sg +|| 6. Dickson Ee Phone Number: 444444 Email: dickson@nus.edu.sg +|| 7. Esther Potato Phone Number: 555555 Email: esther@notreal.potato +|| 8. John Doe Phone Number: 98765432 Email: johnd@gmail.com +|| +|| 8 persons found! +|| =================================================== +|| Enter command: || [Command entered: add Zack Low p/99887766 e/lowz@nus.edu.sg] +|| New person added: Zack Low, Phone: 99887766, Email: lowz@nus.edu.sg +|| =================================================== +|| Enter command: || [Command entered: sort] +|| 1. Adam Brown Phone Number: 111111 Email: adam@gmail.com +|| 2. Betsy Choo Phone Number: 222222 Email: benchoo@nus.edu.sg +|| 3. Betty Phone Number: 92837465 Email: betty@gmail.com +|| 4. Catie Parry Phone Number: 12345678 Email: catiep@hotmail.com +|| 5. Charlie Dickson Phone Number: 333333 Email: charlie.d@nus.edu.sg +|| 6. Dickson Ee Phone Number: 444444 Email: dickson@nus.edu.sg +|| 7. Esther Potato Phone Number: 555555 Email: esther@notreal.potato +|| 8. John Doe Phone Number: 98765432 Email: johnd@gmail.com +|| 9. Zack Low Phone Number: 99887766 Email: lowz@nus.edu.sg +|| +|| 9 persons found! +|| =================================================== +|| Enter command: || [Command entered: list] +|| 1. Adam Brown Phone Number: 111111 Email: adam@gmail.com +|| 2. Betsy Choo Phone Number: 222222 Email: benchoo@nus.edu.sg +|| 3. Charlie Dickson Phone Number: 333333 Email: charlie.d@nus.edu.sg +|| 4. Dickson Ee Phone Number: 444444 Email: dickson@nus.edu.sg +|| 5. Esther Potato Phone Number: 555555 Email: esther@notreal.potato +|| 6. John Doe Phone Number: 98765432 Email: johnd@gmail.com +|| 7. Catie Parry Phone Number: 12345678 Email: catiep@hotmail.com +|| 8. Betty Phone Number: 92837465 Email: betty@gmail.com +|| 9. Zack Low Phone Number: 99887766 Email: lowz@nus.edu.sg +|| +|| 9 persons found! +|| =================================================== || Enter command: || [Command entered: find] || || 0 persons found! @@ -247,8 +318,12 @@ || 2. Betsy Choo Phone Number: 222222 Email: benchoo@nus.edu.sg || 3. Dickson Ee Phone Number: 444444 Email: dickson@nus.edu.sg || 4. Esther Potato Phone Number: 555555 Email: esther@notreal.potato +|| 5. John Doe Phone Number: 98765432 Email: johnd@gmail.com +|| 6. Catie Parry Phone Number: 12345678 Email: catiep@hotmail.com +|| 7. Betty Phone Number: 92837465 Email: betty@gmail.com +|| 8. Zack Low Phone Number: 99887766 Email: lowz@nus.edu.sg || -|| 4 persons found! +|| 8 persons found! || =================================================== || Enter command: || [Command entered: delete 4] || Deleted Person: Esther Potato Phone Number: 555555 Email: esther@notreal.potato @@ -257,8 +332,12 @@ || 1. Adam Brown Phone Number: 111111 Email: adam@gmail.com || 2. Betsy Choo Phone Number: 222222 Email: benchoo@nus.edu.sg || 3. Dickson Ee Phone Number: 444444 Email: dickson@nus.edu.sg +|| 4. John Doe Phone Number: 98765432 Email: johnd@gmail.com +|| 5. Catie Parry Phone Number: 12345678 Email: catiep@hotmail.com +|| 6. Betty Phone Number: 92837465 Email: betty@gmail.com +|| 7. Zack Low Phone Number: 99887766 Email: lowz@nus.edu.sg || -|| 3 persons found! +|| 7 persons found! || =================================================== || Enter command: || [Command entered: delete 1] || Deleted Person: Adam Brown Phone Number: 111111 Email: adam@gmail.com @@ -266,8 +345,12 @@ || Enter command: || [Command entered: list] || 1. Betsy Choo Phone Number: 222222 Email: benchoo@nus.edu.sg || 2. Dickson Ee Phone Number: 444444 Email: dickson@nus.edu.sg +|| 3. John Doe Phone Number: 98765432 Email: johnd@gmail.com +|| 4. Catie Parry Phone Number: 12345678 Email: catiep@hotmail.com +|| 5. Betty Phone Number: 92837465 Email: betty@gmail.com +|| 6. Zack Low Phone Number: 99887766 Email: lowz@nus.edu.sg || -|| 2 persons found! +|| 6 persons found! || =================================================== || Enter command: || [Command entered: clear] || Address book has been cleared! diff --git a/test/input.txt b/test/input.txt index 0b99df54..5c18ef3a 100644 --- a/test/input.txt +++ b/test/input.txt @@ -14,7 +14,7 @@ list ########################################################## -# test add person command, setup state for futuer tests +# test add person command, setup state for future tests ########################################################## # should catch invalid args format @@ -40,6 +40,23 @@ list add Esther Potato p/555555 e/esther@notreal.potato list + +########################################################## +# test sort person command +########################################################## + + # should add correctly + add John Doe p/98765432 e/johnd@gmail.com + sort + add Catie Parry p/12345678 e/catiep@hotmail.com + sort + add Betty p/92837465 e/betty@gmail.com + sort + add Zack Low p/99887766 e/lowz@nus.edu.sg + sort + + # list should still follow added order + list ########################################################## # test find persons command From 719907f590390b89e90f7be60867e785c5045372 Mon Sep 17 00:00:00 2001 From: Melvin Date: Sat, 4 Feb 2017 12:52:10 +0800 Subject: [PATCH 4/4] Add sort description to help --- src/seedu/addressbook/AddressBook.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/seedu/addressbook/AddressBook.java b/src/seedu/addressbook/AddressBook.java index 4517218d..05fa5954 100644 --- a/src/seedu/addressbook/AddressBook.java +++ b/src/seedu/addressbook/AddressBook.java @@ -18,7 +18,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Optional; @@ -1122,6 +1121,7 @@ private static String getUsageInfoForAllCommands() { return getUsageInfoForAddCommand() + LS + getUsageInfoForFindCommand() + LS + getUsageInfoForViewCommand() + LS + + getUsageInfoForSortCommand() + LS + getUsageInfoForDeleteCommand() + LS + getUsageInfoForClearCommand() + LS + getUsageInfoForExitCommand() + LS @@ -1160,6 +1160,11 @@ private static String getUsageInfoForViewCommand() { return String.format(MESSAGE_COMMAND_HELP, COMMAND_LIST_WORD, COMMAND_LIST_DESC) + LS + String.format(MESSAGE_COMMAND_HELP_EXAMPLE, COMMAND_LIST_EXAMPLE) + LS; } + + private static String getUsageInfoForSortCommand() { + return String.format(MESSAGE_COMMAND_HELP, COMMAND_SORT_WORD, COMMAND_SORT_DESC) + LS + + String.format(MESSAGE_COMMAND_HELP_EXAMPLE, COMMAND_SORT_EXAMPLE) + LS; + } /** Returns string for showing 'help' command usage instruction */ private static String getUsageInfoForHelpCommand() {