forked from nus-cs2103-AY2425S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Refactor command error messages #148
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4126ff9
Change build settings to decrease jar size
ZShunRen 4484722
Merge branch 'master' of https://github.com/AY2425S1-CS2103T-T14-4/tp
ZShunRen 7b2e9f9
Add more specific add command error message
ZShunRen 546af09
Refactor tests to match new add command message
ZShunRen 2ee69e5
Add cumulative invalid parameter errors
ZShunRen dbd7108
Fix comment in EditCommandParserTest
ZShunRen 4b3f612
Add back debug comment
ZShunRen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/seedu/address/commons/util/PrefixCheckResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package seedu.address.commons.util; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.logic.parser.Prefix; | ||
|
||
/** | ||
* Contains the results of checking for missing prefixes. | ||
*/ | ||
public class PrefixCheckResult { | ||
private final boolean isAllPrefixPresent; | ||
private final List<Prefix> missingPrefixes; | ||
|
||
/** | ||
* Constructs a {@code PrefixCheckResult} object. | ||
* @param isAllPrefixPresent boolean value that is true when all mandatory prefixes are present. | ||
* @param missingPrefixes a {@code List} object that contains all the missing prefixes in the invalid add command. | ||
*/ | ||
public PrefixCheckResult(boolean isAllPrefixPresent, List<Prefix> missingPrefixes) { | ||
this.isAllPrefixPresent = isAllPrefixPresent; | ||
this.missingPrefixes = missingPrefixes; | ||
} | ||
|
||
public boolean isAllPrefixPresent() { | ||
return this.isAllPrefixPresent; | ||
} | ||
|
||
public List<Prefix> getMissingPrefixes() { | ||
return this.missingPrefixes; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,18 +24,22 @@ 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. " | ||
+ "Parameters: " | ||
+ PREFIX_NAME + "NAME " | ||
+ PREFIX_PHONE + "PHONE " | ||
+ PREFIX_EMAIL + "EMAIL " | ||
+ PREFIX_ADDRESS + "ADDRESS " | ||
+ PREFIX_JOB + "JOB " | ||
+ PREFIX_INCOME + "INCOME " | ||
+ "[" + PREFIX_TIER + "TIER]...\n" | ||
+ "[" + PREFIX_NEW_REMARK + "NEW REMARK]..." | ||
+ "[" + PREFIX_STATUS + "STATUS]...\n" | ||
+ "Example: " + COMMAND_WORD + " " | ||
public static final String MISSING_PREFIX_MESSAGE_START = "The following mandatory prefixes are missing: "; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book.\n" | ||
+ "Required Parameters: " | ||
+ PREFIX_NAME + " NAME " | ||
+ PREFIX_PHONE + " PHONE " | ||
+ PREFIX_EMAIL + " EMAIL " | ||
+ PREFIX_ADDRESS + " ADDRESS " | ||
+ PREFIX_JOB + " JOB " | ||
+ PREFIX_INCOME + " INCOME\n" | ||
+ "Optional Parameters: " | ||
+ "[" + PREFIX_TIER + " TIER] " | ||
+ "[" + PREFIX_NEW_REMARK + " NEW REMARK] " | ||
+ "[" + PREFIX_STATUS + " STATUS] \n" | ||
+ "Example Usage: '" | ||
+ COMMAND_WORD + " " | ||
+ PREFIX_NAME + "John Doe " | ||
+ PREFIX_PHONE + "98765432 " | ||
+ PREFIX_EMAIL + "[email protected] " | ||
|
@@ -44,7 +48,8 @@ public class AddCommand extends Command { | |
+ PREFIX_INCOME + "300 " | ||
+ PREFIX_TIER + "GOLD " | ||
+ PREFIX_NEW_REMARK + "He is very smart " | ||
+ PREFIX_STATUS + "NON_URGENT"; | ||
+ PREFIX_STATUS + "NON_URGENT" | ||
+ "'"; | ||
|
||
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"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import java.util.Set; | ||
import java.util.function.Supplier; | ||
|
||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.person.Person; | ||
|
||
/** | ||
|
@@ -11,4 +15,38 @@ public final class CommandCommons { | |
public static final String DEFAULT_STATUS = "NONE"; | ||
public static final Person EMPTY_PERSON = null; | ||
|
||
/** | ||
* A functional interface similar to {@link Supplier}, but allows for a checked exception, {@code ParseException} | ||
* to be thrown. | ||
* @param <T> The return type of the method supplied by this supplier. | ||
*/ | ||
@FunctionalInterface | ||
public interface ThrowingSupplier<T> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice abstraction with ThrowingSupplier! |
||
T get() throws ParseException; | ||
} | ||
|
||
/** | ||
* Used to parse a field in a command, and if there are problems with the field, add the resulting error message | ||
* to a {@link Set}, to be displayed to the user | ||
* @param <T> The attribute type to be parsed | ||
* @param parserMethod A lambda expression that contains a method, that when run can either return the parsed value | ||
* or throws a {@code ParseException} | ||
* @param errors A {@link Set} that contains the error messages | ||
* @return The parsed value or null | ||
*/ | ||
public static <T> T parseField(ThrowingSupplier<? extends T> parserMethod, Set<String> errors) { | ||
try { | ||
return parserMethod.get(); | ||
} catch (ParseException e) { | ||
errors.add(e.getMessage()); | ||
return null; | ||
} | ||
} | ||
|
||
public static String getErrorMessage(Set<String> errors) { | ||
StringBuilder accumulatedErrors = new StringBuilder(); | ||
errors.forEach(error -> accumulatedErrors.append(error + "\n")); | ||
return accumulatedErrors.toString().trim(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,20 +44,21 @@ public class EditCommand extends Command { | |
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the person identified " | ||
+ "by the index number used in the displayed person list. " | ||
+ "Existing values will be overwritten by the input values. Any fields unspecified will not be modified.\n" | ||
+ "Parameters: INDEX (must be a positive integer) " | ||
+ "[" + PREFIX_NAME + "NAME] " | ||
+ "[" + PREFIX_PHONE + "PHONE] " | ||
+ "[" + PREFIX_EMAIL + "EMAIL] " | ||
+ "[" + PREFIX_ADDRESS + "ADDRESS] " | ||
+ "[" + PREFIX_JOB + "JOB] " | ||
+ "[" + PREFIX_INCOME + "INCOME] " | ||
+ "[" + PREFIX_TIER + "TIER]...\n" | ||
+ "[" + PREFIX_NEW_REMARK + "NEW REMARK] " | ||
+ "[" + PREFIX_APPEND_REMARK + "ADD-ON TO EXISTING REMARK] " | ||
+ "[" + PREFIX_STATUS + "STATUS] " | ||
+ "Example: " + COMMAND_WORD + " 1 " | ||
+ "Required Parameters: INDEX (must be a positive integer)\n" | ||
+ "Optional Parameters: " | ||
+ "[" + PREFIX_NAME + " NAME] " | ||
+ "[" + PREFIX_PHONE + " PHONE] " | ||
+ "[" + PREFIX_EMAIL + " EMAIL] " | ||
+ "[" + PREFIX_ADDRESS + " ADDRESS] " | ||
+ "[" + PREFIX_JOB + " JOB] " | ||
+ "[" + PREFIX_INCOME + " INCOME] " | ||
+ "[" + PREFIX_TIER + " TIER] " | ||
+ "[" + PREFIX_NEW_REMARK + " NEW REMARK] " | ||
+ "[" + PREFIX_APPEND_REMARK + " ADD-ON TO EXISTING REMARK] " | ||
+ "[" + PREFIX_STATUS + " STATUS] \n" | ||
+ "Example Usage: '" + COMMAND_WORD + " 1 " | ||
+ PREFIX_PHONE + "91234567 " | ||
+ PREFIX_EMAIL + "[email protected]"; | ||
+ PREFIX_EMAIL + "[email protected]'"; | ||
|
||
public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s"; | ||
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't forget to clean up this commented lines later!