diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index 4abb17e3e..1736142cd 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -111,6 +111,11 @@ Deletes the 2nd person in the address book. `delete 1` + Deletes the 1st person in the results of the `find` command. +== Display total number of persons in address book : `total` + +Shows the total number of persons in the address book. + +Format: `total` + == View non-private details of a person : `view` Displays the non-private details of the specified person. + diff --git a/src/seedu/addressbook/commands/HelpCommand.java b/src/seedu/addressbook/commands/HelpCommand.java index 9be217d89..761be3c77 100644 --- a/src/seedu/addressbook/commands/HelpCommand.java +++ b/src/seedu/addressbook/commands/HelpCommand.java @@ -16,6 +16,7 @@ public CommandResult execute() { return new CommandResult( AddCommand.MESSAGE_USAGE + "\n" + DeleteCommand.MESSAGE_USAGE + + "\n" + TotalCommand.MESSAGE_USAGE + "\n" + ClearCommand.MESSAGE_USAGE + "\n" + FindCommand.MESSAGE_USAGE + "\n" + ListCommand.MESSAGE_USAGE diff --git a/src/seedu/addressbook/commands/TotalCommand.java b/src/seedu/addressbook/commands/TotalCommand.java new file mode 100644 index 000000000..bae800c1b --- /dev/null +++ b/src/seedu/addressbook/commands/TotalCommand.java @@ -0,0 +1,21 @@ +package seedu.addressbook.commands; + +/** + * display the total number of persons stored in the address book + */ +public class TotalCommand extends Command { + + public static final String COMMAND_WORD = "total"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": display the total number of persons stored in the address book.\n" + + "Example: " + COMMAND_WORD; + + public static final String MESSAGE_TOTAL_IN_ADDRESSBOOK = "There is/are %1$s person(s) in the address book"; + + @Override + public CommandResult execute() { + return new CommandResult(String.format(MESSAGE_TOTAL_IN_ADDRESSBOOK, addressBook.getTotal())); + } + +} diff --git a/src/seedu/addressbook/data/AddressBook.java b/src/seedu/addressbook/data/AddressBook.java index 537d35c89..c876cc0c9 100644 --- a/src/seedu/addressbook/data/AddressBook.java +++ b/src/seedu/addressbook/data/AddressBook.java @@ -54,6 +54,11 @@ public void removePerson(ReadOnlyPerson toRemove) throws PersonNotFoundException allPersons.remove(toRemove); } + /** + * Gets total number of persons in list. + */ + public int getTotal() { return allPersons.getSize(); } + /** * Clears all persons and tags from the address book. */ diff --git a/src/seedu/addressbook/data/person/UniquePersonList.java b/src/seedu/addressbook/data/person/UniquePersonList.java index d7acd8b4a..a0a03e185 100644 --- a/src/seedu/addressbook/data/person/UniquePersonList.java +++ b/src/seedu/addressbook/data/person/UniquePersonList.java @@ -122,6 +122,11 @@ public void remove(ReadOnlyPerson toRemove) throws PersonNotFoundException { } } + /** + * Gets total number of persons in list. + */ + public int getSize() { return internalList.size(); } + /** * Clears all persons in list. */ diff --git a/src/seedu/addressbook/parser/Parser.java b/src/seedu/addressbook/parser/Parser.java index abddb3f45..f9097fc22 100644 --- a/src/seedu/addressbook/parser/Parser.java +++ b/src/seedu/addressbook/parser/Parser.java @@ -20,6 +20,7 @@ import seedu.addressbook.commands.HelpCommand; import seedu.addressbook.commands.IncorrectCommand; import seedu.addressbook.commands.ListCommand; +import seedu.addressbook.commands.TotalCommand; import seedu.addressbook.commands.ViewAllCommand; import seedu.addressbook.commands.ViewCommand; import seedu.addressbook.data.exception.IllegalValueException; @@ -79,6 +80,9 @@ public Command parseCommand(String userInput) { case DeleteCommand.COMMAND_WORD: return prepareDelete(arguments); + case TotalCommand.COMMAND_WORD: + return new TotalCommand(); + case ClearCommand.COMMAND_WORD: return new ClearCommand(); diff --git a/test/expected.txt b/test/expected.txt index 56fe5fcac..96df94da3 100644 --- a/test/expected.txt +++ b/test/expected.txt @@ -12,6 +12,8 @@ || delete: Deletes the person identified by the index number used in the last person listing. || Parameters: INDEX || Example: delete 1 +|| total: display the total number of persons stored in the address book. +|| Example: total || 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. @@ -290,6 +292,21 @@ || || 2 persons listed! || =================================================== +|| Enter command: || [Command entered: list] +|| 1. Betsy Choo Tags: [secretive] +|| 2. Dickson Ee Phone: 444444 Address: 444, delta street Tags: [friends] +|| +|| 2 persons listed! +|| =================================================== +|| Enter command: || [Command entered: total] +|| There is/are 2 person(s) in the address book +|| =================================================== +|| Enter command: || [Command entered: delete 1] +|| Deleted Person: Betsy Choo Phone: (private) 222222 Email: (private) benchoo@nus.edu.sg Address: (private) 222, beta street Tags: [secretive] +|| =================================================== +|| Enter command: || [Command entered: total] +|| There is/are 1 person(s) in the address book +|| =================================================== || Enter command: || [Command entered: clear] || Address book has been cleared! || =================================================== diff --git a/test/input.txt b/test/input.txt index eb8df81f8..7cb5d34d2 100644 --- a/test/input.txt +++ b/test/input.txt @@ -140,6 +140,18 @@ delete 1 list +########################################################## + # test total command +########################################################## + + # list all persons in address book and compare + list + total + + # add 1 person and test again + delete 1 + total + ########################################################## # test clear command ##########################################################