-
Notifications
You must be signed in to change notification settings - Fork 4
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
Modify existing feature: add member details (add) #46
Changes from 1 commit
c5c3bc1
38529eb
09054d9
2fac5b4
e189d61
f7fbef7
2a01c04
0ef9be2
8136db8
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 |
---|---|---|
|
@@ -8,11 +8,11 @@ title: "Tutorial: Removing Fields" | |
> — Antoine de Saint-Exupery | ||
|
||
When working on an existing code base, you will most likely find that some features that are no longer necessary. | ||
This tutorial aims to give you some practice on such a code 'removal' activity by removing the `address` field from `Person` class. | ||
This tutorial aims to give you some practice on such a code 'removal' activity by removing the `telegram` field from `Person` class. | ||
|
||
<div markdown="span" class="alert alert-success"> | ||
|
||
**If you have done the [Add `remark` command tutorial](AddRemark.html) already**, you should know where the code had to be updated to add the field `remark`. From that experience, you can deduce where the code needs to be changed to _remove_ that field too. The removing of the `address` field can be done similarly. | ||
**If you have done the [Add `remark` command tutorial](AddRemark.html) already**, you should know where the code had to be updated to add the field `remark`. From that experience, you can deduce where the code needs to be changed to _remove_ that field too. The removing of the `telegram` field can be done similarly. | ||
<br> | ||
<br> | ||
However, if you have no such prior knowledge, removing a field can take a quite a bit of detective work. This tutorial takes you through that process. **At least have a read even if you don't actually do the steps yourself.** | ||
|
@@ -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 `telegram` field in `Person` is actually an instance of the `seedu.address.model.person.Telegrams` 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` | ||
|
||
 | ||
|
@@ -41,18 +41,18 @@ Remove usages of `Address` by performing `Safe Delete`s on each entry i.e., doub | |
|
||
Let’s try removing references to `Address` in `EditPersonDescriptor`. | ||
|
||
1. Safe delete the field `address` in `EditPersonDescriptor`. | ||
1. Safe delete the field `telegram` in `EditPersonDescriptor`. | ||
|
||
1. Select `Yes` when prompted to remove getters and setters. | ||
|
||
1. Select `View Usages` again.<br> | ||
 | ||
|
||
1. Remove the usages of `address` and select `Do refactor` when you are done. | ||
1. Remove the usages of `telegram` and select `Do refactor` when you are done. | ||
|
||
<div markdown="span" class="alert alert-primary"> | ||
|
||
:bulb: **Tip:** Removing usages may result in errors. Exercise discretion and fix them. For example, removing the `address` field from the `Person` class will require you to modify its constructor. | ||
:bulb: **Tip:** Removing usages may result in errors. Exercise discretion and fix them. For example, removing the `telegram` field from the `Person` class will require you to modify its constructor. | ||
</div> | ||
|
||
1. Repeat the steps for the remaining usages of `Address` | ||
|
@@ -61,11 +61,11 @@ After you are done, verify that the application still works by compiling and run | |
|
||
### Manual refactoring | ||
|
||
Unfortunately, there are usages of `Address` that IntelliJ IDEA cannot identify. You can find them by searching for instances of the word `address` in your code (`Edit` \> `Find` \> `Find in path`). | ||
Unfortunately, there are usages of `Address` that IntelliJ IDEA cannot identify. You can find them by searching for instances of the word `telegram` in your code (`Edit` \> `Find` \> `Find in path`). | ||
|
||
Places of interest to look out for would be resources used by the application. `main/resources` contains images and `fxml` files used by the application and `test/resources` contains test data. For example, there is a `$address` in each `PersonCard` that has not been removed nor identified. | ||
Places of interest to look out for would be resources used by the application. `main/resources` contains images and `fxml` files used by the application and `test/resources` contains test data. For example, there is a `$telegram` in each `PersonCard` that has not been removed nor identified. | ||
|
||
 | ||
 | ||
|
||
A quick look at the `PersonCard` class and its `fxml` file quickly reveals why it slipped past the automated refactoring. | ||
|
||
|
@@ -74,7 +74,7 @@ A quick look at the `PersonCard` class and its `fxml` file quickly reveals why i | |
``` java | ||
... | ||
@FXML | ||
private Label address; | ||
private Label telegram; | ||
... | ||
``` | ||
|
||
|
@@ -83,7 +83,7 @@ private Label address; | |
``` xml | ||
... | ||
<Label fx:id="phone" styleClass="cell_small_label" text="\$phone" /> | ||
<Label fx:id="address" styleClass="cell_small_label" text="\$address" /> | ||
<Label fx:id="telegram" styleClass="cell_small_label" text="\$telegram" /> | ||
<Label fx:id="email" styleClass="cell_small_label" text="\$email" /> | ||
... | ||
``` | ||
|
@@ -94,7 +94,7 @@ After removing the `Label`, we can proceed to formally test our code. If everyth | |
|
||
At this point, your application is working as intended and all your tests are passing. What’s left to do is to clean up references to `Address` in test data and documentation. | ||
|
||
In `src/test/data/`, data meant for testing purposes are stored. While keeping the `address` field in the json files does not cause the tests to fail, it is not good practice to let cruft from old features accumulate. | ||
In `src/test/data/`, data meant for testing purposes are stored. While keeping the `telegram` field in the json files does not cause the tests to fail, it is not good practice to let cruft from old features accumulate. | ||
|
||
**`invalidPersonAddressBook.json`:** | ||
|
||
|
@@ -104,9 +104,9 @@ In `src/test/data/`, data meant for testing purposes are stored. While keeping t | |
"name": "Person with invalid name field: Ha!ns Mu@ster", | ||
"phone": "9482424", | ||
"email": "hans@example.com", | ||
"address": "4th street" | ||
"telegram": "4th street" | ||
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. Needs update |
||
} ] | ||
} | ||
``` | ||
|
||
You can go through each individual `json` file and manually remove the `address` field. | ||
You can go through each individual `json` file and manually remove the `telegram` field. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ In our case, we would want to begin the tracing at the very point where the App | |
|
||
<img src="../images/ArchitectureSequenceDiagram.png" width="550" /> | ||
|
||
According to the sequence diagram you saw earlier (and repeated above for reference), the `UI` component yields control to the `Logic` component through a method named `execute`. Searching through the code base for an `execute()` method that belongs to the `Logic` component yields a promising candidate in `seedu.address.logic.Logic`. | ||
According to the sequence diagram you saw earlier (and repeated above for reference), the `UI` component yields control to the `Logic` component through a method named `execute`. Searching through the code base for an `execute()` method that belongs to the `Logic` component yields a promising candidate in `seedu.telegram.logic.Logic`. | ||
|
||
<img src="../images/tracing/searchResultsForExecuteMethod.png" /> | ||
|
||
|
@@ -48,7 +48,7 @@ According to the sequence diagram you saw earlier (and repeated above for refere | |
:bulb: **Intellij Tip:** The ['**Search Everywhere**' feature](https://www.jetbrains.com/help/idea/searching-everywhere.html) can be used here. In particular, the '**Find Symbol**' ('Symbol' here refers to methods, variables, classes etc.) variant of that feature is quite useful here as we are looking for a _method_ named `execute`, not simply the text `execute`. | ||
</div> | ||
|
||
A quick look at the `seedu.address.logic.Logic` (an extract given below) confirms that this indeed might be what we’re looking for. | ||
A quick look at the `seedu.telegram.logic.Logic` (an extract given below) confirms that this indeed might be what we’re looking for. | ||
|
||
```java | ||
public interface Logic { | ||
|
@@ -292,10 +292,10 @@ Here are some quick questions you can try to answer based on your execution path | |
|
||
2. Allow `delete` to remove more than one index at a time | ||
|
||
3. Save the address book in the CSV format instead | ||
3. Save the telegram book in the CSV format instead | ||
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. Be careful not to accidentally refactor address book into telegram book. We should probably rename address book to ForYourInterest some time soon. |
||
|
||
4. Add a new command | ||
|
||
5. Add a new field to `Person` | ||
|
||
6. Add a new entity to the address book | ||
6. Add a new entity to the telegram 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. Be careful not to accidentally refactor address book into telegram book |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TELEGRAM; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; | ||
|
@@ -19,7 +19,7 @@ | |
import seedu.address.commons.util.CollectionUtil; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Address; | ||
import seedu.address.model.person.Telegram; | ||
import seedu.address.model.person.Email; | ||
import seedu.address.model.person.Name; | ||
import seedu.address.model.person.Person; | ||
|
@@ -40,7 +40,7 @@ public class EditCommand extends Command { | |
+ "[" + PREFIX_NAME + "NAME] " | ||
+ "[" + PREFIX_PHONE + "PHONE] " | ||
+ "[" + PREFIX_EMAIL + "EMAIL] " | ||
+ "[" + PREFIX_ADDRESS + "ADDRESS] " | ||
+ "[" + PREFIX_TELEGRAM + "TELEGRAM] " | ||
+ "[" + PREFIX_TAG + "TAG]...\n" | ||
+ "Example: " + COMMAND_WORD + " 1 " | ||
+ PREFIX_PHONE + "91234567 " | ||
|
@@ -96,10 +96,10 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript | |
Name updatedName = editPersonDescriptor.getName().orElse(personToEdit.getName()); | ||
Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone()); | ||
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail()); | ||
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress()); | ||
Telegram updatedTelegram = editPersonDescriptor.getAddress().orElse(personToEdit.getTelegram()); | ||
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); | ||
|
||
return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags); | ||
return new Person(updatedName, updatedPhone, updatedEmail, updatedTelegram, updatedTags); | ||
} | ||
|
||
@Override | ||
|
@@ -128,7 +128,7 @@ public static class EditPersonDescriptor { | |
private Name name; | ||
private Phone phone; | ||
private Email email; | ||
private Address address; | ||
private Telegram telegram; | ||
private Set<Tag> tags; | ||
|
||
public EditPersonDescriptor() {} | ||
|
@@ -141,15 +141,15 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { | |
setName(toCopy.name); | ||
setPhone(toCopy.phone); | ||
setEmail(toCopy.email); | ||
setAddress(toCopy.address); | ||
setAddress(toCopy.telegram); | ||
setTags(toCopy.tags); | ||
} | ||
|
||
/** | ||
* Returns true if at least one field is edited. | ||
*/ | ||
public boolean isAnyFieldEdited() { | ||
return CollectionUtil.isAnyNonNull(name, phone, email, address, tags); | ||
return CollectionUtil.isAnyNonNull(name, phone, email, telegram, tags); | ||
} | ||
|
||
public void setName(Name name) { | ||
|
@@ -176,12 +176,12 @@ public Optional<Email> getEmail() { | |
return Optional.ofNullable(email); | ||
} | ||
|
||
public void setAddress(Address address) { | ||
this.address = address; | ||
public void setAddress(Telegram telegram) { | ||
this.telegram = telegram; | ||
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. Please refactor the name of this method as well to something like |
||
} | ||
|
||
public Optional<Address> getAddress() { | ||
return Optional.ofNullable(address); | ||
public Optional<Telegram> getAddress() { | ||
return Optional.ofNullable(telegram); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TELEGRAM; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; | ||
|
@@ -12,11 +12,8 @@ | |
|
||
import seedu.address.logic.commands.AddCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.person.Address; | ||
import seedu.address.model.person.Email; | ||
import seedu.address.model.person.Name; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.person.Phone; | ||
import seedu.address.model.person.*; | ||
import seedu.address.model.person.Telegram; | ||
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. Try not to use wild card import, it will fail the checkstyle I believe |
||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
|
@@ -31,20 +28,20 @@ public class AddCommandParser implements Parser<AddCommand> { | |
*/ | ||
public AddCommand parse(String args) throws ParseException { | ||
ArgumentMultimap argMultimap = | ||
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG); | ||
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_TELEGRAM, PREFIX_TAG); | ||
|
||
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL) | ||
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_TELEGRAM, PREFIX_PHONE, PREFIX_EMAIL) | ||
|| !argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); | ||
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()); | ||
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); | ||
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); | ||
Telegram telegram = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_TELEGRAM).get()); | ||
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); | ||
|
||
Person person = new Person(name, phone, email, address, tagList); | ||
Person person = new Person(name, phone, email, telegram, tagList); | ||
|
||
return new AddCommand(person); | ||
} | ||
|
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.
I don't think you renamed the
address.png
totelegram.png
Since you're on this, perhaps you can change the
address.png
file totelegram.png
and use this image that has the updated ui mockup