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

Implement an IndexIdPair #206

Merged
merged 10 commits into from
Oct 26, 2020
Merged

Implement an IndexIdPair #206

merged 10 commits into from
Oct 26, 2020

Conversation

hopinxian
Copy link

@hopinxian hopinxian commented Oct 26, 2020

An IndexIdPair contains either an index or an Id which points to either a Person or a Location. The significance of implementing this pair is to make it scalable for all commands to be able to use either index or id to refer to a Person or a Location.

All commands possible have been updated to use this IndexIdPair where possible.

Close #197

@hopinxian hopinxian added priority.High Needs to be completed soon Implementation Coding required labels Oct 26, 2020
@hopinxian hopinxian added this to the v1.3 milestone Oct 26, 2020
@hopinxian hopinxian self-assigned this Oct 26, 2020
Copy link

@siangernlow siangernlow left a comment

Choose a reason for hiding this comment

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

LGTM once done, just some recommendations/queries to be answered.

+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_NAME + "National University of Singapore "
+ PREFIX_ADDRESS + "21 Lower Kent Ridge Rd, Singapore 119077";
+ PREFIX_ADDRESS + "21 Lower Kent Ridge Rd, Singapore 119077";;

Choose a reason for hiding this comment

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

There might be a typo here (extra semi-colon)

Copy link
Author

Choose a reason for hiding this comment

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

Yeah it is. Have removed it.

* @throws ParseException if unable to parse the Id or the index.
*/
public IndexIdPair(ArgumentMultimap argMultimap, Prefix prefix) throws ParseException {
requireAllNonNull(argMultimap, prefix);

Choose a reason for hiding this comment

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

As this is a public constructor, perhaps you could consider making this code more defensive by ensuring that Prefix could only be PREFIX_PERSON_ID or PREFIX_LOCATION_ID? Since a wrong argument is likely to originate from a command inputting the wrong prefix, an assert statement here should be good enough.

Choose a reason for hiding this comment

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

Alternatively, checking and throwing an exception may make this constructor easier to test.

Copy link
Author

Choose a reason for hiding this comment

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

Sure! I have added exception checking.

}

@Test
public void constructor_validArgs_success() {

Choose a reason for hiding this comment

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

Might need to add the corresponding tests for constructor related to the comment in the IndexIdPair class.

Copy link
Author

Choose a reason for hiding this comment

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

Got it! Done!

Comment on lines +94 to +107
try {
assertEquals(new IndexIdPair(argMultimap, PREFIX_PERSON_ID), expectedPersonPair);
} catch (ParseException pe) {
throw new IllegalArgumentException("Invalid userInput.", pe);
}

// location index
argMultimap = ArgumentTokenizer.tokenize(indexString, PREFIX_LOCATION_ID);
IndexIdPair expectedLocationPair = new IndexIdPair(INDEX_FIRST, null, PREFIX_LOCATION_ID);
try {
assertEquals(new IndexIdPair(argMultimap, PREFIX_LOCATION_ID), expectedLocationPair);
} catch (ParseException pe) {
throw new IllegalArgumentException("Invalid userInput.", pe);
}

Choose a reason for hiding this comment

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

Are the try-catch statements required here as the test is not supposed to fail anyway, and the parse exception isn't part of an assertion.

Copy link
Author

Choose a reason for hiding this comment

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

indexIdPair constructor might throw a ParseException. Hence, the solution is either to use a try catch block, or have the test method throw the parse exception. I chose to use try catch in this case.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, i went to look through other tests and it seems addressbook for person tests chooses to have the method throw exception. I will follow accordingly.

@siangernlow siangernlow merged commit f8b0b15 into AY2021S1-CS2103T-T13-1:master Oct 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implementation Coding required priority.High Needs to be completed soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a dedicated parser for Indexes and IDs
2 participants