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][F10-2]Lim Fong Yuan #454

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
9 changes: 4 additions & 5 deletions src/seedu/addressbook/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ public class AddCommand extends Command {

public static final String COMMAND_WORD = "add";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
+ "Contact details can be marked private by prepending 'p' to the prefix.\n"
+ "Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...\n"
+ "Example: " + COMMAND_WORD
+ " John Doe p/98765432 e/[email protected] a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney";
public static final String MESSAGE_USAGE = Command.getMessageUsage(COMMAND_WORD,
"Adds a person to the address book. Contact details can be marked private by prepending 'p' to the prefix.",
"NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...",
"John Doe p/98765432 e/[email protected] a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney");

public static final String MESSAGE_SUCCESS = "New person added: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book";
Expand Down
4 changes: 2 additions & 2 deletions src/seedu/addressbook/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
public class ClearCommand extends Command {

public static final String COMMAND_WORD = "clear";
public static final String MESSAGE_USAGE = "Clears address book permanently.\n"
+ "Example: " + COMMAND_WORD;
public static final String MESSAGE_USAGE = Command.getMessageUsage(COMMAND_WORD,
"Clears address book permanently.");

public static final String MESSAGE_SUCCESS = "Address book has been cleared!";

Expand Down
32 changes: 32 additions & 0 deletions src/seedu/addressbook/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,38 @@ public Command(int targetIndex) {
protected Command() {
}

/**
* Generates the MESSAGE_USAGE for a command.
* @param commandWord The command's COMMAND_WORD
* @param commandDesc A brief description of what the command does
* @param commandParams The list of parameters the command accepts, or "none" if the command has no parameters
* @param commandEgParams An example of a set of valid parameter values to pass to the command, give "" if the command has no parameters
* @return the MESSAGE_USAGE for a command.
*/
protected static String getMessageUsage(
String commandWord,
Copy link

Choose a reason for hiding this comment

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

Indentation for wrapped lines should be 8 spaces

String commandDesc,
String commandParams,
String commandEgParams) {

return commandWord + ": " + commandDesc + "\n"
+ " Parameters: " + commandParams + "\n"
+ " Example: " + commandWord + (commandEgParams.equals("") ? "" : " " + commandEgParams);
}

/**
* Overloaded getMessageUsage() for commands that take in no parameters
* @param commandWord The command's COMMAND_WORD
* @param commandDesc A brief description of what the command does
* @return the MESSAGE_USAGE for a command.
*/
protected static String getMessageUsage(
String commandWord,
String commandDesc) {

return getMessageUsage(commandWord, commandDesc, "none", "");
}

/**
* Constructs a feedback message to summarise an operation that displayed a listing of persons.
*
Expand Down
8 changes: 4 additions & 4 deletions src/seedu/addressbook/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public class DeleteCommand extends Command {

public static final String COMMAND_WORD = "delete";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the person identified by the index number used in the last person listing.\n"
+ "Parameters: INDEX\n"
+ "Example: " + COMMAND_WORD + " 1";
public static final String MESSAGE_USAGE = Command.getMessageUsage(COMMAND_WORD,
"Deletes the person identified by the index number used in the last person listing.",
"INDEX",
"1");

public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s";

Expand Down
5 changes: 3 additions & 2 deletions src/seedu/addressbook/commands/ExitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ public class ExitCommand extends Command {

public static final String COMMAND_WORD = "exit";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Exits the program.\n"
+ "Example: " + COMMAND_WORD;
public static final String MESSAGE_USAGE = Command.getMessageUsage(COMMAND_WORD,
"Exits the program.");

public static final String MESSAGE_EXIT_ACKNOWEDGEMENT = "Exiting Address Book as requested ...";

@Override
Expand Down
8 changes: 4 additions & 4 deletions src/seedu/addressbook/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public class FindCommand extends Command {

public static final String COMMAND_WORD = "find";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose names contain any of "
+ "the specified keywords (case-sensitive) and displays them as a list with index numbers.\n"
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n"
+ "Example: " + COMMAND_WORD + " alice bob charlie";
public static final String MESSAGE_USAGE = Command.getMessageUsage(COMMAND_WORD,
"Finds all persons whose names contain any of the specified keywords (case-sensitive) and displays them as a list with index numbers.",
"KEYWORD [MORE_KEYWORDS]...",
"alice bob charlie");

private final Set<String> keywords;

Expand Down
4 changes: 2 additions & 2 deletions src/seedu/addressbook/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class HelpCommand extends Command {

public static final String COMMAND_WORD = "help";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Shows program usage instructions.\n"
+ "Example: " + COMMAND_WORD;
public static final String MESSAGE_USAGE = Command.getMessageUsage(COMMAND_WORD,
"Shows program usage instructions.");

@Override
public CommandResult execute() {
Expand Down
5 changes: 2 additions & 3 deletions src/seedu/addressbook/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ public class ListCommand extends Command {

public static final String COMMAND_WORD = "list";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Displays all persons in the address book as a list with index numbers.\n"
+ "Example: " + COMMAND_WORD;
public static final String MESSAGE_USAGE = Command.getMessageUsage(COMMAND_WORD,
"Displays all persons in the address book as a list with index numbers.");


@Override
Expand Down
8 changes: 4 additions & 4 deletions src/seedu/addressbook/commands/ViewAllCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public class ViewAllCommand extends Command {

public static final String COMMAND_WORD = "viewall";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Views the non-private details of the person "
+ "identified by the index number in the last shown person listing.\n"
+ "Parameters: INDEX\n"
+ "Example: " + COMMAND_WORD + " 1";
public static final String MESSAGE_USAGE = Command.getMessageUsage(COMMAND_WORD,
"Views the non-private details of the person identified by the index number in the last shown person listing.",
"INDEX",
"1");

public static final String MESSAGE_VIEW_PERSON_DETAILS = "Viewing person: %1$s";

Expand Down
8 changes: 4 additions & 4 deletions src/seedu/addressbook/commands/ViewCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public class ViewCommand extends Command {

public static final String COMMAND_WORD = "view";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Views the non-private details of the person "
+ "identified by the index number in the last shown person listing.\n"
+ "Parameters: INDEX\n"
+ "Example: " + COMMAND_WORD + " 1";
public static final String MESSAGE_USAGE = Command.getMessageUsage(COMMAND_WORD,
"Views the non-private details of the person identified by the index number in the last shown person listing.",
"INDEX",
"1");

public static final String MESSAGE_VIEW_PERSON_DETAILS = "Viewing person: %1$s";

Expand Down
66 changes: 35 additions & 31 deletions test/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,32 @@
|| ===================================================
|| Enter command: || [Command entered: sfdfd]
|| add: Adds a person to the address book. Contact details can be marked private by prepending 'p' to the prefix.
|| Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...
|| Example: add John Doe p/98765432 e/[email protected] a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney
|| Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...
|| Example: add John Doe p/98765432 e/[email protected] a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney
|| delete: Deletes the person identified by the index number used in the last person listing.
|| Parameters: INDEX
|| Example: delete 1
|| Clears address book permanently.
|| Example: clear
|| Parameters: INDEX
|| Example: delete 1
|| clear: Clears address book permanently.
|| Parameters: none
|| 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.
|| Parameters: KEYWORD [MORE_KEYWORDS]...
|| Example: find alice bob charlie
|| Parameters: KEYWORD [MORE_KEYWORDS]...
|| Example: find alice bob charlie
|| list: Displays all persons in the address book as a list with index numbers.
|| Example: list
|| Parameters: none
|| Example: list
|| view: Views the non-private details of the person identified by the index number in the last shown person listing.
|| Parameters: INDEX
|| Example: view 1
|| Parameters: INDEX
|| Example: view 1
|| viewall: Views the non-private details of the person identified by the index number in the last shown person listing.
|| Parameters: INDEX
|| Example: viewall 1
|| Parameters: INDEX
|| Example: viewall 1
|| help: Shows program usage instructions.
|| Example: help
|| Parameters: none
|| Example: help
|| exit: Exits the program.
|| Example: exit
|| Parameters: none
|| Example: exit
|| ===================================================
|| Enter command: || [Command entered: delete 1]
|| The person index provided is invalid
Expand All @@ -49,26 +53,26 @@
|| Enter command: || [Command entered: add wrong args wrong args]
|| Invalid command format!
|| add: Adds a person to the address book. Contact details can be marked private by prepending 'p' to the prefix.
|| Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...
|| Example: add John Doe p/98765432 e/[email protected] a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney
|| Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...
|| Example: add John Doe p/98765432 e/[email protected] a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney
|| ===================================================
|| Enter command: || [Command entered: add Valid Name 12345 e/[email protected] a/valid, address]
|| Invalid command format!
|| add: Adds a person to the address book. Contact details can be marked private by prepending 'p' to the prefix.
|| Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...
|| Example: add John Doe p/98765432 e/[email protected] a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney
|| Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...
|| Example: add John Doe p/98765432 e/[email protected] a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney
|| ===================================================
|| Enter command: || [Command entered: add Valid Name p/12345 [email protected] a/valid, address]
|| Invalid command format!
|| add: Adds a person to the address book. Contact details can be marked private by prepending 'p' to the prefix.
|| Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...
|| Example: add John Doe p/98765432 e/[email protected] a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney
|| Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...
|| Example: add John Doe p/98765432 e/[email protected] a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney
|| ===================================================
|| Enter command: || [Command entered: add Valid Name p/12345 e/[email protected] valid, address]
|| Invalid command format!
|| add: Adds a person to the address book. Contact details can be marked private by prepending 'p' to the prefix.
|| Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...
|| Example: add John Doe p/98765432 e/[email protected] a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney
|| Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...
|| Example: add John Doe p/98765432 e/[email protected] a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney
|| ===================================================
|| Enter command: || [Command entered: add Valid Name p/12345 e/[email protected] a/valid, address t/goodTag noPrefixTag]
|| Tags names should be alphanumeric
Expand Down Expand Up @@ -141,14 +145,14 @@
|| Enter command: || [Command entered: view]
|| Invalid command format!
|| view: Views the non-private details of the person identified by the index number in the last shown person listing.
|| Parameters: INDEX
|| Example: view 1
|| Parameters: INDEX
|| Example: view 1
|| ===================================================
|| Enter command: || [Command entered: viewall]
|| Invalid command format!
|| viewall: Views the non-private details of the person identified by the index number in the last shown person listing.
|| Parameters: INDEX
|| Example: viewall 1
|| Parameters: INDEX
|| Example: viewall 1
|| ===================================================
|| Enter command: || [Command entered: view should be only one number]
|| The person index provided is invalid
Expand Down Expand Up @@ -201,8 +205,8 @@
|| Enter command: || [Command entered: find]
|| Invalid command format!
|| find: Finds all persons whose names contain any of the specified keywords (case-sensitive) and displays them as a list with index numbers.
|| Parameters: KEYWORD [MORE_KEYWORDS]...
|| Example: find alice bob charlie
|| Parameters: KEYWORD [MORE_KEYWORDS]...
|| Example: find alice bob charlie
|| ===================================================
|| Enter command: || [Command entered: find bet]
||
Expand Down Expand Up @@ -236,8 +240,8 @@
|| Enter command: || [Command entered: delete]
|| Invalid command format!
|| delete: Deletes the person identified by the index number used in the last person listing.
|| Parameters: INDEX
|| Example: delete 1
|| Parameters: INDEX
|| Example: delete 1
|| ===================================================
|| Enter command: || [Command entered: delete should be only one number]
|| The person index provided is invalid
Expand Down
5 changes: 5 additions & 0 deletions test/java/seedu/addressbook/common/UtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public void elementsAreUnique() throws Exception {
assertNotUnique(null, "a", "b", null);
}

@Test
public void isAnyNullTest() {
assertFalse(Utils.isAnyNull());
}

private void assertAreUnique(Object... objects) {
assertTrue(Utils.elementsAreUnique(Arrays.asList(objects)));
}
Expand Down