-
Notifications
You must be signed in to change notification settings - Fork 411
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
Removal of repeatable parameters #190
Removal of repeatable parameters #190
Conversation
Click here to submit a new iteration when this PR is ready for review. See this repository's contribution guide for more information. |
Codecov Report
@@ Coverage Diff @@
## master #190 +/- ##
============================================
+ Coverage 74.00% 74.16% +0.16%
- Complexity 420 428 +8
============================================
Files 71 71
Lines 1281 1293 +12
Branches 126 127 +1
============================================
+ Hits 948 959 +11
+ Misses 301 300 -1
- Partials 32 34 +2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
v1@Eclipse-Dominator submitted v1 for review.
Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level3.git refs/pr/190/1/head:BRANCHNAME where |
1 similar comment
v1@Eclipse-Dominator submitted v1 for review.
Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level3.git refs/pr/190/1/head:BRANCHNAME where |
@Eclipse-Dominator Now that we have three alternatives, what your thoughts about selecting one? |
Updated the PR description instead. |
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.
Some initial comments ...
src/main/java/seedu/address/logic/parser/EditCommandParser.java
Outdated
Show resolved
Hide resolved
src/test/java/seedu/address/logic/parser/AddCommandParserTest.java
Outdated
Show resolved
Hide resolved
@Eclipse-Dominator As discussed, let's proceed with this approach. |
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.
Added a few more comments.
src/test/java/seedu/address/logic/parser/AddCommandParserTest.java
Outdated
Show resolved
Hide resolved
src/test/java/seedu/address/logic/parser/AddCommandParserTest.java
Outdated
Show resolved
Hide resolved
ba48384
to
7d3bb2b
Compare
v2@Eclipse-Dominator submitted v2 for review. (📚 Archive) (📈 Interdiff between v1 and v2) (📈 Range-Diff between v1 and v2) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level3.git refs/pr/190/2/head:BRANCHNAME where |
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.
Suggestion to change the message for duplicate person.
@@ -9,5 +14,21 @@ public class Messages { | |||
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_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!"; | |||
public static final String MESSAGE_DUPLICATE_FIELDS = "Detected multiple values for the following field%s: " | |||
+ "%s.\nPlease only a single value for those fields\n"; |
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.
I feel that this Message should be worded properly. Perhaps it will be better to have a message like "Multiple values detected for the following field%s: " + "%s.\nOnly one value is allowed for these fields\n".
7d3bb2b
to
6210dce
Compare
v3@Eclipse-Dominator submitted v3 for review. (📚 Archive) (📈 Interdiff between v2 and v3) (📈 Range-Diff between v2 and v3) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level3.git refs/pr/190/3/head:BRANCHNAME where |
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.
Some suggestions added
|
||
return String.format(MESSAGE_DUPLICATE_FIELDS, duplicateFields.size() > 1 ? "s" : "", | ||
String.join(" ", duplicateFields), duplicateFields.size() > 1 ? "these" : "this"); | ||
} |
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.
I think we are complicating this code too much for too little payback. No need to bother with singular/plural differences. Something like the following?
Multiple values specified for the following single-valued filed(s): ...
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.
Personally, I think over complicating this code is okay here since everything related to the messages have been abstracted to within Messages
. So, there won't be any additional code duplication and its self-contained to within Messages
.
That being said, I think changing it the message to
Multiple values specified for the following single-valued field(s): ...
Please only supply a single value for the field(s) mentioned above.
can make it appear more user-friendly?
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.
Personally, I think over complicating this code is okay here since everything related to the messages have been abstracted to within Messages. So, there won't be any additional code duplication and its self-contained to within Messages.
Always be as economical as possible with code. Every line of code is an additional burden every project member has to carry for the rest of the lifetime of the project.
That being said, I think changing it the message to
Multiple values specified for the following single-valued field(s): ...
Please only supply a single value for the field(s) mentioned above.
can make it appear more user-friendly?
Not totally opposed, but I have some concerns:
- Feels a bit redundant. Check how the UI present this error to the user. Perhaps the first sentence is enough for the user to understand the problem.
- Check other error messages. If they don't have
Please do such and such ...
part, we don't want to make this specific error message different from others.
/** | ||
* Formats the duplicate prefixes into an error message. | ||
*/ | ||
public static String getDuplicatePrefixesToMessage(Set<Prefix> duplicatePrefixes) { |
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.
alternative to consider:
public static String getDuplicatePrefixesToMessage(Set<Prefix> duplicatePrefixes) { | |
public static String getDuplicatePrefixesToMessage(Prefix... duplicatePrefixes) { |
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.
I kept it intentionally this to avoid ordering of the fields in the message to avoid complications when doing unit test etc.
It is possible to sort the field within this method but I feel that supplying it with a Set
will make it cleaner.
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.
Instead of creating Set
objects everywhere this method is called, you can create the Set
inside the method at the start?
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.
Yes, but the code technically is really only called once in production code and the rest of it is called in unit test.
Which is called below.
/**
* Throws a {@code ParseException} if any of the prefixes given in {@code prefixes} appeared more than
* once among the arguments.
*/
public void verifyNoDuplicatePrefixesFor(Prefix... prefixes) throws ParseException {
Set<Prefix> duplicatedPrefixes = new HashSet<>();
Set<Prefix> prefixSet = Set.of(prefixes);
argMultimap.forEach((key, list) -> {
if (list.size() > 1 && prefixSet.contains(key)) {
duplicatedPrefixes.add(key);
}
});
if (!duplicatedPrefixes.isEmpty()) {
throw new ParseException(Messages.getDuplicatePrefixesToMessage(duplicatedPrefixes));
}
}
Converting getDuplicatePrefixesToMessage()
to take in Prefix...
or Prefix[]
will involve calling duplicatedPrefixes.toArray(Prefix[]::new))
which will cause it to be converted once again into a Set
object when inside the method.
This is true unless we are using a fixed-size array for duplicatedPrefixes
or alternative we can convert the whole process as a java stream and convert it to an array.
I will experiment processing the above with java stream and see its readability in the next version.
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.
I think the code is cleaner with java stream, I will update the relevant code.
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.
BTW, you are doing something very similar in here:
public void verifyNoDuplicatePrefixesFor(Prefix... prefixes) throws ParseException {
Set<Prefix> duplicatedPrefixes = new HashSet<>();
Set<Prefix> prefixSet = Set.of(prefixes);
6210dce
to
a4b0fa9
Compare
v4@Eclipse-Dominator submitted v4 for review. (📚 Archive) (📈 Interdiff between v3 and v4) (📈 Range-Diff between v3 and v4) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level3.git refs/pr/190/4/head:BRANCHNAME where |
v5@Eclipse-Dominator submitted v5 for review.
(📚 Archive) (📈 Interdiff between v4 and v5) (📈 Range-Diff between v4 and v5) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level3.git refs/pr/190/5/head:BRANCHNAME where |
dd943c5
to
9d63a65
Compare
v6@Eclipse-Dominator submitted v6 for review.
(📚 Archive) (📈 Interdiff between v5 and v6) (📈 Range-Diff between v5 and v6) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level3.git refs/pr/190/6/head:BRANCHNAME where |
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.
Some further suggestions
84bc1cd
to
1e74f73
Compare
v10@Eclipse-Dominator submitted v10 for review. (📚 Archive) (📈 Interdiff between v9 and v10) (📈 Range-Diff between v9 and v10) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level3.git refs/pr/190/10/head:BRANCHNAME where |
Resolve rebase conflicts. |
@Eclipse-Dominator Looks like the rebase wasn't entirely correct. There are some unrelated code in this PR. |
d7b3553
to
7841d23
Compare
v11@Eclipse-Dominator submitted v11 for review. (📚 Archive) (📈 Interdiff between v10 and v11) (📈 Range-Diff between v10 and v11) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level3.git refs/pr/190/11/head:BRANCHNAME where |
src/test/java/seedu/address/logic/parser/EditCommandParserTest.java
Outdated
Show resolved
Hide resolved
src/test/java/seedu/address/logic/parser/EditCommandParserTest.java
Outdated
Show resolved
Hide resolved
7841d23
to
e407b81
Compare
v12@Eclipse-Dominator submitted v12 for review. (📚 Archive) (📈 Interdiff between v11 and v12) (📈 Range-Diff between v11 and v12) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level3.git refs/pr/190/12/head:BRANCHNAME where |
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.
Some comments added (did not review the test code though).
938be75
to
ce1f59b
Compare
v13@Eclipse-Dominator submitted v13 for review. (📚 Archive) (📈 Interdiff between v12 and v13) (📈 Range-Diff between v12 and v13) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level3.git refs/pr/190/13/head:BRANCHNAME where |
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.
Just a minor question. I think we are close to home on this one. Let me ask others to have a look as well.
src/test/java/seedu/address/logic/parser/EditCommandParserTest.java
Outdated
Show resolved
Hide resolved
@se-edu/tech-team-level1 for your review ... |
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.
Overall, LGTM! Just some minor suggestions below
* Throws a {@code ParseException} if any of the prefixes given in {@code prefixes} appeared more than | ||
* once among the arguments. | ||
*/ | ||
public void verifyNoDuplicatePrefixesFor(Prefix... prefixes) throws ParseException { |
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.
Could consider shortening the name of the method to verifyNoDuplicatePrefixes as the 'For' does not seem to be very necessary
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.
It reads as a natural statement e.g., verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_ADDRESS)
i.e., verify no duplicate prefixes for A, B, ..
But OK to remove.
Can also consider verifyNoDuplicatesFor
as Prefix is implied by the parameter type.
src/test/java/seedu/address/logic/parser/EditCommandParserTest.java
Outdated
Show resolved
Hide resolved
ce1f59b
to
3d2c2df
Compare
v14@Eclipse-Dominator submitted v14 for review. (📚 Archive) (📈 Interdiff between v13 and v14) (📈 Range-Diff between v13 and v14) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level3.git refs/pr/190/14/head:BRANCHNAME where |
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.
Two commented you missed.
If a single-valued parameter is repeated multiple times in a command, only the last occurrence is taken. This allows the user to correct a mistake in a parameter value by simply typing it again, which may be faster than moving the cursor back to the original parameter values and editing it. This feature serves as a good example of 'going the extra mile to optimize the application for target users' (i.e., users who can type fast). However, this feature can cause certain user errors to go unnoticed e.g., unintended repetition caused by a typo in parameter name Alternatives considered: (a) Retain current behavior but give a friendly warning to the user that a parameter was 'overridden'. (b) Remove this feature i.e., treat repeated single-valued parameters as an error, and reject the command with an error message. Alternative (a) requires significantly more complicated code (see se-edu#181), steepening the learning curve for for new programmers. Given that this application is primarily meant for training novice programmers, the impact on the learning curve is not worth the benefit of retaining this feature. Therefore, let's do option (b).
3d2c2df
to
4a4144d
Compare
v15@Eclipse-Dominator submitted v15 for review. (📚 Archive) (📈 Interdiff between v14 and v15) (📈 Range-Diff between v14 and v15) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level3.git refs/pr/190/15/head:BRANCHNAME where |
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.
Code works as expected. LGTM.
This PR an alternative that Fixes #162 (other alternatives: #176, #181)
In this PR, we treat repeated parameters as an error.