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

Add a new command (show total number of persons in the address book) #463

Open
wants to merge 1 commit 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 src/seedu/addressbook/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public static String getMessageForPersonListShownSummary(List<? extends ReadOnly
return String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, personsDisplayed.size());
}

/* get message of total number */
public static String getMessageForTotalNumber(List<? extends ReadOnlyPerson> personsDisplayed) {
return String.format(Messages.MESSAGE_TOTAL, personsDisplayed.size());
}

/**
* Executes the command and returns the result.
*/
Expand Down
25 changes: 25 additions & 0 deletions src/seedu/addressbook/commands/TotalNumberCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package seedu.addressbook.commands;

import seedu.addressbook.data.person.ReadOnlyPerson;

import java.util.List;


/**
* Lists all persons in the address book to the user.
*/
public class TotalNumberCommand extends Command {

public static final String COMMAND_WORD = "Total";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Displays total number of all the people in this address book.\n"
+ "Example: " + COMMAND_WORD;


@Override
public CommandResult execute() {
List<ReadOnlyPerson> allPersons = addressBook.getAllPersons().immutableListView();
return new CommandResult(getMessageForTotalNumber(allPersons), null);
}
}
1 change: 1 addition & 0 deletions src/seedu/addressbook/common/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class Messages {
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_PROGRAM_LAUNCH_ARGS_USAGE = "Launch command format: " +
"java seedu.addressbook.Main [STORAGE_FILE_PATH]";
public static final String MESSAGE_TOTAL = "%1$d persons in the address book!";
public static final String MESSAGE_WELCOME = "Welcome to your Address Book!";
public static final String MESSAGE_USING_STORAGE_FILE = "Using storage file : %1$s";
}
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.TotalNumberCommand;
import seedu.addressbook.commands.ViewAllCommand;
import seedu.addressbook.commands.ViewCommand;
import seedu.addressbook.data.exception.IllegalValueException;
Expand Down Expand Up @@ -76,6 +77,9 @@ public Command parseCommand(String userInput) {
case AddCommand.COMMAND_WORD:
return prepareAdd(arguments);

case TotalNumberCommand.COMMAND_WORD:
return new TotalNumberCommand();

case DeleteCommand.COMMAND_WORD:
return prepareDelete(arguments);

Expand Down