From 44e3782e8df787cba136b2c821070609debb12c6 Mon Sep 17 00:00:00 2001 From: Davindran Sukumaran Date: Wed, 12 Sep 2018 22:31:16 +0800 Subject: [PATCH] Enhancement: 'find' function not case sensitive --- docs/UserGuide.adoc | 16 +++++++++++++--- src/seedu/addressbook/commands/FindCommand.java | 3 ++- src/seedu/addressbook/data/person/Name.java | 2 +- src/seedu/addressbook/parser/Parser.java | 2 +- test/expected.txt | 9 +++++---- test/input.txt | 2 +- 6 files changed, 23 insertions(+), 11 deletions(-) diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index 4abb17e3e..9b0011d8c 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -79,17 +79,17 @@ Format: `find KEYWORD [MORE_KEYWORDS]` [NOTE] ==== -The search is case sensitive, the order of the keywords does not matter, only the name is searched, +The search is NOT case sensitive, 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`. +Returns `John Doe` or `john`. * `find Betsy Tim John` + -Returns Any person having names `Betsy`, `Tim`, or `John`. +Returns Any person having names `Betsy`, `betsy`, `Tim`, `tim`, `John` or `john`. == Deleting a person : `delete` @@ -176,6 +176,15 @@ Example: * `java seedu.addressbook.Main mydata.txt` +== ENHANCEMENT +The 'find' function is not case sensitive! + +Examples: + +* `find john` + +Returns `John Doe` or `john doe`. + + [NOTE] ==== The file name must end in `.txt` for it to be acceptable to the program. @@ -183,3 +192,4 @@ The file name must end in `.txt` for it to be acceptable to the program. When running the program inside IntelliJ, you can set command line parameters before running the program. ==== + diff --git a/src/seedu/addressbook/commands/FindCommand.java b/src/seedu/addressbook/commands/FindCommand.java index 7fe2c52c3..7d4446365 100644 --- a/src/seedu/addressbook/commands/FindCommand.java +++ b/src/seedu/addressbook/commands/FindCommand.java @@ -11,13 +11,14 @@ /** * Finds and lists all persons in address book whose name contains any of the argument keywords. * Keyword matching is case sensitive. + * ENHANCEMENT: keyword matching is NOT case sensitive. */ 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 (non case-sensitive) and displays them as a list with index numbers.\n" + "Parameters: KEYWORD [MORE_KEYWORDS]...\n" + "Example: " + COMMAND_WORD + " alice bob charlie"; diff --git a/src/seedu/addressbook/data/person/Name.java b/src/seedu/addressbook/data/person/Name.java index d1d271414..a131f5e6b 100644 --- a/src/seedu/addressbook/data/person/Name.java +++ b/src/seedu/addressbook/data/person/Name.java @@ -40,7 +40,7 @@ public static boolean isValidName(String test) { * Retrieves a listing of every word in the name, in order. */ public List getWordsInName() { - return Arrays.asList(fullName.split("\\s+")); + return Arrays.asList(fullName.toUpperCase().split("\\s+")); } @Override diff --git a/src/seedu/addressbook/parser/Parser.java b/src/seedu/addressbook/parser/Parser.java index 25c412f6b..d61008060 100644 --- a/src/seedu/addressbook/parser/Parser.java +++ b/src/seedu/addressbook/parser/Parser.java @@ -238,7 +238,7 @@ private int parseArgsAsDisplayedIndex(String args) throws ParseException, Number * @return the prepared command */ private Command prepareFind(String args) { - final Matcher matcher = KEYWORDS_ARGS_FORMAT.matcher(args.trim()); + final Matcher matcher = KEYWORDS_ARGS_FORMAT.matcher(args.toUpperCase().trim()); if (!matcher.matches()) { return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE)); diff --git a/test/expected.txt b/test/expected.txt index 56fe5fcac..3352174f9 100644 --- a/test/expected.txt +++ b/test/expected.txt @@ -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 (NON case-sensitive) 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. @@ -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 (NON case-sensitive) and displays them as a list with index numbers. || Parameters: KEYWORD [MORE_KEYWORDS]... || Example: find alice bob charlie || =================================================== @@ -213,8 +213,9 @@ || 0 persons listed! || =================================================== || Enter command: || [Command entered: find betsy] -|| -|| 0 persons listed! +|| 1. Betsy Choo Tags: [secretive] +|| +|| 1 persons listed! || =================================================== || Enter command: || [Command entered: find Betsy] || 1. Betsy Choo Tags: [secretive] diff --git a/test/input.txt b/test/input.txt index eb8df81f8..c772366c5 100644 --- a/test/input.txt +++ b/test/input.txt @@ -96,7 +96,7 @@ find bet # does not match if none have keyword find 23912039120 - # matching should be case-sensitive + # matching should not be case-sensitive find betsy # find unique keyword