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.7][F11-1]Wu Jiacheng #440

Open
wants to merge 9 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 @@ -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. +
Expand Down
1 change: 1 addition & 0 deletions src/seedu/addressbook/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions src/seedu/addressbook/commands/TotalCommand.java
Original file line number Diff line number Diff line change
@@ -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;
Copy link

Choose a reason for hiding this comment

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

Nice! I did not think of explaining what the total command does in my own implementation. Oversight on my part :(. I totally assumed it would be similar to the clear and/or list command(s)


public static final String MESSAGE_TOTAL_IN_ADDRESSBOOK = "There is/are %1$s person(s) in the address book";
Copy link

Choose a reason for hiding this comment

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

I liked your usage of %1$s in the MESSAGE_TOTAL_IN_ADDRESSBOOK String constant :)


@Override
public CommandResult execute() {
return new CommandResult(String.format(MESSAGE_TOTAL_IN_ADDRESSBOOK, addressBook.getTotal()));
}

}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/data/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }

Copy link

Choose a reason for hiding this comment

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

Nice naming of getter method as getTotal(). For me, I called it getSize() both in this file and src/seedu/addressbook/data/person/UniquePersonList.java :(

/**
* Clears all persons and tags from the address book.
*/
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 {
}
}

/**
* Gets total number of persons in list.
*/
public int getSize() { return internalList.size(); }

Choose a reason for hiding this comment

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

Formatting issue, please check coding standard


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

Expand Down
17 changes: 17 additions & 0 deletions test/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) [email protected] 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!
|| ===================================================
Expand Down
12 changes: 12 additions & 0 deletions test/input.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
##########################################################
Expand Down