diff --git a/doc/UserGuide.md b/doc/UserGuide.md index d03dfce73..4dae15c3f 100644 --- a/doc/UserGuide.md +++ b/doc/UserGuide.md @@ -38,6 +38,10 @@ Examples: Shows a list of all persons in the address book.
Format: `list` +## Listing all persons : `sort` +Shows a sorted list of all persons in the address book.
+Format: `sort` + ## Finding all persons containing any keyword in their name: `find` Finds persons whose names contain any of the given keywords.
Format: `find KEYWORD [MORE_KEYWORDS]` diff --git a/src/seedu/addressbook/commands/Command.java b/src/seedu/addressbook/commands/Command.java index a54cbcb5b..14bef909c 100644 --- a/src/seedu/addressbook/commands/Command.java +++ b/src/seedu/addressbook/commands/Command.java @@ -36,6 +36,16 @@ public static String getMessageForPersonListShownSummary(List personsDisplayed) { + return String.format(Messages.MESSAGE_PERSONS_SORTED_OVERVIEW, personsDisplayed.size()); + } + /** * Executes the command and returns the result. */ diff --git a/src/seedu/addressbook/commands/SortCommand.java b/src/seedu/addressbook/commands/SortCommand.java index e06cf9cf3..90291c718 100644 --- a/src/seedu/addressbook/commands/SortCommand.java +++ b/src/seedu/addressbook/commands/SortCommand.java @@ -23,7 +23,7 @@ public CommandResult execute() { List SortAllPersons = addressBook.getAllPersons().SortAllPersons(); - return new CommandResult(getMessageForPersonListShownSummary(SortAllPersons), SortAllPersons); + return new CommandResult(getMessageForPersonSortShownSummary(SortAllPersons), SortAllPersons); } } diff --git a/src/seedu/addressbook/parser/Parser.java b/src/seedu/addressbook/parser/Parser.java index c4ed061c8..9913be21c 100644 --- a/src/seedu/addressbook/parser/Parser.java +++ b/src/seedu/addressbook/parser/Parser.java @@ -14,19 +14,18 @@ */ public class Parser { - public static final Pattern PERSON_INDEX_ARGS_FORMAT = Pattern.compile("(?.+)"); + private static final Pattern PERSON_INDEX_ARGS_FORMAT = Pattern.compile("(?.+)"); - public static final Pattern KEYWORDS_ARGS_FORMAT = + private static final Pattern KEYWORDS_ARGS_FORMAT = Pattern.compile("(?\\S+(?:\\s+\\S+)*)"); // one or more keywords separated by whitespace - public static final Pattern PERSON_DATA_ARGS_FORMAT = // '/' forward slashes are reserved for delimiter prefixes + private static final Pattern PERSON_DATA_ARGS_FORMAT = // '/' forward slashes are reserved for delimiter prefixes Pattern.compile("(?[^/]+)" + " (?p?)p/(?[^/]+)" + " (?p?)e/(?[^/]+)" + " (?p?)a/(?
[^/]+)" + "(?(?: t/[^/]+)*)"); // variable number of tags - /** * Signals that the user input could not be parsed. */ diff --git a/src/seedu/addressbook/ui/Gui.java b/src/seedu/addressbook/ui/Gui.java index ed21989a4..4cb843f90 100644 --- a/src/seedu/addressbook/ui/Gui.java +++ b/src/seedu/addressbook/ui/Gui.java @@ -5,8 +5,6 @@ import javafx.stage.Stage; import seedu.addressbook.logic.Logic; import seedu.addressbook.Main; - -import java.io.File; import java.io.IOException; /** @@ -17,8 +15,8 @@ public class Gui { /** Offset required to convert between 1-indexing and 0-indexing. */ public static final int DISPLAYED_INDEX_OFFSET = 1; - public static final int INITIAL_WINDOW_WIDTH = 800; - public static final int INITIAL_WINDOW_HEIGHT = 600; + private static final int INITIAL_WINDOW_WIDTH = 800; + private static final int INITIAL_WINDOW_HEIGHT = 600; private final Logic logic; private MainWindow mainWindow; diff --git a/test/java/seedu/addressbook/logic/LogicTest.java b/test/java/seedu/addressbook/logic/LogicTest.java index 7efa921ca..914b35cbe 100644 --- a/test/java/seedu/addressbook/logic/LogicTest.java +++ b/test/java/seedu/addressbook/logic/LogicTest.java @@ -116,6 +116,7 @@ public void execute_clear() throws Exception { addressBook.addPerson(helper.generatePerson(1, true)); addressBook.addPerson(helper.generatePerson(2, true)); addressBook.addPerson(helper.generatePerson(3, true)); + addressBook.addPerson(helper.generatePerson(4, true)); assertCommandBehavior("clear", ClearCommand.MESSAGE_SUCCESS, AddressBook.empty(), false, Collections.emptyList()); } @@ -201,6 +202,23 @@ public void execute_list_showsAllPersons() throws Exception { expectedList); } + @Test + public void execute_sort_showsAllPersons() throws Exception { + // prepare expectations + TestDataHelper helper = new TestDataHelper(); + AddressBook expectedAB = helper.generateAddressBook(false, true); + List expectedList = expectedAB.getAllPersons().SortAllPersons(); + + // prepare address book state + helper.addToAddressBook(addressBook, false, true); + + assertCommandBehavior("sort", + Command.getMessageForPersonSortShownSummary(expectedList), + expectedAB, + true, + expectedList); + } + @Test public void execute_view_invalidArgsFormat() throws Exception { String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewCommand.MESSAGE_USAGE); @@ -418,16 +436,16 @@ public void execute_find_onlyMatchesFullWordsInNames() throws Exception { } @Test - public void execute_find_isCaseSensitive() throws Exception { + public void execute_find_isCaseInSensitive() throws Exception { TestDataHelper helper = new TestDataHelper(); Person pTarget1 = helper.generatePersonWithName("bla bla KEY bla"); Person pTarget2 = helper.generatePersonWithName("bla KEY bla bceofeia"); - Person p1 = helper.generatePersonWithName("key key"); + Person p1 = helper.generatePersonWithName("Kay KAAY"); Person p2 = helper.generatePersonWithName("KEy sduauo"); List fourPersons = helper.generatePersonList(p1, pTarget1, p2, pTarget2); AddressBook expectedAB = helper.generateAddressBook(fourPersons); - List expectedList = helper.generatePersonList(pTarget1, pTarget2); + List expectedList = helper.generatePersonList(pTarget1, p2, pTarget2); helper.addToAddressBook(addressBook, fourPersons); assertCommandBehavior("find KEY", @@ -447,7 +465,7 @@ public void execute_find_matchesIfAnyKeywordPresent() throws Exception { List fourPersons = helper.generatePersonList(p1, pTarget1, p2, pTarget2); AddressBook expectedAB = helper.generateAddressBook(fourPersons); - List expectedList = helper.generatePersonList(pTarget1, pTarget2); + List expectedList = helper.generatePersonList(p1, pTarget1, p2, pTarget2); helper.addToAddressBook(addressBook, fourPersons); assertCommandBehavior("find KEY rAnDoM", diff --git a/test/java/seedu/addressbook/parser/ParserTest.java b/test/java/seedu/addressbook/parser/ParserTest.java index f01be613c..24264c3e5 100644 --- a/test/java/seedu/addressbook/parser/ParserTest.java +++ b/test/java/seedu/addressbook/parser/ParserTest.java @@ -59,6 +59,12 @@ public void listCommand_parsedCorrectly() { parseAndAssertCommandType(input, ListCommand.class); } + @Test + public void sortCommand_parsedCorrectly(){ + final String input = "sort"; + parseAndAssertCommandType(input, SortCommand.class); + } + @Test public void exitCommand_parsedCorrectly() { final String input = "exit";