-
Notifications
You must be signed in to change notification settings - Fork 35
[W5][M11-1]Wang Jiannan #25
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
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,77 @@ | ||
| package seedu.addressbook.commands; | ||
|
|
||
| import seedu.addressbook.common.Messages; | ||
| import seedu.addressbook.data.exception.IllegalValueException; | ||
| import seedu.addressbook.data.person.*; | ||
| import seedu.addressbook.data.person.UniquePersonList.DuplicatePersonException; | ||
| import seedu.addressbook.data.person.UniquePersonList.PersonNotFoundException; | ||
| import seedu.addressbook.data.tag.Tag; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| *Edit the particulars of a contact in the addressBook | ||
| */ | ||
| public class EditCommand extends Command{ | ||
| public static final String COMMAND_WORD = "edit"; | ||
| public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits a contact in the address book. " | ||
|
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. 👍 for updating the in-app help |
||
| + "Enter the index of the contact to be edited,followed by a '/ '.\n" | ||
| + "If the contact exists, enter the new particulars of this contact in the correct format.\n" | ||
| + "Contact details can be marked private by prepending 'p' to the prefix.\n" | ||
| + "Parameters: NAME [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...\n" | ||
| + "Example: " + COMMAND_WORD | ||
| + " John Doe p/98765432 e/johnd@gmail.com a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney"; | ||
|
|
||
| public static final String MESSAGE_SUCCESS = "Contact is edited: %1$s"; | ||
| //public static final String MESSAGE_NONEXISTENT_PERSON = "This person does not exist in the address book"; | ||
|
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. Eliminate unused code and do not retain them commented, you can always get it back from previous versions if necessary. |
||
|
|
||
| private final Person toEdit; | ||
|
|
||
| /** | ||
| * Convenience constructor using raw values. | ||
| * | ||
| * @throws IllegalValueException if any of the raw values are invalid | ||
| */ | ||
|
|
||
| public EditCommand(int targetVisibleIndex,String name, | ||
| String phone, boolean isPhonePrivate, | ||
| String email, boolean isEmailPrivate, | ||
| String address, boolean isAddressPrivate, | ||
| Set<String> tags) throws IllegalValueException { | ||
|
|
||
| final Set<Tag> tagSet = new HashSet<>(); | ||
| for (String tagName : tags) { | ||
| tagSet.add(new Tag(tagName)); | ||
| } | ||
| setTargetIndex(targetVisibleIndex); | ||
|
|
||
| this.toEdit = new Person( | ||
| new Name(name), | ||
| new Phone(phone, isPhonePrivate), | ||
| new Email(email, isEmailPrivate), | ||
| new Address(address, isAddressPrivate), | ||
| tagSet | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public CommandResult execute() { | ||
| try { | ||
|
|
||
| final ReadOnlyPerson target = getTargetPerson(); | ||
| System.out.println("fk"); | ||
|
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. Inappropriate code! Use the debugger instead to trace the program flow! |
||
| addressBook.removePerson(target); | ||
|
|
||
| addressBook.addPerson(toEdit); | ||
| return new CommandResult(MESSAGE_SUCCESS); | ||
| } catch (IndexOutOfBoundsException ie) { | ||
| return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
| } catch (PersonNotFoundException pnfe) { | ||
| return new CommandResult(Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK); | ||
| } | ||
| catch (DuplicatePersonException dpethisisuseless){ | ||
|
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. Coding standard violation here. (2 counts!, can you identify them?) |
||
| return new CommandResult("DuplicationPersonException thrown,never gonna happen though"); | ||
| } | ||
| } | ||
| } | ||
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.
Do not import everything using
*, import only necessary classes