diff --git a/src/main/java/seedu/address/commons/util/StringUtil.java b/src/main/java/seedu/address/commons/util/StringUtil.java
index 61cc8c9a1cb..42d8e21c119 100644
--- a/src/main/java/seedu/address/commons/util/StringUtil.java
+++ b/src/main/java/seedu/address/commons/util/StringUtil.java
@@ -65,4 +65,31 @@ public static boolean isNonZeroUnsignedInteger(String s) {
return false;
}
}
+
+ /**
+ * Returns true if the strings are equal after being trimmed.
+ */
+ public static boolean areStrippedStringsEqual(String a, String b) {
+ if (a == null || b == null) {
+ return a == null && b == null;
+ }
+
+ return a.strip().equals(b.strip());
+ }
+
+ /**
+ * Strips whitespace and format specifiers from the {@code message}.
+ *
+ * Format specifiers are assumed to be in the format of {@code %\\d*\\$?\\w}.
+ *
+ * @param text The text to strip.
+ * @return The message without the placeholders and whitespace.
+ */
+ public static String stripMessageFormatSpecifiers(String text) {
+ if (text.contains("%")) {
+ return text.replaceAll("%\\d*\\$?\\w", "").trim();
+ } else {
+ return text.trim();
+ }
+ }
}
diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java
index b8003a20eaa..7ee9f985f3b 100644
--- a/src/main/java/seedu/address/logic/Messages.java
+++ b/src/main/java/seedu/address/logic/Messages.java
@@ -8,28 +8,40 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import seedu.address.commons.util.StringUtil;
+import seedu.address.logic.commands.AddPersonCommand;
+import seedu.address.logic.commands.ClearCommand;
+import seedu.address.logic.commands.DeletePersonCommand;
+import seedu.address.logic.commands.EditPersonCommand;
+import seedu.address.logic.commands.ExitCommand;
+import seedu.address.logic.commands.HelpCommand;
+import seedu.address.logic.commands.ListPersonCommand;
+import seedu.address.logic.commands.MarkAttendanceCommand;
+import seedu.address.logic.commands.SetCourseCommand;
+import seedu.address.logic.commands.UnmarkAttendanceCommand;
import seedu.address.logic.parser.Prefix;
import seedu.address.model.person.Person;
/**
* Container for user visible messages.
+ *
+ * Messages that are not command-specific are listed here.
+ *
+ * Messages that are command-specific should be in their respective classes.
*/
public class Messages {
public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
- public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
- public static final String MESSAGE_MISSING_NUSNET = "No such student with the NUSNET_ID found in contacts!";
- public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
+ public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The student index provided is invalid";
+ public static final String MESSAGE_MISSING_NUSNET = "No such student with the NUSNet ID found in contacts!";
+ public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d students listed!";
public static final String MESSAGE_DUPLICATE_FIELDS =
- "Multiple values specified for the following single-valued field(s): ";
- public static final String MESSAGE_MARKED_ATTENDANCE_SUCCESS = "Marked attendance for student: ";
- public static final String MESSAGE_MARK_EXISTING_ATTENDANCE_SUCCESS =
- "Re-marked Attendance for student: ";
- public static final String MESSAGE_UNMARKED_ATTENDANCE_SUCCESS = "Unmarked attendance for student: ";
- public static final String MESSAGE_UNMARK_NONEXISITING_ATTENDANCE_SUCCESS =
- "Attendance is unmarked for student: ";
+ "Multiple values specified for the following single-valued field(s): ";
+ public static final String MESSAGE_DUPLICATE_PERSON =
+ "This student already exists in the contact book";
+ /** Error messages are shown when a command cannot be executed. */
private static final String[] ERROR_MESSAGES = {
MESSAGE_UNKNOWN_COMMAND,
MESSAGE_INVALID_COMMAND_FORMAT,
@@ -38,12 +50,26 @@ public class Messages {
MESSAGE_DUPLICATE_FIELDS,
};
- private static final String[] SUCCESS_MESSAGES = {
+ /** Neutral messages are shown when a command executes successfully, but no change occurs. */
+ private static final String[] NEUTRAL_MESSAGES = {
MESSAGE_PERSONS_LISTED_OVERVIEW,
- MESSAGE_MARKED_ATTENDANCE_SUCCESS,
- MESSAGE_MARK_EXISTING_ATTENDANCE_SUCCESS,
- MESSAGE_UNMARKED_ATTENDANCE_SUCCESS,
- MESSAGE_UNMARK_NONEXISITING_ATTENDANCE_SUCCESS,
+ EditPersonCommand.MESSAGE_NOT_EDITED,
+ ExitCommand.MESSAGE_EXIT_ACKNOWLEDGEMENT,
+ HelpCommand.SHOWING_HELP_MESSAGE,
+ ListPersonCommand.MESSAGE_SUCCESS,
+ MarkAttendanceCommand.MESSAGE_MARK_EXISTING_ATTENDANCE_SUCCESS,
+ UnmarkAttendanceCommand.MESSAGE_UNMARK_NONEXISITING_ATTENDANCE_SUCCESS
+ };
+
+ /** Success messages are shown when a command executes successfully and does a modification. */
+ private static final String[] SUCCESS_MESSAGES = {
+ AddPersonCommand.MESSAGE_SUCCESS,
+ ClearCommand.MESSAGE_SUCCESS,
+ DeletePersonCommand.MESSAGE_DELETE_PERSON_SUCCESS,
+ EditPersonCommand.MESSAGE_EDIT_PERSON_SUCCESS,
+ MarkAttendanceCommand.MESSAGE_MARKED_ATTENDANCE_SUCCESS,
+ SetCourseCommand.MESSAGE_SUCCESS,
+ UnmarkAttendanceCommand.MESSAGE_UNMARKED_ATTENDANCE_SUCCESS,
};
/**
@@ -83,35 +109,32 @@ public static String format(Person person) {
}
/**
- * Returns true if the message is a message representing the failure of a command.
+ * Returns true if the {@code message} is a message representing the failure of a command.
+ * Otherwise, false is returned.
+ *
+ * @param message The message to check.
+ * @see StringUtil#stripMessageFormatSpecifiers(String)
*/
public static boolean isErrorMessage(String message) {
requireNonNull(message);
return Arrays
.stream(ERROR_MESSAGES)
- .map(Messages::stripMessagePlaceholders)
+ .map(StringUtil::stripMessageFormatSpecifiers)
.anyMatch(message::contains);
}
/**
- * Returns true if the message is a message representing the success of a command.
+ * Returns true if the {@code message} is a message representing the success of a command.
+ * Otherwise, false is returned.
+ *
+ * @param message The message to check.
+ * @see StringUtil#stripMessageFormatSpecifiers(String)
*/
public static boolean isSuccessMessage(String message) {
requireNonNull(message);
return Arrays
.stream(SUCCESS_MESSAGES)
- .map(Messages::stripMessagePlaceholders)
+ .map(StringUtil::stripMessageFormatSpecifiers)
.anyMatch(message::contains);
}
-
- /**
- * Strips whitespace and {@code %1$s} placeholders from the message.
- */
- private static String stripMessagePlaceholders(String message) {
- if (message.contains("%1$s")) {
- return String.format(message, "").trim();
- } else {
- return message.trim();
- }
- }
}
diff --git a/src/main/java/seedu/address/logic/commands/AddPersonCommand.java b/src/main/java/seedu/address/logic/commands/AddPersonCommand.java
index fc1e6b4c140..96b0310a497 100644
--- a/src/main/java/seedu/address/logic/commands/AddPersonCommand.java
+++ b/src/main/java/seedu/address/logic/commands/AddPersonCommand.java
@@ -1,6 +1,7 @@
package seedu.address.logic.commands;
import static java.util.Objects.requireNonNull;
+import static seedu.address.logic.Messages.MESSAGE_DUPLICATE_PERSON;
import static seedu.address.logic.commands.util.CommandMessageUsageUtil.generateMessageUsage;
import static seedu.address.logic.commands.util.ParameterSyntax.PARAMETER_ADDRESS;
import static seedu.address.logic.commands.util.ParameterSyntax.PARAMETER_EMAIL;
@@ -24,7 +25,7 @@ public class AddPersonCommand extends Command {
public static final String MESSAGE_USAGE = generateMessageUsage(
COMMAND_WORD,
- "Adds a person to the address book. ",
+ "Adds a student into the contact book. ",
PARAMETER_NAME,
PARAMETER_NUSNET,
PARAMETER_PHONE.asOptional(true),
@@ -33,10 +34,9 @@ public class AddPersonCommand extends Command {
PARAMETER_TAG.asMultiple(2)
);
- 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";
- public static final String MESSAGE_DUPLICATE_NUSNET = "Another person with the same NUSNET already exists in the "
- + "contact book";
+ public static final String MESSAGE_SUCCESS = "New student added: %1$s";
+ public static final String MESSAGE_DUPLICATE_NUSNET = "Another student with the same NUSNet ID "
+ + "already exists in the contact book";
private final Person toAdd;
diff --git a/src/main/java/seedu/address/logic/commands/ClearCommand.java b/src/main/java/seedu/address/logic/commands/ClearCommand.java
index 9c86b1fa6e4..e634c47a6e0 100644
--- a/src/main/java/seedu/address/logic/commands/ClearCommand.java
+++ b/src/main/java/seedu/address/logic/commands/ClearCommand.java
@@ -11,8 +11,7 @@
public class ClearCommand extends Command {
public static final String COMMAND_WORD = "clear";
- public static final String MESSAGE_SUCCESS = "Address book has been cleared!";
-
+ public static final String MESSAGE_SUCCESS = "Contact book has been cleared!";
@Override
public CommandResult execute(Model model) {
diff --git a/src/main/java/seedu/address/logic/commands/DeletePersonCommand.java b/src/main/java/seedu/address/logic/commands/DeletePersonCommand.java
index 149d85c45db..b152aa149d7 100644
--- a/src/main/java/seedu/address/logic/commands/DeletePersonCommand.java
+++ b/src/main/java/seedu/address/logic/commands/DeletePersonCommand.java
@@ -22,11 +22,11 @@ public class DeletePersonCommand extends Command {
public static final String MESSAGE_USAGE = generateMessageUsage(
COMMAND_WORD,
- "Deletes the student identified by NUSNET_ID.",
+ "Deletes the student identified by NUSNet ID.",
PARAMETER_NUSNET
);
- public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Student: %1$s";
+ public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted student: %1$s";
private final NusNet targetNusNet;
diff --git a/src/main/java/seedu/address/logic/commands/EditPersonCommand.java b/src/main/java/seedu/address/logic/commands/EditPersonCommand.java
index 6ba95c96400..95575990f4e 100644
--- a/src/main/java/seedu/address/logic/commands/EditPersonCommand.java
+++ b/src/main/java/seedu/address/logic/commands/EditPersonCommand.java
@@ -1,6 +1,7 @@
package seedu.address.logic.commands;
import static java.util.Objects.requireNonNull;
+import static seedu.address.logic.Messages.MESSAGE_DUPLICATE_PERSON;
import static seedu.address.logic.commands.util.CommandMessageUsageUtil.generateMessageUsage;
import static seedu.address.logic.commands.util.ParameterSyntax.PARAMETER_ADDRESS;
import static seedu.address.logic.commands.util.ParameterSyntax.PARAMETER_EMAIL;
@@ -42,8 +43,8 @@ public class EditPersonCommand extends Command {
public static final String MESSAGE_USAGE = generateMessageUsage(
COMMAND_WORD,
- "Edits the details of the person identified "
- + "by the index number used in the displayed person list. "
+ "Edits the details of the student identified "
+ + "by the index number used in the currently displayed student list. "
+ "Existing values will be overwritten by the input values.",
PARAMETER_INDEX,
PARAMETER_NAME.asOptional(false),
@@ -54,9 +55,8 @@ public class EditPersonCommand extends Command {
PARAMETER_TAG.asMultiple(0)
);
- public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s";
+ public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited student: %1$s";
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
- public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book.";
private final Index index;
private final EditPersonDescriptor editPersonDescriptor;
diff --git a/src/main/java/seedu/address/logic/commands/FindPersonCommand.java b/src/main/java/seedu/address/logic/commands/FindPersonCommand.java
index 1e8f770c44d..f50fae02c46 100644
--- a/src/main/java/seedu/address/logic/commands/FindPersonCommand.java
+++ b/src/main/java/seedu/address/logic/commands/FindPersonCommand.java
@@ -18,11 +18,10 @@ public class FindPersonCommand extends Command {
public static final String MESSAGE_USAGE = generateMessageUsage(
COMMAND_WORD,
- "Finds all persons whose names contain any of "
+ "Finds all students whose names contain any of "
+ "the specified keywords (case-insensitive) and displays them as a list with index numbers.",
"KEYWORD [MORE_KEYWORDS]...",
COMMAND_WORD + " alice bob charlie"
-
);
private final NameContainsKeywordsPredicate predicate;
diff --git a/src/main/java/seedu/address/logic/commands/MarkAttendanceCommand.java b/src/main/java/seedu/address/logic/commands/MarkAttendanceCommand.java
index 83b828e0421..28bec22d1f0 100644
--- a/src/main/java/seedu/address/logic/commands/MarkAttendanceCommand.java
+++ b/src/main/java/seedu/address/logic/commands/MarkAttendanceCommand.java
@@ -18,7 +18,7 @@
import seedu.address.model.weeknumber.WeekNumber;
/**
- * Marks attendance of an existing person in the address book.
+ * Marks attendance of an existing student in the contact book.
*/
public class MarkAttendanceCommand extends Command {
@@ -26,10 +26,14 @@ public class MarkAttendanceCommand extends Command {
public static final String MESSAGE_USAGE = generateMessageUsage(
COMMAND_WORD,
- "Marks the attendance of the person identified by their NusNet by adding the specified week to "
- + "their attendance set. ",
+ "Marks the attendance of the student identified by their NUSNet ID "
+ + "by adding the specified week to their attendance set. ",
PARAMETER_NUSNET, PARAMETER_WEEK);
+ public static final String MESSAGE_MARKED_ATTENDANCE_SUCCESS = "Marked attendance for student: ";
+ public static final String MESSAGE_MARK_EXISTING_ATTENDANCE_SUCCESS =
+ "Attendance is already marked for student: ";
+
private final NusNet nusNet;
private final WeekNumber weekNumber;
@@ -59,7 +63,7 @@ public CommandResult execute(Model model) throws CommandException {
if (!updatedWeekAttendance.add(weekNumber)) {
String formattedMessage = String.format("%1$s%2$s, %3$s, Week %4$s",
- Messages.MESSAGE_MARK_EXISTING_ATTENDANCE_SUCCESS,
+ MESSAGE_MARK_EXISTING_ATTENDANCE_SUCCESS,
personToMark.getName(), personToMark.getNusNet(), weekNumber);
return new CommandResult(formattedMessage);
@@ -70,7 +74,7 @@ public CommandResult execute(Model model) throws CommandException {
model.setPerson(personToMark, updatedPerson);
- String formattedMessage = String.format("%1$s%2$s, %3$s, Week %4$s", Messages.MESSAGE_MARKED_ATTENDANCE_SUCCESS,
+ String formattedMessage = String.format("%1$s%2$s, %3$s, Week %4$s", MESSAGE_MARKED_ATTENDANCE_SUCCESS,
updatedPerson.getName(), updatedPerson.getNusNet(), weekNumber);
return new CommandResult(formattedMessage);
diff --git a/src/main/java/seedu/address/logic/commands/SetCourseCommand.java b/src/main/java/seedu/address/logic/commands/SetCourseCommand.java
index 0bf0cffb2f1..4344830709c 100644
--- a/src/main/java/seedu/address/logic/commands/SetCourseCommand.java
+++ b/src/main/java/seedu/address/logic/commands/SetCourseCommand.java
@@ -1,6 +1,7 @@
package seedu.address.logic.commands;
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
+import static seedu.address.logic.commands.util.ParameterSyntax.PARAMETER_COURSE_CODE;
import static seedu.address.model.course.Course.isValidCode;
import seedu.address.logic.commands.exceptions.CommandException;
@@ -20,13 +21,11 @@
public class SetCourseCommand extends Command {
public static final String COMMAND_WORD = "setcrs";
- public static final String MESSAGE_ARGUMENTS = "Course: %1$s";
- public static final String MESSAGE_CONSTRAINTS =
- "Course code should follow the format \"XX1234Y\", Y is optional";
-
- public static final String MESSAGE_USAGE = CommandMessageUsageUtil.generateMessageUsage(COMMAND_WORD,
- "Set Course name ", "course code", COMMAND_WORD + " CS2104");
+ public static final String MESSAGE_USAGE = CommandMessageUsageUtil.generateMessageUsage(
+ COMMAND_WORD,
+ "Sets the course name. ",
+ PARAMETER_COURSE_CODE);
public static final String MESSAGE_SUCCESS = "Successfully updated course name";
@@ -49,7 +48,7 @@ public SetCourseCommand(Course course) {
@Override
public CommandResult execute(Model model) throws CommandException {
if (!isValidCode(course.toString())) {
- throw new CommandException(MESSAGE_CONSTRAINTS);
+ throw new CommandException(PARAMETER_COURSE_CODE.getParameterConstraint());
}
model.changeCode(course.toString());
return new CommandResult(MESSAGE_SUCCESS);
diff --git a/src/main/java/seedu/address/logic/commands/UnmarkAttendanceCommand.java b/src/main/java/seedu/address/logic/commands/UnmarkAttendanceCommand.java
index 00aa7dcc819..9140befa8a7 100644
--- a/src/main/java/seedu/address/logic/commands/UnmarkAttendanceCommand.java
+++ b/src/main/java/seedu/address/logic/commands/UnmarkAttendanceCommand.java
@@ -17,7 +17,10 @@
import seedu.address.model.weeknumber.WeekNumber;
/**
- *
+ * Unmarks attendance of an existing student of a certain week in the contact book.
+ *
The week should be between 1 and 13.
+ * The NUSNet ID should be valid.
+ * Attendance can be unmarked again, without any error, but no change would occur.
*/
public class UnmarkAttendanceCommand extends Command {
@@ -25,16 +28,21 @@ public class UnmarkAttendanceCommand extends Command {
public static final String MESSAGE_USAGE = generateMessageUsage(
COMMAND_WORD,
- "Unmarks the attendance of the person identified by their NusNet by removing the specified week to "
- + "their attendance set. ",
+ "Unmarks the attendance of the student identified by their NUSNet ID "
+ + "by removing the specified week to their attendance set. ",
PARAMETER_NUSNET, PARAMETER_WEEK);
+ public static final String MESSAGE_UNMARKED_ATTENDANCE_SUCCESS = "Unmarked attendance for student: ";
+ public static final String MESSAGE_UNMARK_NONEXISITING_ATTENDANCE_SUCCESS =
+ "Attendance is already unmarked for student: ";
private final NusNet nusNet;
private final WeekNumber weekNumber;
/**
- * @param nusNet of the person to mark attendance for
- * @param weekNumber the week number to mark attendance for
+ * Creates an {@link UnmarkAttendanceCommand}.
+ *
+ * @param nusNet of the person to mark attendance for.
+ * @param weekNumber the week number to mark attendance for.
*/
public UnmarkAttendanceCommand(NusNet nusNet, WeekNumber weekNumber) {
requireNonNull(nusNet);
@@ -57,7 +65,7 @@ public CommandResult execute(Model model) throws CommandException {
if (!updatedWeekAttendance.remove(weekNumber)) {
String formattedMessage = String.format("%1$s%2$s, %3$s, Week %4$s",
- Messages.MESSAGE_UNMARK_NONEXISITING_ATTENDANCE_SUCCESS,
+ MESSAGE_UNMARK_NONEXISITING_ATTENDANCE_SUCCESS,
personToUnmark.getName(), personToUnmark.getNusNet(), weekNumber);
return new CommandResult(formattedMessage);
@@ -70,7 +78,7 @@ public CommandResult execute(Model model) throws CommandException {
model.setPerson(personToUnmark, updatedPerson);
String formattedMessage = String.format("%1$s%2$s, %3$s, Week %4$s",
- Messages.MESSAGE_UNMARKED_ATTENDANCE_SUCCESS,
+ MESSAGE_UNMARKED_ATTENDANCE_SUCCESS,
updatedPerson.getName(), updatedPerson.getNusNet(), weekNumber);
return new CommandResult(formattedMessage);
diff --git a/src/main/java/seedu/address/logic/commands/util/CommandMessageUsageUtil.java b/src/main/java/seedu/address/logic/commands/util/CommandMessageUsageUtil.java
index 9f73444e202..0f862f872b5 100644
--- a/src/main/java/seedu/address/logic/commands/util/CommandMessageUsageUtil.java
+++ b/src/main/java/seedu/address/logic/commands/util/CommandMessageUsageUtil.java
@@ -1,6 +1,7 @@
package seedu.address.logic.commands.util;
import static java.util.Objects.requireNonNull;
+import static seedu.address.commons.util.StringUtil.areStrippedStringsEqual;
/**
* A container for {@code Command} message specific utility functions.
@@ -11,6 +12,8 @@ public class CommandMessageUsageUtil {
public static final String PARAMETER_LABEL = "Parameters: ";
+ public static final String CONSTRAINT_LABEL = "Constraints: ";
+
/**
* Generates the message usage, given the {@code commandWord}, {@code description},
* and {@code example} as strings.
@@ -34,16 +37,41 @@ public static String generateMessageUsage(String commandWord, String description
+ EXAMPLE_LABEL + example;
}
+ /**
+ * Generates the message usage, given the {@code commandWord}, {@code description},
+ * {@code parameters}, {@code constraints} and {@code example} as strings.
+ */
+ public static String generateMessageUsage(String commandWord, String description,
+ String parameters, String constraints, String example) {
+ return commandWord + ": "
+ + description + "\n"
+ + PARAMETER_LABEL + parameters + "\n"
+ + CONSTRAINT_LABEL + constraints + "\n"
+ + EXAMPLE_LABEL + example;
+ }
+
/**
* Generates the message usage, given the {@code commandWord}, {@code description} as strings,
* and the {@code parameters}.
*/
public static String generateMessageUsage(String commandWord, String description,
Parameter... parameters) {
+ String constraints = generateMessageUsageConstraints(parameters);
+
+ if (constraints.isBlank()) {
+ return generateMessageUsage(
+ commandWord,
+ description,
+ generateMessageUsageParameters(parameters),
+ generateMessageUsageExample(commandWord, parameters)
+ );
+ }
+
return generateMessageUsage(
commandWord,
description,
generateMessageUsageParameters(parameters),
+ constraints,
generateMessageUsageExample(commandWord, parameters)
);
}
@@ -63,6 +91,24 @@ public static String generateMessageUsageParameters(Parameter... parameters) {
return stringBuilder.toString().trim();
}
+ /**
+ * Generates the message usage constraints, given the {@code parameters}.
+ */
+ public static String generateMessageUsageConstraints(Parameter... parameters) {
+ StringBuilder stringBuilder = new StringBuilder();
+
+ for (Parameter p : parameters) {
+ String constraint = p.getParameterConstraint();
+ if (!constraint.isBlank()) {
+ stringBuilder
+ .append(constraint)
+ .append(" ");
+ }
+ }
+
+ return stringBuilder.toString().trim();
+ }
+
/**
* Generates the message usage example, given the {@code commmandWord} and {@code parameters}.
*/
@@ -86,7 +132,8 @@ public static String generateMessageUsageExample(String commandWord, Parameter..
*/
public static boolean isUtilLabel(String text) {
requireNonNull(text);
- return EXAMPLE_LABEL.strip().equals(text.strip())
- || PARAMETER_LABEL.strip().equals(text.strip());
+ return areStrippedStringsEqual(EXAMPLE_LABEL, text)
+ || areStrippedStringsEqual(PARAMETER_LABEL, text)
+ || areStrippedStringsEqual(CONSTRAINT_LABEL, text);
}
}
diff --git a/src/main/java/seedu/address/logic/commands/util/Parameter.java b/src/main/java/seedu/address/logic/commands/util/Parameter.java
index 1e68a7dcd3a..54dfe74c6c2 100644
--- a/src/main/java/seedu/address/logic/commands/util/Parameter.java
+++ b/src/main/java/seedu/address/logic/commands/util/Parameter.java
@@ -8,7 +8,7 @@
* in a more standardized way.
*/
public class Parameter {
- public final String parameterHint;
+ public final String parameterConstraint;
private final String parameterName;
private final String[] parameterExampleValues;
@@ -19,14 +19,14 @@ public class Parameter {
private final int exampleRepetitions;
/**
- * Constructor for a {@code Parameter} that takes in the {@code parameterName}, {@code parameterHint}
+ * Constructor for a {@code Parameter} that takes in the {@code parameterName}, {@code parameterConstraint}
* and valid {@code parameterExampleValues}, with at least one example value.
*/
- public Parameter(String parameterName, String parameterHint, String... parameterExampleValues) {
+ public Parameter(String parameterName, String parameterConstraint, String... parameterExampleValues) {
assert parameterName != null;
this.parameterName = parameterName;
- this.parameterHint = parameterHint;
+ this.parameterConstraint = parameterConstraint;
assert parameterExampleValues != null;
assert parameterExampleValues.length > 0;
@@ -42,7 +42,7 @@ public Parameter(String parameterName, String parameterHint, String... parameter
*/
Parameter(Parameter parameter, String detailWrapper, int exampleRepetitions) {
this.parameterName = parameter.parameterName;
- this.parameterHint = parameter.parameterHint;
+ this.parameterConstraint = parameter.parameterConstraint;
this.parameterExampleValues = parameter.parameterExampleValues;
assert detailWrapper.contains("%s") : "detailWrapper must contain `%s`";
@@ -58,11 +58,10 @@ public String getParameterName() {
}
/**
- * Gets the parameter hint or an empty string if no hint is present.
+ * Gets the parameter constraint or an empty string if no constraint is present.
*/
- public String getParameterHint() {
- return Optional.ofNullable(parameterHint)
- .map(hint -> "(" + hint + ")")
+ public String getParameterConstraint() {
+ return Optional.ofNullable(parameterConstraint)
.orElse("");
}
@@ -70,7 +69,7 @@ public String getParameterHint() {
* Gets the details of the parameter, which are the parameter name and hint appended behind.
*/
public String getParameterDetails() {
- String details = getParameterName() + " " + getParameterHint();
+ String details = getParameterName();
return details.trim();
}
diff --git a/src/main/java/seedu/address/logic/commands/util/ParameterSyntax.java b/src/main/java/seedu/address/logic/commands/util/ParameterSyntax.java
index eea6acfc639..985413aa7eb 100644
--- a/src/main/java/seedu/address/logic/commands/util/ParameterSyntax.java
+++ b/src/main/java/seedu/address/logic/commands/util/ParameterSyntax.java
@@ -53,7 +53,7 @@ public class ParameterSyntax {
public static final Parameter PARAMETER_INDEX = new Parameter(
"INDEX",
- "must be a positive integer",
+ "Index must be a positive integer.",
"1"
);
@@ -63,5 +63,9 @@ public class ParameterSyntax {
"1"
);
-
+ public static final Parameter PARAMETER_COURSE_CODE = new Parameter(
+ "COURSE_CODE",
+ "Course code must follow the format \"XX1234Y\", Y is optional.",
+ "CS2104"
+ );
}
diff --git a/src/main/java/seedu/address/logic/parser/SetCourseCommandParser.java b/src/main/java/seedu/address/logic/parser/SetCourseCommandParser.java
index f7ae2f48258..5330b72f3b0 100644
--- a/src/main/java/seedu/address/logic/parser/SetCourseCommandParser.java
+++ b/src/main/java/seedu/address/logic/parser/SetCourseCommandParser.java
@@ -25,7 +25,7 @@ public SetCourseCommand parse(String args) throws ParseException {
course = ParserUtil.parseCourse(args);
} catch (IllegalValueException ive) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT,
- SetCourseCommand.MESSAGE_CONSTRAINTS), ive);
+ SetCourseCommand.MESSAGE_USAGE), ive);
}
return new SetCourseCommand(course);
diff --git a/src/test/java/seedu/address/commons/util/StringUtilTest.java b/src/test/java/seedu/address/commons/util/StringUtilTest.java
index c56d407bf3f..82325ed7270 100644
--- a/src/test/java/seedu/address/commons/util/StringUtilTest.java
+++ b/src/test/java/seedu/address/commons/util/StringUtilTest.java
@@ -1,5 +1,6 @@
package seedu.address.commons.util;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.testutil.Assert.assertThrows;
@@ -140,4 +141,46 @@ public void getDetails_nullGiven_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> StringUtil.getDetails(null));
}
+ @Test
+ void areStrippedStringsEqual_equalStrings() {
+ assertTrue(StringUtil.areStrippedStringsEqual("abc", " abc "));
+ assertTrue(StringUtil.areStrippedStringsEqual(" x y z ", "x y z "));
+ assertTrue(StringUtil.areStrippedStringsEqual(null, null));
+ assertTrue(StringUtil.areStrippedStringsEqual("", " "));
+ }
+
+ @Test
+ void areStrippedStringsEqual_unequalStrings() {
+ assertFalse(StringUtil.areStrippedStringsEqual("q w e", "qwe"));
+ assertFalse(StringUtil.areStrippedStringsEqual(" x ", " X"));
+ assertFalse(StringUtil.areStrippedStringsEqual("", null));
+ }
+
+ @Test
+ void stripMessageFormatSpecifiers_blankText_specifierAbsent() {
+ assertEquals("", StringUtil.stripMessageFormatSpecifiers(""));
+ assertEquals("", StringUtil.stripMessageFormatSpecifiers(" "));
+ assertEquals("", StringUtil.stripMessageFormatSpecifiers(" \n "));
+ }
+
+ @Test
+ void stripMessageFormatSpecifiers_blankText_specifierPresent() {
+ assertEquals("", StringUtil.stripMessageFormatSpecifiers("%d %s %c %f"));
+ assertEquals("", StringUtil.stripMessageFormatSpecifiers(" %d \n %1$d "));
+ assertEquals("", StringUtil.stripMessageFormatSpecifiers("%2$s \t %3$c \n %1$o"));
+ }
+
+ @Test
+ void stripMessageFormatSpecifiers_nonBlankText_specifierAbsent() {
+ assertEquals("abc", StringUtil.stripMessageFormatSpecifiers("abc"));
+ assertEquals("def", StringUtil.stripMessageFormatSpecifiers(" def "));
+ assertEquals("1 2 3", StringUtil.stripMessageFormatSpecifiers(" 1 2 3 \n"));
+ }
+
+ @Test
+ void stripMessageFormatSpecifiers_nonBlankText_specifierPresent() {
+ assertEquals("abc", StringUtil.stripMessageFormatSpecifiers("a%sb%dc"));
+ assertEquals("def", StringUtil.stripMessageFormatSpecifiers(" d%1$se%2$bf %f "));
+ assertEquals("1 2 3", StringUtil.stripMessageFormatSpecifiers("%d\n1 2 3 %1$t \t "));
+ }
}
diff --git a/src/test/java/seedu/address/logic/commands/AddCommandIntegrationTest.java b/src/test/java/seedu/address/logic/commands/AddCommandIntegrationTest.java
index 8c8425d7df4..5439adfd0ec 100644
--- a/src/test/java/seedu/address/logic/commands/AddCommandIntegrationTest.java
+++ b/src/test/java/seedu/address/logic/commands/AddCommandIntegrationTest.java
@@ -1,5 +1,6 @@
package seedu.address.logic.commands;
+import static seedu.address.logic.Messages.MESSAGE_DUPLICATE_PERSON;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalCourse.getTypicalCourseName;
@@ -43,7 +44,7 @@ public void execute_newPerson_success() {
public void execute_duplicatePerson_throwsCommandException() {
Person personInList = model.getAddressBook().getPersonList().get(0);
assertCommandFailure(new AddPersonCommand(personInList), model,
- AddPersonCommand.MESSAGE_DUPLICATE_PERSON);
+ MESSAGE_DUPLICATE_PERSON);
}
}
diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java
index 04c9ffbe145..6b00e2e75fa 100644
--- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java
+++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java
@@ -4,6 +4,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static seedu.address.logic.Messages.MESSAGE_DUPLICATE_PERSON;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalPersons.ALICE;
@@ -57,7 +58,7 @@ public void execute_duplicatePerson_throwsCommandException() {
ModelStub modelStub = new ModelStubWithPerson(validPerson);
assertThrows(CommandException.class,
- AddPersonCommand.MESSAGE_DUPLICATE_PERSON, () -> addCommand.execute(modelStub));
+ MESSAGE_DUPLICATE_PERSON, () -> addCommand.execute(modelStub));
Person validPerson2 = new PersonBuilder()
.withNusNet("E1234567")
diff --git a/src/test/java/seedu/address/logic/commands/EditCommandTest.java b/src/test/java/seedu/address/logic/commands/EditCommandTest.java
index fc575b36631..aed3923382d 100644
--- a/src/test/java/seedu/address/logic/commands/EditCommandTest.java
+++ b/src/test/java/seedu/address/logic/commands/EditCommandTest.java
@@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static seedu.address.logic.Messages.MESSAGE_DUPLICATE_PERSON;
import static seedu.address.logic.commands.CommandTestUtil.DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB;
@@ -117,7 +118,7 @@ public void execute_duplicatePersonUnfilteredList_failure() {
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(firstPerson).build();
EditPersonCommand editCommand = new EditPersonCommand(INDEX_SECOND_PERSON, descriptor);
- assertCommandFailure(editCommand, model, EditPersonCommand.MESSAGE_DUPLICATE_PERSON);
+ assertCommandFailure(editCommand, model, MESSAGE_DUPLICATE_PERSON);
}
@Test
@@ -129,7 +130,7 @@ public void execute_duplicatePersonFilteredList_failure() {
EditPersonCommand editCommand = new EditPersonCommand(INDEX_FIRST_PERSON,
new EditPersonDescriptorBuilder(personInList).build());
- assertCommandFailure(editCommand, model, EditPersonCommand.MESSAGE_DUPLICATE_PERSON);
+ assertCommandFailure(editCommand, model, MESSAGE_DUPLICATE_PERSON);
}
@Test
diff --git a/src/test/java/seedu/address/logic/commands/MarkAttendanceCommandTest.java b/src/test/java/seedu/address/logic/commands/MarkAttendanceCommandTest.java
index cfb18e8c190..1c5ed52f3ff 100644
--- a/src/test/java/seedu/address/logic/commands/MarkAttendanceCommandTest.java
+++ b/src/test/java/seedu/address/logic/commands/MarkAttendanceCommandTest.java
@@ -71,7 +71,7 @@ public void execute_validNusNetValidWeekNumber_markSuccess() {
public void execute_validNusNetDuplicateWeekNumber_markSuccess() {
MarkAttendanceCommand command = new MarkAttendanceCommand(testValidNusNet, testValidWeekNo1);
CommandResult expectedCommandResult =
- new CommandResult("Re-marked Attendance for student: Alice Pauline, e0000001, Week 1");
+ new CommandResult("Attendance is already marked for student: Alice Pauline, e0000001, Week 1");
assertCommandSuccess(command, model, expectedCommandResult, expectedModel);
}
diff --git a/src/test/java/seedu/address/logic/commands/UnmarkAttendanceCommandTest.java b/src/test/java/seedu/address/logic/commands/UnmarkAttendanceCommandTest.java
index c852cba0252..49f006eb219 100644
--- a/src/test/java/seedu/address/logic/commands/UnmarkAttendanceCommandTest.java
+++ b/src/test/java/seedu/address/logic/commands/UnmarkAttendanceCommandTest.java
@@ -79,7 +79,7 @@ public void execute_validNusNetValidWeekNumber_unmarkSuccess() {
ALICE.getAddress(), aliceAttendanceUpdated, ALICE.getTags());
CommandResult expectedCommandResult =
- new CommandResult("Attendance is unmarked for student: Alice Pauline, e0000001, Week 6");
+ new CommandResult("Attendance is already unmarked for student: Alice Pauline, e0000001, Week 6");
UnmarkAttendanceCommand command = new UnmarkAttendanceCommand(testValidNusNet, testValidWeekNo6);
diff --git a/src/test/java/seedu/address/logic/commands/util/CommandMessageUsageUtilTest.java b/src/test/java/seedu/address/logic/commands/util/CommandMessageUsageUtilTest.java
index 3f7b8c390c3..c0c32c08e29 100644
--- a/src/test/java/seedu/address/logic/commands/util/CommandMessageUsageUtilTest.java
+++ b/src/test/java/seedu/address/logic/commands/util/CommandMessageUsageUtilTest.java
@@ -32,7 +32,8 @@ void generateMessageUsage_withParameters() {
String messageUsage = CommandMessageUsageUtil
.generateMessageUsage("bad", "cat", p1, p2);
assertEquals("bad: cat\n"
- + "Parameters: ert (cbs) hic/ban\n"
+ + "Parameters: ert hic/ban\n"
+ + "Constraints: cbs\n"
+ "Example: bad lmr hic/741",
messageUsage);
}
@@ -50,7 +51,7 @@ void generateMessageUsage_withStringParameters() {
@Test
void generateMessageUsageParameters() {
String parameters = CommandMessageUsageUtil.generateMessageUsageParameters(p1, p2);
- assertEquals("ert (cbs) hic/ban", parameters);
+ assertEquals("ert hic/ban", parameters);
}
@Test
diff --git a/src/test/java/seedu/address/logic/commands/util/ParameterTest.java b/src/test/java/seedu/address/logic/commands/util/ParameterTest.java
index 96f685ddad2..6d8a1449d3d 100644
--- a/src/test/java/seedu/address/logic/commands/util/ParameterTest.java
+++ b/src/test/java/seedu/address/logic/commands/util/ParameterTest.java
@@ -19,17 +19,17 @@ void getParameterName() {
@Test
void getParameterHint() {
- assertEquals("(def)", parameter.getParameterHint());
+ assertEquals("def", parameter.getParameterConstraint());
}
@Test
void getParameterDetails() {
- assertEquals("abc (def)", parameter.getParameterDetails());
+ assertEquals("abc", parameter.getParameterDetails());
}
@Test
void getFormattedParameterDetails() {
- assertEquals("abc (def)", parameter.getParameterDetails());
+ assertEquals("abc", parameter.getParameterDetails());
}
@Test
@@ -49,26 +49,26 @@ void getParameterWithExampleValues() {
@Test
void asOptional_exampleNotPresent() {
- assertEquals("[abc (def)]", parameter.asOptional(false).toString());
+ assertEquals("[abc]", parameter.asOptional(false).toString());
}
@Test
void asOptional_examplePresent() {
- assertEquals("[abc (def)] 123", parameter.asOptional(true).toString());
+ assertEquals("[abc] 123", parameter.asOptional(true).toString());
}
@Test
void asMultiple_zeroExampleRepetitions() {
- assertEquals("[abc (def)]...", parameter.asMultiple(0).toString());
+ assertEquals("[abc]...", parameter.asMultiple(0).toString());
}
@Test
void asMultiple_oneExampleRepetitions() {
- assertEquals("[abc (def)]... 123", parameter.asMultiple(1).toString());
+ assertEquals("[abc]... 123", parameter.asMultiple(1).toString());
}
@Test
void asMultiple_twoExampleRepetitions() {
- assertEquals("[abc (def)]... 123 456", parameter.asMultiple(2).toString());
+ assertEquals("[abc]... 123 456", parameter.asMultiple(2).toString());
}
}
diff --git a/src/test/java/seedu/address/ui/util/SyntaxHighlighterTest.java b/src/test/java/seedu/address/ui/util/SyntaxHighlighterTest.java
index ae5ef5a2a06..7364b0b05e7 100644
--- a/src/test/java/seedu/address/ui/util/SyntaxHighlighterTest.java
+++ b/src/test/java/seedu/address/ui/util/SyntaxHighlighterTest.java
@@ -31,9 +31,9 @@ class SyntaxHighlighterTest {
static void setUp() {
s = new SyntaxHighlighter();
errorTextFlow = s.generateLine(Messages.MESSAGE_UNKNOWN_COMMAND);
- successTextFlow = s.generateLine(Messages.MESSAGE_MARKED_ATTENDANCE_SUCCESS);
+ successTextFlow = s.generateLine(MarkAttendanceCommand.MESSAGE_MARKED_ATTENDANCE_SUCCESS);
genericTextFlow = s.generateLine(MarkAttendanceCommand.MESSAGE_USAGE);
- multilineTextFlows = s.generateLines(Messages.MESSAGE_MARKED_ATTENDANCE_SUCCESS + "\n"
+ multilineTextFlows = s.generateLines(MarkAttendanceCommand.MESSAGE_MARKED_ATTENDANCE_SUCCESS + "\n"
+ MarkAttendanceCommand.MESSAGE_USAGE
);
}