-
Notifications
You must be signed in to change notification settings - Fork 141
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.11r][W15-B3] Pham Vu Hung #775
base: master
Are you sure you want to change the base?
Changes from all commits
950d379
eee08a1
552f46b
275cc81
7292461
2ff07af
8e3347e
c068d47
2ece011
151fc72
2226fc9
d275881
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 |
---|---|---|
|
@@ -34,10 +34,29 @@ Examples: | |
* `add John Doe p/98765432 e/[email protected] a/John street, block 123, #01-01` | ||
* `add Betsy Crowe pp/1234567 e/[email protected] pa/Newgate Prison t/criminal t/friend` | ||
|
||
## Editing a person : `edit` | ||
Edits the specified person from the address book.<br> | ||
Format: `edit INDEX [p]p/PHONE_NUMBER [p]e/EMAIL [p]a/ADDRESS [t/TAG]...` | ||
|
||
> Edits the person at the specified `INDEX`. | ||
The index refers to the index number shown in the most recent listing. | ||
|
||
Examples: | ||
* `list`<br> | ||
`edit 2 pp/999 pe/[email protected] pa/somewhere t/secretive`<br> | ||
Edits the 2nd person in the address book. | ||
* `find Betsy`<br> | ||
`edit 1 pp/999 pe/[email protected] pa/somewhere t/secretive`<br> | ||
Edits the 1st person in the results of the `find` command. | ||
|
||
## Listing all persons : `list` | ||
Shows a list of all persons in the address book.<br> | ||
Format: `list` | ||
|
||
## Sorting all persons: `sort` | ||
Sorts the address book by name in ascending order.<br> | ||
Format: `sort` | ||
|
||
## Finding all persons containing any keyword in their name: `find` | ||
Finds persons whose names contain any of the given keywords.<br> | ||
Format: `find KEYWORD [MORE_KEYWORDS]` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package seedu.addressbook.commands; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import seedu.addressbook.common.Messages; | ||
import seedu.addressbook.data.exception.IllegalValueException; | ||
import seedu.addressbook.data.person.*; | ||
import seedu.addressbook.data.person.UniquePersonList.PersonNotFoundException; | ||
import seedu.addressbook.data.tag.Tag; | ||
import seedu.addressbook.data.tag.UniqueTagList; | ||
|
||
|
||
/** | ||
* Edits a person identified using it's last displayed index from the address book. | ||
*/ | ||
public class EditCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "edit"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" | ||
+ "Edits the person identified by the index number used in the last person listing.\n\t" | ||
+ "Parameters: INDEX [p]p/PHONE [p]e/EMAIL [p]a/ADDRESS [t/TAG]...\n\t" | ||
+ "Example: " + COMMAND_WORD | ||
+ " 1 p/98765432 e/[email protected] a/311, Clementi Ave 2, #02-25 t/friends t/owesMoney"; | ||
|
||
public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book"; | ||
|
||
private final Person toEdit; | ||
|
||
/** | ||
* Convenience constructor using raw values. | ||
* | ||
* @throws IllegalValueException if any of the raw values are invalid | ||
*/ | ||
public EditCommand(int targetIndex, | ||
String phone, boolean isPhonePrivate, | ||
String email, boolean isEmailPrivate, | ||
String address, boolean isAddressPrivate, | ||
Set<String> tags) throws IllegalValueException { | ||
super(targetIndex); | ||
final Set<Tag> tagSet = new HashSet<>(); | ||
for (String tagName : tags) { | ||
tagSet.add(new Tag(tagName)); | ||
} | ||
this.toEdit = new Person( | ||
new Name("dummy"), | ||
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. Could use the index to retrieve the name of |
||
new Phone(phone, isPhonePrivate), | ||
new Email(email, isEmailPrivate), | ||
new Address(address, isAddressPrivate), | ||
new UniqueTagList(tagSet) | ||
); | ||
} | ||
|
||
public ReadOnlyPerson getPerson() { | ||
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. Is this really necessary? |
||
return toEdit; | ||
} | ||
|
||
@Override | ||
public CommandResult execute() { | ||
try { | ||
final ReadOnlyPerson target = getTargetPerson(); | ||
toEdit.changeName(target.getName()); | ||
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. There shouldn't be a random setter() just to cater for editting. |
||
addressBook.editPerson(target, toEdit); | ||
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, toEdit)); | ||
|
||
} catch (IndexOutOfBoundsException ie) { | ||
return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} catch (PersonNotFoundException pnfe) { | ||
return new CommandResult(Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package seedu.addressbook.commands; | ||
|
||
import seedu.addressbook.data.exception.IllegalValueException; | ||
import seedu.addressbook.data.person.*; | ||
import seedu.addressbook.data.tag.Tag; | ||
import seedu.addressbook.data.tag.UniqueTagList; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** | ||
* Sorts the address book by name in ascending order. | ||
*/ | ||
public class SortCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "sort"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" | ||
+ "Sorts the address book by name in ascending order, then display it.\n\t" | ||
+ "Example: " + COMMAND_WORD; | ||
|
||
public static final String MESSAGE_SUCCESS = "Address book is sorted as above.\n\n"; | ||
|
||
@Override | ||
public CommandResult execute() { | ||
addressBook.sort(); | ||
List<ReadOnlyPerson> allPersons = addressBook.getAllPersons().immutableListView(); | ||
return new CommandResult(MESSAGE_SUCCESS | ||
+ getMessageForPersonListShownSummary(allPersons), allPersons); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,19 @@ public void addPerson(Person toAdd) throws DuplicatePersonException { | |
allPersons.add(toAdd); | ||
} | ||
|
||
public void editPerson(ReadOnlyPerson target, Person editedPerson) throws PersonNotFoundException { | ||
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. Every public facing method should have a method header according to JavaDoc standards. |
||
syncTagsWithMasterList(editedPerson); | ||
allPersons.editPerson(target, editedPerson); | ||
} | ||
|
||
|
||
/** | ||
* Sorts the address book by name in ascending order. | ||
*/ | ||
public void sort() { | ||
allPersons.sort(); | ||
} | ||
|
||
/** | ||
* Checks if an equivalent person exists in the address book. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package seedu.addressbook.data.person; | ||
|
||
import seedu.addressbook.data.exception.IllegalValueException; | ||
import seedu.addressbook.data.tag.UniqueTagList; | ||
|
||
import java.util.Objects; | ||
|
@@ -39,6 +40,15 @@ public Name getName() { | |
return name; | ||
} | ||
|
||
/** | ||
* Change the name of a person | ||
* | ||
* @param newName | ||
*/ | ||
public void changeName(Name newName) { | ||
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. This should not be allowed. |
||
name = newName; | ||
} | ||
|
||
@Override | ||
public Phone getPhone() { | ||
return phone; | ||
|
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.
You should avoid importing by
*