Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[W5][T08-4]Phan Duy Nhat Tan #49

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the description for this feature? It is missing.

Format: `size`


== Clearing all entries : `clear`

Clears all entries from the address book. +
Expand Down
3 changes: 3 additions & 0 deletions src/seedu/addressbook/commands/HelpCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package seedu.addressbook.commands;


import javafx.css.Size;

/**
* Shows help instructions.
*/
Expand All @@ -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
);
Expand Down
21 changes: 21 additions & 0 deletions src/seedu/addressbook/commands/SizeCommand.java
Original file line number Diff line number Diff line change
@@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing header comment. All non-trivial methods should have java doc format header comments.

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.");
}
}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/data/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public UniquePersonList getAllPersons() {
return new UniquePersonList(allPersons);
}

/**
* Show the size of the address book
*/
public int size() {return allPersons.size();}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method call of size() should be put on a separate line.


@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
Expand Down
5 changes: 5 additions & 0 deletions src/seedu/addressbook/data/person/UniquePersonList.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/seedu/addressbook/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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();
Expand Down