Skip to content

Commit

Permalink
Refactor person to contact
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ-Lee01 committed Oct 5, 2023
1 parent 4895e9d commit c5b778d
Show file tree
Hide file tree
Showing 52 changed files with 461 additions and 458 deletions.
20 changes: 10 additions & 10 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ How the `Logic` component works:

1. When `Logic` is called upon to execute a command, it is passed to an `AddressBookParser` object which in turn creates a parser that matches the command (e.g., `DeleteCommandParser`) and uses it to parse the command.
1. This results in a `Command` object (more precisely, an object of one of its subclasses e.g., `DeleteCommand`) which is executed by the `LogicManager`.
1. The command can communicate with the `Model` when it is executed (e.g. to delete a person).
1. The command can communicate with the `Model` when it is executed (e.g. to delete a contact).
1. The result of the command execution is encapsulated as a `CommandResult` object which is returned back from `Logic`.

Here are the other classes in `Logic` (omitted from the class diagram above) that are used for parsing a user command:
Expand Down Expand Up @@ -172,19 +172,19 @@ Step 1. The user launches the application for the first time. The `VersionedAddr

![UndoRedoState0](images/UndoRedoState0.png)

Step 2. The user executes `delete 5` command to delete the 5th person in the address book. The `delete` command calls `Model#commitAddressBook()`, causing the modified state of the address book after the `delete 5` command executes to be saved in the `addressBookStateList`, and the `currentStatePointer` is shifted to the newly inserted address book state.
Step 2. The user executes `delete 5` command to delete the 5th contact in the address book. The `delete` command calls `Model#commitAddressBook()`, causing the modified state of the address book after the `delete 5` command executes to be saved in the `addressBookStateList`, and the `currentStatePointer` is shifted to the newly inserted address book state.

![UndoRedoState1](images/UndoRedoState1.png)

Step 3. The user executes `add n/David …​` to add a new person. The `add` command also calls `Model#commitAddressBook()`, causing another modified address book state to be saved into the `addressBookStateList`.
Step 3. The user executes `add n/David …​` to add a new contact. The `add` command also calls `Model#commitAddressBook()`, causing another modified address book state to be saved into the `addressBookStateList`.

![UndoRedoState2](images/UndoRedoState2.png)

<div markdown="span" class="alert alert-info">:information_source: **Note:** If a command fails its execution, it will not call `Model#commitAddressBook()`, so the address book state will not be saved into the `addressBookStateList`.

</div>

Step 4. The user now decides that adding the person was a mistake, and decides to undo that action by executing the `undo` command. The `undo` command will call `Model#undoAddressBook()`, which will shift the `currentStatePointer` once to the left, pointing it to the previous address book state, and restores the address book to that state.
Step 4. The user now decides that adding the contact was a mistake, and decides to undo that action by executing the `undo` command. The `undo` command will call `Model#undoAddressBook()`, which will shift the `currentStatePointer` once to the left, pointing it to the previous address book state, and restores the address book to that state.

![UndoRedoState3](images/UndoRedoState3.png)

Expand Down Expand Up @@ -229,7 +229,7 @@ The following activity diagram summarizes what happens when a user executes a ne

* **Alternative 2:** Individual command knows how to undo/redo by
itself.
* Pros: Will use less memory (e.g. for `delete`, just save the person being deleted).
* Pros: Will use less memory (e.g. for `delete`, just save the contact being deleted).
* Cons: We must ensure that the implementation of each individual command are correct.

