-
Notifications
You must be signed in to change notification settings - Fork 35
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,43 @@ | ||||||
package seedu.addressbook.commands; | ||||||
|
||||||
import seedu.addressbook.common.Messages; | ||||||
import seedu.addressbook.data.person.ReadOnlyPerson; | ||||||
import seedu.addressbook.data.person.UniquePersonList.PersonNotFoundException; | ||||||
import seedu.addressbook.data.person.UniquePersonList.AlreadyFavouritedException; | ||||||
|
||||||
/** | ||||||
* Favourites a person identified using it's last displayed index from the address book. | ||||||
*/ | ||||||
public class FavouriteCommand extends Command { | ||||||
|
||||||
public static final String COMMAND_WORD = "favourite"; | ||||||
|
||||||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||||||
+ ": Favourites the person identified by the index number used in the last person listing.\n" | ||||||
+ "Parameters: INDEX\n" | ||||||
+ "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"; | ||||||
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. Small typo here.
Suggested change
|
||||||
|
||||||
public FavouriteCommand(int targetVisibleIndex) { | ||||||
super(targetVisibleIndex); | ||||||
} | ||||||
|
||||||
|
||||||
@Override | ||||||
public CommandResult execute() { | ||||||
try { | ||||||
final ReadOnlyPerson target = getTargetPerson(); | ||||||
addressBook.favouritePerson(target); | ||||||
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) { | ||||||
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. 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? 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. Neh. He is catching for the case of having an outdated list.
As the list is only updated per call to |
||||||
return new CommandResult(Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK); | ||||||
} catch (AlreadyFavouritedException pnfe) { | ||||||
return new CommandResult(MESSAGE_PERSON_ALREADY_FAVOURITED); | ||||||
} | ||||||
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. Well done improving your user experience by catching for AlreadyFavourited cases |
||||||
} | ||||||
|
||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
import seedu.addressbook.data.person.UniquePersonList; | ||
import seedu.addressbook.data.person.UniquePersonList.DuplicatePersonException; | ||
import seedu.addressbook.data.person.UniquePersonList.PersonNotFoundException; | ||
|
||
import seedu.addressbook.data.person.UniquePersonList.AlreadyFavouritedException; | ||
/** | ||
* Represents the entire address book. Contains the data of the address book. | ||
*/ | ||
|
@@ -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); | ||
} | ||
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. 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 |
||
|
||
/** | ||
* Clears all persons and tags from the address book. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ public class Person implements ReadOnlyPerson { | |
private Phone phone; | ||
private Email email; | ||
private Address address; | ||
|
||
private boolean isFavourite = false; | ||
private final Set<Tag> tags = new HashSet<>(); | ||
|
||
/** | ||
|
@@ -62,6 +62,13 @@ public Set<Tag> getTags() { | |
return new HashSet<>(tags); | ||
} | ||
|
||
public boolean setFavourite() { | ||
this.isFavourite = true; | ||
return true; | ||
} | ||
|
||
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. Odd choice of having a function that always returns true |
||
public boolean getFavourite() { return this.isFavourite; } | ||
|
||
/** | ||
* Replaces this person's tags with the tags in the argument tag set. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -29,6 +29,13 @@ protected DuplicatePersonException() { | |||||
} | ||||||
} | ||||||
|
||||||
/** | ||||||
* Signals that the person is already favourited. | ||||||
*/ | ||||||
public static class AlreadyFavouritedException extends DuplicateDataException { | ||||||
protected AlreadyFavouritedException() { super("Peron is already favourited"); } | ||||||
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.
Suggested change
|
||||||
} | ||||||
|
||||||
/** | ||||||
* Signals that an operation targeting a specified person in the list would fail because | ||||||
* there is no such matching person in the list. | ||||||
|
@@ -122,6 +129,23 @@ public void remove(ReadOnlyPerson toRemove) throws PersonNotFoundException { | |||||
} | ||||||
} | ||||||
|
||||||
/** | ||||||
* Favourites the equivalent person from the list. | ||||||
* | ||||||
* @throws PersonNotFoundException if no such person could be found in the list. | ||||||
* @throws AlreadyFavouritedException if person is already favourited. | ||||||
*/ | ||||||
public void favourite(ReadOnlyPerson toFavourite) throws PersonNotFoundException, AlreadyFavouritedException { | ||||||
if(internalList.get(internalList.indexOf(toFavourite)).getFavourite()) { | ||||||
throw new AlreadyFavouritedException(); | ||||||
} else { | ||||||
final boolean personFoundAndFavourited = internalList.get(internalList.indexOf(toFavourite)).setFavourite(); | ||||||
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. The above violates Law of Demeter, which probably isn't taught yet. |
||||||
if (!personFoundAndFavourited) { | ||||||
throw new PersonNotFoundException(); | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
/** | ||||||
* Clears all persons in list. | ||||||
*/ | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,9 @@ | |
|| Enter command: || [Command entered: delete 1] | ||
|| The person index provided is invalid | ||
|| =================================================== | ||
|| Enter command: || [Command entered: favourite 1] | ||
|| The person index provided is invalid | ||
|| =================================================== | ||
|| Enter command: || [Command entered: view 1] | ||
|| The person index provided is invalid | ||
|| =================================================== | ||
|
@@ -233,6 +236,27 @@ | |
|| | ||
|| 2 persons listed! | ||
|| =================================================== | ||
|| Enter command: || [Command entered: favourite] | ||
|| Invalid command format! | ||
|| favourite: Favourites the person identified by the index number used in the last person listing. | ||
|| Parameters: INDEX | ||
|| Example: favourite 1 | ||
|| =================================================== | ||
|| Enter command: || [Command entered: favourite should be only one number] | ||
|| The person index provided is invalid | ||
|| =================================================== | ||
|| Enter command: || [Command entered: favourite -1] | ||
|| The person index provided is invalid | ||
|| =================================================== | ||
|| Enter command: || [Command entered: favourite 0] | ||
|| The person index provided is invalid | ||
|| =================================================== | ||
|| Enter command: || [Command entered: favourite 3] | ||
|| The person index provided is invalid | ||
|| =================================================== | ||
|| Enter command: || [Command entered: favourite 2] | ||
|| Favourited Charlie Dickson Phone: (private) 333333 Email: [email protected] Address: 333, gamma street Tags: [school][friends] | ||
|| =================================================== | ||
|| Enter command: || [Command entered: delete] | ||
|| Invalid command format! | ||
|| delete: Deletes the person identified by the index number used in the last person listing. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
# should show appropriate message when no listing has happened yet | ||
delete 1 | ||
favourite 1 | ||
view 1 | ||
viewall 1 | ||
|
||
|
@@ -106,6 +107,22 @@ | |
# find multiple with some keywords | ||
find Charlie Betsy | ||
|
||
########################################################## | ||
# test favourite person command | ||
########################################################## | ||
|
||
# last active view: [1] betsy [2] charlie | ||
|
||
# should catch invalid args format | ||
favourite | ||
favourite should be only one number | ||
|
||
# should catch invalid index | ||
favourite -1 | ||
favourite 0 | ||
favourite 3 | ||
favourite 2 | ||
|
||
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. Good that I/O testing is updated |
||
########################################################## | ||
# test delete person command | ||
########################################################## | ||
|
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.
Substantial updating of UG while keeping to its original format, well done.