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][T08-3]Julian Lim #30

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

macchazuki
Copy link

No description provided.

+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_FAVOURITE_PERSON_SUCCESS = "Favourited %1$s";
public static final String MESSAGE_PERSON_ALREADY_FAVOURITED = "Peron is already favourited";

Choose a reason for hiding this comment

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

Small typo here.

Suggested change
public static final String MESSAGE_PERSON_ALREADY_FAVOURITED = "Peron is already favourited";
public static final String MESSAGE_PERSON_ALREADY_FAVOURITED = "Person is already favourited";

* Signals that the person is already favourited.
*/
public static class AlreadyFavouritedException extends DuplicateDataException {
protected AlreadyFavouritedException() { super("Peron is already favourited"); }

Choose a reason for hiding this comment

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

Suggested change
protected AlreadyFavouritedException() { super("Peron is already favourited"); }
protected AlreadyFavouritedException() { super("Person is already favourited"); }

return new CommandResult(String.format(MESSAGE_FAVOURITE_PERSON_SUCCESS, target));
} catch (IndexOutOfBoundsException ie) {
return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
} catch (PersonNotFoundException pnfe) {

Choose a reason for hiding this comment

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

The favourite command is based on the index shown from a list of people who exists in the address book so would there be a PersonNotFoundException? Wouldn't the index out of bounds exception be enough if they enter an invalid index?

Copy link

Choose a reason for hiding this comment

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

Neh. He is catching for the case of having an outdated list.
ie,

  1. You list 5 people
  2. You delete person 2
  3. You try to favourite person 2.

As the list is only updated per call to list, the list may be outdated and still contain non-existent people.
Good job catching for this edge case (How much is inherited, I will not comment)

Copy link

@0WN463 0WN463 left a comment

Choose a reason for hiding this comment

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

Overall, good attempt. I/O testing was in place and function-wise, the feature works, however you should be careful of the code smell that exists within your work

* `find Betsy` +
`favourite 1` +
Favourites the 1st person in the results of the `find` command.

Copy link

Choose a reason for hiding this comment

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

Substantial updating of UG while keeping to its original format, well done.

return new CommandResult(String.format(MESSAGE_FAVOURITE_PERSON_SUCCESS, target));
} catch (IndexOutOfBoundsException ie) {
return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
} catch (PersonNotFoundException pnfe) {
Copy link

Choose a reason for hiding this comment

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

Neh. He is catching for the case of having an outdated list.
ie,

  1. You list 5 people
  2. You delete person 2
  3. You try to favourite person 2.

As the list is only updated per call to list, the list may be outdated and still contain non-existent people.
Good job catching for this edge case (How much is inherited, I will not comment)

return new CommandResult(Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK);
} catch (AlreadyFavouritedException pnfe) {
return new CommandResult(MESSAGE_PERSON_ALREADY_FAVOURITED);
}
Copy link

Choose a reason for hiding this comment

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

Well done improving your user experience by catching for AlreadyFavourited cases

@@ -54,6 +54,10 @@ public void removePerson(ReadOnlyPerson toRemove) throws PersonNotFoundException
allPersons.remove(toRemove);
}

public void favouritePerson(ReadOnlyPerson toFavourite) throws PersonNotFoundException, AlreadyFavouritedException {
allPersons.favourite(toFavourite);
}
Copy link

Choose a reason for hiding this comment

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

Some muddiness here because favourite can be both a verb, an adjective and a noun. So maybe renaming it to makeFavourite would make it clearer that it is a method and adhere better to coding standards

if(internalList.get(internalList.indexOf(toFavourite)).getFavourite()) {
throw new AlreadyFavouritedException();
} else {
final boolean personFoundAndFavourited = internalList.get(internalList.indexOf(toFavourite)).setFavourite();
Copy link

Choose a reason for hiding this comment

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

The above violates Law of Demeter, which probably isn't taught yet.
That's why the better approach would be UniquePersonList telling target Person to make himself a favourite, and have the target Person be the one who throws the exception instead
Also, internalList.get(internalList.indexOf(toFavourite)) is called a lot so refactoring it out would be good.
Also the smell from the setFavourite also return true has resurfaced here. personFoundAndFavourited will always be true unless you run into a OOB Exception, which means that PersonNotFound Exception will never thrown and the program would malfunction.

this.isFavourite = true;
return true;
}

Copy link

Choose a reason for hiding this comment

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

Odd choice of having a function that always returns true

favourite 0
favourite 3
favourite 2

Copy link

Choose a reason for hiding this comment

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

Good that I/O testing is updated
(Though because you didn't test for PersonNotFound, I can safely assumed that my thesis about "inheriting" is correct in my previous comment.)

@0WN463
Copy link

0WN463 commented Feb 15, 2019

See my comments for suggestions. Please close this PR after reading comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants