From 9dc5a28a4cb312ed08a48db70e18d2f0ae003a81 Mon Sep 17 00:00:00 2001 From: tantantan277 Date: Mon, 11 Feb 2019 13:36:39 +0800 Subject: [PATCH 1/4] Add size command --- .../addressbook/commands/HelpCommand.java | 3 +++ .../addressbook/commands/SizeCommand.java | 21 +++++++++++++++++++ src/seedu/addressbook/data/AddressBook.java | 5 +++++ .../data/person/UniquePersonList.java | 5 +++++ src/seedu/addressbook/parser/Parser.java | 4 ++++ 5 files changed, 38 insertions(+) create mode 100644 src/seedu/addressbook/commands/SizeCommand.java 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(); From ec9bfbcf5049af0654362b56479a65718ce56284 Mon Sep 17 00:00:00 2001 From: tantantan277 Date: Mon, 11 Feb 2019 13:37:21 +0800 Subject: [PATCH 2/4] Revert "Add size command" This reverts commit 9dc5a28a4cb312ed08a48db70e18d2f0ae003a81. --- .../addressbook/commands/HelpCommand.java | 3 --- .../addressbook/commands/SizeCommand.java | 21 ------------------- src/seedu/addressbook/data/AddressBook.java | 5 ----- .../data/person/UniquePersonList.java | 5 ----- src/seedu/addressbook/parser/Parser.java | 4 ---- 5 files changed, 38 deletions(-) delete mode 100644 src/seedu/addressbook/commands/SizeCommand.java diff --git a/src/seedu/addressbook/commands/HelpCommand.java b/src/seedu/addressbook/commands/HelpCommand.java index 521b4f6a2..9be217d89 100644 --- a/src/seedu/addressbook/commands/HelpCommand.java +++ b/src/seedu/addressbook/commands/HelpCommand.java @@ -1,8 +1,6 @@ package seedu.addressbook.commands; -import javafx.css.Size; - /** * Shows help instructions. */ @@ -23,7 +21,6 @@ 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 deleted file mode 100644 index faf18ba75..000000000 --- a/src/seedu/addressbook/commands/SizeCommand.java +++ /dev/null @@ -1,21 +0,0 @@ -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 9ea020ee1..537d35c89 100644 --- a/src/seedu/addressbook/data/AddressBook.java +++ b/src/seedu/addressbook/data/AddressBook.java @@ -68,11 +68,6 @@ 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 57a0b3bef..d7acd8b4a 100644 --- a/src/seedu/addressbook/data/person/UniquePersonList.java +++ b/src/seedu/addressbook/data/person/UniquePersonList.java @@ -122,11 +122,6 @@ 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 fc6f0d355..abddb3f45 100644 --- a/src/seedu/addressbook/parser/Parser.java +++ b/src/seedu/addressbook/parser/Parser.java @@ -22,7 +22,6 @@ 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; /** @@ -98,9 +97,6 @@ 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(); From 33a57935899ff2d988fc59b9245f69dbbb50ccca Mon Sep 17 00:00:00 2001 From: tantantan277 Date: Mon, 11 Feb 2019 13:54:36 +0800 Subject: [PATCH 3/4] Revert "Revert "Add size command"" This reverts commit ec9bfbcf5049af0654362b56479a65718ce56284. --- .../addressbook/commands/HelpCommand.java | 3 +++ .../addressbook/commands/SizeCommand.java | 21 +++++++++++++++++++ src/seedu/addressbook/data/AddressBook.java | 5 +++++ .../data/person/UniquePersonList.java | 5 +++++ src/seedu/addressbook/parser/Parser.java | 4 ++++ 5 files changed, 38 insertions(+) create mode 100644 src/seedu/addressbook/commands/SizeCommand.java 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(); From 38e2892459f8e7a250c5e75cc6431a7b189f79e5 Mon Sep 17 00:00:00 2001 From: tantantan277 Date: Mon, 11 Feb 2019 13:58:53 +0800 Subject: [PATCH 4/4] Update user guide --- docs/UserGuide.adoc | 5 +++++ 1 file changed, 5 insertions(+) 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. +