diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index 4abb17e3e..96cf40d1b 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -151,6 +151,11 @@ Views all details of the 2nd person in the address book. `viewall 1` + Views all details of the 1st person in the results of the `find` command. +== Show the number of person in the address book : `size` + +Format: `size` + + == Clearing all entries : `clear` Clears all entries from the address book. + diff --git a/src/seedu/addressbook/commands/HelpCommand.java b/src/seedu/addressbook/commands/HelpCommand.java index 9be217d89..521b4f6a2 100644 --- a/src/seedu/addressbook/commands/HelpCommand.java +++ b/src/seedu/addressbook/commands/HelpCommand.java @@ -1,6 +1,8 @@ package seedu.addressbook.commands; +import javafx.css.Size; + /** * Shows help instructions. */ @@ -21,6 +23,7 @@ public CommandResult execute() { + "\n" + ListCommand.MESSAGE_USAGE + "\n" + ViewCommand.MESSAGE_USAGE + "\n" + ViewAllCommand.MESSAGE_USAGE + + "\n" + SizeCommand.MESSAGE_USAGE + "\n" + HelpCommand.MESSAGE_USAGE + "\n" + ExitCommand.MESSAGE_USAGE ); diff --git a/src/seedu/addressbook/commands/SizeCommand.java b/src/seedu/addressbook/commands/SizeCommand.java new file mode 100644 index 000000000..faf18ba75 --- /dev/null +++ b/src/seedu/addressbook/commands/SizeCommand.java @@ -0,0 +1,21 @@ +package seedu.addressbook.commands; + +/** + * Shows help instructions. + */ +public class SizeCommand extends Command { + + public static final String COMMAND_WORD = "size"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Show the size of the address book.\n" + + "Example: " + COMMAND_WORD; + + @Override + public CommandResult execute() { + if (addressBook.size() == 0) + return new CommandResult("There is no person in the address book."); + else if (addressBook.size() == 1) + return new CommandResult("There is one person in the address book."); + else return new CommandResult("There are " + addressBook.size() + " persons in the address book."); + } +} \ No newline at end of file diff --git a/src/seedu/addressbook/data/AddressBook.java b/src/seedu/addressbook/data/AddressBook.java index 537d35c89..9ea020ee1 100644 --- a/src/seedu/addressbook/data/AddressBook.java +++ b/src/seedu/addressbook/data/AddressBook.java @@ -68,6 +68,11 @@ public UniquePersonList getAllPersons() { return new UniquePersonList(allPersons); } + /** + * Show the size of the address book + */ + public int size() {return allPersons.size();} + @Override public boolean equals(Object other) { return other == this // short circuit if same object diff --git a/src/seedu/addressbook/data/person/UniquePersonList.java b/src/seedu/addressbook/data/person/UniquePersonList.java index d7acd8b4a..57a0b3bef 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 { } } + /** + * Return the size of the list + */ + public int size() {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..fc6f0d355 100644 --- a/src/seedu/addressbook/parser/Parser.java +++ b/src/seedu/addressbook/parser/Parser.java @@ -22,6 +22,7 @@ import seedu.addressbook.commands.ListCommand; import seedu.addressbook.commands.ViewAllCommand; import seedu.addressbook.commands.ViewCommand; +import seedu.addressbook.commands.SizeCommand; import seedu.addressbook.data.exception.IllegalValueException; /** @@ -97,6 +98,9 @@ public Command parseCommand(String userInput) { case ExitCommand.COMMAND_WORD: return new ExitCommand(); + case SizeCommand.COMMAND_WORD: + return new SizeCommand(); + case HelpCommand.COMMAND_WORD: // Fallthrough default: return new HelpCommand();