forked from nus-cs2103-AY2425S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from volleyballkickedme/nric-indexing
Nric indexing
- Loading branch information
Showing
23 changed files
with
503 additions
and
346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,6 @@ | |
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.util.CollectionUtil; | ||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
|
@@ -45,17 +44,17 @@ public class EditCommand extends Command { | |
|
||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the person identified " | ||
+ "by the index number used in the displayed person list. " | ||
+ "by the patient's NRIC. " | ||
+ "Existing values will be overwritten by the input values.\n" | ||
+ "Parameters: INDEX (must be a positive integer) " | ||
+ "Parameters: NRIC " | ||
+ "[" + PREFIX_NAME + "NAME] " | ||
+ "[" + PREFIX_PHONE + "PHONE] " | ||
+ "[" + PREFIX_EMAIL + "EMAIL] " | ||
+ "[" + PREFIX_NRIC + "NRIC] " | ||
+ "[" + PREFIX_ADDRESS + "ADDRESS] " | ||
+ "[" + PREFIX_TAG + "TAG]..." | ||
+ "[" + PREFIX_APPOINTMENT + "APPOINTMENT]\n" | ||
+ "Example: " + COMMAND_WORD + " 1 " | ||
+ "Example: " + COMMAND_WORD + " S1234567A " | ||
+ PREFIX_PHONE + "91234567 " | ||
+ PREFIX_EMAIL + "[email protected]" | ||
+ PREFIX_NRIC + "S1231231D"; | ||
|
@@ -64,18 +63,20 @@ public class EditCommand extends Command { | |
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; | ||
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book."; | ||
|
||
private final Index index; | ||
//private final Index index; | ||
private final Nric nric; | ||
private final EditPersonDescriptor editPersonDescriptor; | ||
|
||
/** | ||
* @param index of the person in the filtered person list to edit | ||
* @param nric of the person in the filtered person list to edit | ||
* @param editPersonDescriptor details to edit the person with | ||
*/ | ||
public EditCommand(Index index, EditPersonDescriptor editPersonDescriptor) { | ||
requireNonNull(index); | ||
public EditCommand(Nric nric, EditPersonDescriptor editPersonDescriptor) { | ||
requireNonNull(nric); | ||
requireNonNull(editPersonDescriptor); | ||
|
||
this.index = index; | ||
//this.index = index; | ||
this.nric = nric; | ||
this.editPersonDescriptor = new EditPersonDescriptor(editPersonDescriptor); | ||
} | ||
|
||
|
@@ -84,20 +85,24 @@ public CommandResult execute(Model model) throws CommandException { | |
requireNonNull(model); | ||
List<Person> lastShownList = model.getFilteredPersonList(); | ||
|
||
if (index.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
Optional<Person> personWithMatchingNric = lastShownList.stream() | ||
.filter(person -> nric.equals(person.getNric())) | ||
.findFirst(); | ||
|
||
Person personToEdit = lastShownList.get(index.getZeroBased()); | ||
Person editedPerson = createEditedPerson(personToEdit, editPersonDescriptor); | ||
if (personWithMatchingNric.isPresent()) { | ||
Person personToEdit = personWithMatchingNric.get(); | ||
Person editedPerson = createEditedPerson(personToEdit, editPersonDescriptor); | ||
|
||
if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_PERSON); | ||
} | ||
if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_PERSON); | ||
} | ||
|
||
model.setPerson(personToEdit, editedPerson); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson))); | ||
model.setPerson(personToEdit, editedPerson); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson))); | ||
} else { | ||
throw new CommandException(Messages.MESSAGE_NO_PERSON_FOUND); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -133,14 +138,14 @@ public boolean equals(Object other) { | |
} | ||
|
||
EditCommand otherEditCommand = (EditCommand) other; | ||
return index.equals(otherEditCommand.index) | ||
return nric.equals(otherEditCommand.nric) | ||
&& editPersonDescriptor.equals(otherEditCommand.editPersonDescriptor); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("index", index) | ||
.add("nric", nric) | ||
.add("editPersonDescriptor", editPersonDescriptor) | ||
.toString(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.