_{more aspects and alternatives to be added}_
Expand Down Expand Up @@ -317,7 +317,7 @@ Priorities: High (must have) - `* * *`, Medium (nice to have) - `* *`, Low (unli
### Non-Functional Requirements

1. Should work on any _mainstream OS_ as long as it has Java `11` or above installed.
2. Should be able to hold up to 1000 persons without a noticeable sluggishness in performance for typical usage.
2. Should be able to hold up to 1000 contacts without a noticeable sluggishness in performance for typical usage.
3. A user with above average typing speed for regular English text (i.e. not code, not system admin commands) should be able to accomplish most of the tasks faster using commands than using the mouse.
4. A user with familiarity with common Unix/Linux shell command syntax should find the syntax of SJ++ to match their habits and easy to pick up.
5. The command syntax should not conflict with something that a user could plausibly use as legitimate data input.
Expand Down Expand Up @@ -356,17 +356,17 @@ testers are expected to do more *exploratory* testing.

1. _{ more test cases …​ }_

### Deleting a person
### Deleting a contact

1. Deleting a person while all persons are being shown
1. Deleting a contact while all contacts are being shown

1. Prerequisites: List all persons using the `list` command. Multiple persons in the list.
1. Prerequisites: List all contacts using the `list` command. Multiple contacts in the list.

1. Test case: `delete 1`<br>
Expected: First contact is deleted from the list. Details of the deleted contact shown in the status message. Timestamp in the status bar is updated.

1. Test case: `delete 0`<br>
Expected: No person is deleted. Error details shown in the status message. Status bar remains the same.
Expected: No contact is deleted. Error details shown in the status message. Status bar remains the same.

1. Other incorrect delete commands to try: `delete`, `delete x`, `...` (where x is larger than the list size)<br>
Expected: Similar to previous.
Expand Down
10 changes: 5 additions & 5 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,18 @@ Examples:

_{To be updated...}_

Deletes the specified person from the address book.
Deletes the specified contact from the address book.

Format: `delete INDEX`


* Deletes the person at the specified `INDEX`.
* The index refers to the index number shown in the displayed person list.
* Deletes the contact at the specified `INDEX`.
* The index refers to the index number shown in the displayed contact list.
* The index **must be a positive integer** 1, 2, 3, ...

Examples:
* `list` followed by `delete 2` deletes the 2nd person in the address book.
* `find Betsy` followed by `delete 1` deletes the 1st person in the results of the `find` command.
* `list` followed by `delete 2` deletes the 2nd contact in the address book.
* `find Betsy` followed by `delete 1` deletes the 1st contact in the results of the `find` command.


### Clearing all entries: `clear`
Expand Down
38 changes: 19 additions & 19 deletions docs/tutorials/AddRemark.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ package seedu.address.logic.commands;
import seedu.address.model.Model;

/**
* Changes the remark of an existing person in the address book.
* Changes the remark of an existing contact in the address book.
*/
public class RemarkCommand extends Command {

Expand Down Expand Up @@ -65,8 +65,8 @@ Following the convention in other commands, we add relevant messages as constant

``` java
public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Edits the remark of the person identified "
+ "by the index number used in the last person listing. "
+ ": Edits the remark of the contact identified "
+ "by the index number used in the last contact listing. "
+ "Existing remark will be overwritten by the input.\n"
+ "Parameters: INDEX (must be a positive integer) "
+ "r/ [REMARK]\n"
Expand Down Expand Up @@ -101,8 +101,8 @@ public class RemarkCommand extends Command {
private final String remark;

/**
* @param index of the person in the filtered person list to edit the remark
* @param remark of the person to be updated to
* @param index of the contact in the filtered contact list to edit the remark
* @param remark of the contact to be updated to
*/
public RemarkCommand(Index index, String remark) {
requireAllNonNull(index, remark);
Expand Down Expand Up @@ -223,11 +223,11 @@ If you are stuck, check out the sample

## Add `Remark` to the model

Now that we have all the information that we need, let’s lay the groundwork for propagating the remarks added into the in-memory storage of person data. We achieve that by working with the `Person` model. Each field in a Person is implemented as a separate class (e.g. a `Name` object represents the person’s name). That means we should add a `Remark` class so that we can use a `Remark` object to represent a remark given to a person.
Now that we have all the information that we need, let’s lay the groundwork for propagating the remarks added into the in-memory storage of contact data. We achieve that by working with the `Person` model. Each field in a Person is implemented as a separate class (e.g. a `Name` object represents the contact’s name). That means we should add a `Remark` class so that we can use a `Remark` object to represent a remark given to a contact.

### Add a new `Remark` class

Create a new `Remark` in `seedu.address.model.person`. Since a `Remark` is a field that is similar to `Address`, we can reuse a significant bit of code.
Create a new `Remark` in `seedu.address.model.contact`. Since a `Remark` is a field that is similar to `Address`, we can reuse a significant bit of code.

A copy-paste and search-replace later, you should have something like [this](https://github.com/se-edu/addressbook-level3/commit/4516e099699baa9e2d51801bd26f016d812dedcc#diff-41bb13c581e280c686198251ad6cc337cd5e27032772f06ed9bf7f1440995ece). Note how `Remark` has no constrains and thus does not require input
validation.
Expand All @@ -238,7 +238,7 @@ Let’s change `RemarkCommand` and `RemarkCommandParser` to use the new `Remark`

## Add a placeholder element for remark to the UI

Without getting too deep into `fxml`, let’s go on a 5 minute adventure to get some placeholder text to show up for each person.
Without getting too deep into `fxml`, let’s go on a 5 minute adventure to get some placeholder text to show up for each contact.

Simply add the following to [`seedu.address.ui.PersonCard`](https://github.com/se-edu/addressbook-level3/commit/850b78879582f38accb05dd20c245963c65ea599#diff-639834f1e05afe2276a86372adf0fe5f69314642c2d93cfa543d614ce5a76688).

Expand Down Expand Up @@ -309,9 +309,9 @@ Just add [this one line of code!](https://github.com/se-edu/addressbook-level3/c
**`PersonCard.java`:**

``` java
public PersonCard(Person person, int displayedIndex) {
public PersonCard(Person contact, int displayedIndex) {
//...
remark.setText(person.getRemark().value);
remark.setText(contact.getRemark().value);
}
```

Expand Down Expand Up @@ -341,25 +341,25 @@ save it with `Model#setPerson()`.
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

Person personToEdit = lastShownList.get(index.getZeroBased());
Person editedPerson = new Person(
personToEdit.getName(), personToEdit.getPhone(), personToEdit.getEmail(),
personToEdit.getAddress(), remark, personToEdit.getTags());
Person contactToEdit = lastShownList.get(index.getZeroBased());
Person editedContact = new Person(
contactToEdit.getName(), contactToEdit.getPhone(), contactToEdit.getEmail(),
contactToEdit.getAddress(), remark, contactToEdit.getTags());

model.setPerson(personToEdit, editedPerson);
model.setPerson(contactToEdit, editedContact);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);

return new CommandResult(generateSuccessMessage(editedPerson));
return new CommandResult(generateSuccessMessage(editedContact));
}

/**
* Generates a command execution success message based on whether
* the remark is added to or removed from
* {@code personToEdit}.
* {@code contactToEdit}.
*/
private String generateSuccessMessage(Person personToEdit) {
private String generateSuccessMessage(Person contactToEdit) {
String message = !remark.value.isEmpty() ? MESSAGE_ADD_REMARK_SUCCESS : MESSAGE_DELETE_REMARK_SUCCESS;
return String.format(message, personToEdit);
return String.format(message, contactToEdit);
}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/RemovingFields.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ IntelliJ IDEA provides a refactoring tool that can identify *most* parts of a re

### Assisted refactoring

The `address` field in `Person` is actually an instance of the `seedu.address.model.person.Address` class. Since removing the `Address` class will break the application, we start by identifying `Address`'s usages. This allows us to see code that depends on `Address` to function properly and edit them on a case-by-case basis. Right-click the `Address` class and select `Refactor` \> `Safe Delete` through the menu.
The `address` field in `Person` is actually an instance of the `seedu.address.model.contact.Address` class. Since removing the `Address` class will break the application, we start by identifying `Address`'s usages. This allows us to see code that depends on `Address` to function properly and edit them on a case-by-case basis. Right-click the `Address` class and select `Refactor` \> `Safe Delete` through the menu.
* :bulb: To make things simpler, you can unselect the options `Search in comments and strings` and `Search for text occurrences`

![Usages detected](../images/remove/UnsafeDelete.png)
Expand Down Expand Up @@ -100,7 +100,7 @@ In `src/test/data/`, data meant for testing purposes are stored. While keeping t

```json
{
"persons": [ {
"contacts": [ {
"name": "Person with invalid name field: Ha!ns Mu@ster",
"phone": "9482424",
"email": "[email protected]",
Expand Down
20 changes: 10 additions & 10 deletions docs/tutorials/TracingCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,22 +189,22 @@ Recall from the User Guide that the `edit` command has the format: `edit INDEX [
@Override
public CommandResult execute(Model model) throws CommandException {
...
Person personToEdit = lastShownList.get(index.getZeroBased());
Person editedPerson = createEditedPerson(personToEdit, editPersonDescriptor);
if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) {
Person contactToEdit = lastShownList.get(index.getZeroBased());
Person editedContact = createEditedPerson(contactToEdit, editPersonDescriptor);
if (!contactToEdit.isSamePerson(editedContact) && model.hasPerson(editedContact)) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}
model.setPerson(personToEdit, editedPerson);
model.setPerson(contactToEdit, editedContact);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, editedPerson));
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, editedContact));
}
```

1. As suspected, `command#execute()` does indeed make changes to the `model` object. Specifically,
* it uses the `setPerson()` method (defined in the interface `Model` and implemented in `ModelManager` as per the usual pattern) to update the person data.
* it uses the `updateFilteredPersonList` method to ask the `Model` to populate the 'filtered list' with _all_ persons.<br>
FYI, The 'filtered list' is the list of persons resulting from the most recent operation that will be shown to the user immediately after. For the `edit` command, we populate it with all the persons so that the user can see the edited person along with all other persons. If this was a `find` command, we would be setting that list to contain the search results instead.<br>
To provide some context, given below is the class diagram of the `Model` component. See if you can figure out where the 'filtered list' of persons is being tracked.
* it uses the `setPerson()` method (defined in the interface `Model` and implemented in `ModelManager` as per the usual pattern) to update the contact data.
* it uses the `updateFilteredPersonList` method to ask the `Model` to populate the 'filtered list' with _all_ contacts.<br>
FYI, The 'filtered list' is the list of contacts resulting from the most recent operation that will be shown to the user immediately after. For the `edit` command, we populate it with all the contacts so that the user can see the edited contact along with all other contacts. If this was a `find` command, we would be setting that list to contain the search results instead.<br>
To provide some context, given below is the class diagram of the `Model` component. See if you can figure out where the 'filtered list' of contacts is being tracked.
<img src="../images/ModelClassDiagram.png" width="450" /><br>
* :bulb: This may be a good time to read through the [`Model` component section of the DG](../DeveloperGuide.html#model-component)

Expand All @@ -231,7 +231,7 @@ Recall from the User Guide that the `edit` command has the format: `edit INDEX [
* {@code JsonSerializableAddressBook}.
*/
public JsonSerializableAddressBook(ReadOnlyAddressBook source) {
persons.addAll(
contacts.addAll(
source.getPersonList()
.stream()
.map(JsonAdaptedPerson::new)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Person;
import seedu.address.model.person.Contact;

/**
* API of the Logic component
Expand All @@ -31,7 +31,7 @@ public interface Logic {
ReadOnlyAddressBook getAddressBook();

/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Person> getFilteredPersonList();
ObservableList<Contact> getFilteredPersonList();

/**
* Returns the user prefs' address book file path.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Person;
import seedu.address.model.person.Contact;
import seedu.address.storage.Storage;

/**
Expand Down Expand Up @@ -67,7 +67,7 @@ public ReadOnlyAddressBook getAddressBook() {
}

@Override
public ObservableList<Person> getFilteredPersonList() {
public ObservableList<Contact> getFilteredPersonList() {
return model.getFilteredPersonList();
}

Expand Down
Loading

0 comments on commit c5b778d

Please sign in to comment.