Skip to content

Commit 4254b0d

Browse files
authored
Merge pull request #76 from channne/branch-ChangePersonToStudent
Refactor `Person` to `Student`
2 parents 904930a + 93e8370 commit 4254b0d

File tree

113 files changed

+1327
-1323
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+1327
-1323
lines changed

docs/tutorials/AddRemark.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ Now that we have all the information that we need, let’s lay the groundwork fo
229229

230230
### Add a new `Remark` class
231231

232-
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.
232+
Create a new `Remark` in `seedu.address.model.student`. Since a `Remark` is a field that is similar to `Address`, we can reuse a significant bit of code.
233233

234234
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
235235
validation.

docs/tutorials/RemovingFields.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ IntelliJ IDEA provides a refactoring tool that can identify *most* parts of a re
2828

2929
### Assisted refactoring
3030

31-
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.
31+
The `address` field in `Person` is actually an instance of the `seedu.address.model.student.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.
3232
* :bulb: To make things simpler, you can unselect the options `Search in comments and strings` and `Search for text occurrences`
3333

3434
![Usages detected](../images/remove/UnsafeDelete.png)

src/main/java/seedu/address/commons/core/Messages.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class Messages {
77

88
public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
99
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
10-
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
11-
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
10+
public static final String MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX = "The student index provided is invalid";
11+
public static final String MESSAGE_STUDENTS_LISTED_OVERVIEW = "%1$d students listed!";
1212

1313
}

src/main/java/seedu/address/logic/Logic.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import seedu.address.logic.commands.exceptions.CommandException;
99
import seedu.address.logic.parser.exceptions.ParseException;
1010
import seedu.address.model.ReadOnlyAddressBook;
11-
import seedu.address.model.person.Person;
11+
import seedu.address.model.student.Student;
1212

1313
/**
1414
* API of the Logic component
@@ -31,7 +31,7 @@ public interface Logic {
3131
ReadOnlyAddressBook getAddressBook();
3232

3333
/** Returns an unmodifiable view of the filtered list of persons */
34-
ObservableList<Person> getFilteredPersonList();
34+
ObservableList<Student> getFilteredStudentList();
3535

3636
/**
3737
* Returns the user prefs' address book file path.

src/main/java/seedu/address/logic/LogicManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import seedu.address.logic.parser.exceptions.ParseException;
1515
import seedu.address.model.Model;
1616
import seedu.address.model.ReadOnlyAddressBook;
17-
import seedu.address.model.person.Person;
17+
import seedu.address.model.student.Student;
1818
import seedu.address.storage.Storage;
1919

2020
/**
@@ -60,8 +60,8 @@ public ReadOnlyAddressBook getAddressBook() {
6060
}
6161

6262
@Override
63-
public ObservableList<Person> getFilteredPersonList() {
64-
return model.getFilteredPersonList();
63+
public ObservableList<Student> getFilteredStudentList() {
64+
return model.getFilteredStudentList();
6565
}
6666

6767
@Override

src/main/java/seedu/address/logic/commands/AddCommand.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
import seedu.address.logic.commands.exceptions.CommandException;
1212
import seedu.address.model.Model;
13-
import seedu.address.model.person.Person;
14-
import seedu.address.model.person.lab.Lab;
15-
import seedu.address.model.person.lab.LabList;
13+
import seedu.address.model.student.Student;
14+
import seedu.address.model.student.lab.Lab;
15+
import seedu.address.model.student.lab.LabList;
1616

1717
/**
1818
* Adds a Student to the TAddressBook.
@@ -39,14 +39,14 @@ public class AddCommand extends Command {
3939
+ PREFIX_TAG + "owesMoney";
4040

4141
public static final String MESSAGE_SUCCESS = "New student added: %1$s";
42-
public static final String MESSAGE_DUPLICATE_PERSON = "This student already exists in the TAddressBook";
42+
public static final String MESSAGE_DUPLICATE_STUDENT = "This student already exists in the TAddressBook";
4343

44-
private final Person toAdd;
44+
private final Student toAdd;
4545

4646
/**
4747
* Creates an AddCommand to add the specified {@code Person}
4848
*/
49-
public AddCommand(Person student) {
49+
public AddCommand(Student student) {
5050
requireNonNull(student);
5151
toAdd = student;
5252
}
@@ -61,10 +61,10 @@ public CommandResult execute(Model model) throws CommandException {
6161
}
6262
toAdd.setLabs(plainLabList);
6363

64-
if (model.hasPerson(toAdd)) {
65-
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
64+
if (model.hasStudent(toAdd)) {
65+
throw new CommandException(MESSAGE_DUPLICATE_STUDENT);
6666
}
67-
model.addPerson(toAdd);
67+
model.addStudent(toAdd);
6868
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
6969
}
7070

src/main/java/seedu/address/logic/commands/AddLabCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import static java.util.Objects.requireNonNull;
44
import static seedu.address.logic.parser.CliSyntax.PREFIX_LAB;
5-
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;
5+
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_STUDENTS;
66

77
import seedu.address.logic.commands.exceptions.CommandException;
88
import seedu.address.model.Model;
9-
import seedu.address.model.person.lab.Lab;
9+
import seedu.address.model.student.lab.Lab;
1010

1111
/**
1212
* Adds a Lab to the TAddressBook.
@@ -43,7 +43,7 @@ public CommandResult execute(Model model) throws CommandException {
4343
}
4444

4545
model.addLab(toAdd);
46-
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
46+
model.updateFilteredStudentList(PREDICATE_SHOW_ALL_STUDENTS);
4747
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
4848
}
4949

src/main/java/seedu/address/logic/commands/DeleteCommand.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import seedu.address.commons.core.index.Index;
99
import seedu.address.logic.commands.exceptions.CommandException;
1010
import seedu.address.model.Model;
11-
import seedu.address.model.person.Person;
11+
import seedu.address.model.student.Student;
1212

1313
/**
1414
* Deletes a Student identified using its displayed index from the TAddressBook.
@@ -18,11 +18,11 @@ public class DeleteCommand extends Command {
1818
public static final String COMMAND_WORD = "delete";
1919

2020
public static final String MESSAGE_USAGE = COMMAND_WORD
21-
+ ": Deletes the student identified by the index number used in the displayed person list.\n"
21+
+ ": Deletes the student identified by the index number used in the displayed student list.\n"
2222
+ "Parameters: INDEX (must be a positive integer)\n"
2323
+ "Example: " + COMMAND_WORD + " 1";
2424

25-
public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted student: %1$s";
25+
public static final String MESSAGE_DELETE_STUDENT_SUCCESS = "Deleted student: %1$s";
2626

2727
private final Index targetIndex;
2828

@@ -33,15 +33,15 @@ public DeleteCommand(Index targetIndex) {
3333
@Override
3434
public CommandResult execute(Model model) throws CommandException {
3535
requireNonNull(model);
36-
List<Person> lastShownList = model.getFilteredPersonList();
36+
List<Student> lastShownList = model.getFilteredStudentList();
3737

3838
if (targetIndex.getZeroBased() >= lastShownList.size()) {
39-
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
39+
throw new CommandException(Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX);
4040
}
4141

42-
Person personToDelete = lastShownList.get(targetIndex.getZeroBased());
43-
model.deletePerson(personToDelete);
44-
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, personToDelete));
42+
Student studentToDelete = lastShownList.get(targetIndex.getZeroBased());
43+
model.deleteStudent(studentToDelete);
44+
return new CommandResult(String.format(MESSAGE_DELETE_STUDENT_SUCCESS, studentToDelete));
4545
}
4646

4747
@Override

src/main/java/seedu/address/logic/commands/EditCommand.java

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import static seedu.address.logic.parser.CliSyntax.PREFIX_STUDENTID;
88
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
99
import static seedu.address.logic.parser.CliSyntax.PREFIX_TELEGRAM;
10-
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;
10+
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_STUDENTS;
1111

1212
import java.util.Collections;
1313
import java.util.HashSet;
@@ -20,13 +20,13 @@
2020
import seedu.address.commons.util.CollectionUtil;
2121
import seedu.address.logic.commands.exceptions.CommandException;
2222
import seedu.address.model.Model;
23-
import seedu.address.model.person.Email;
24-
import seedu.address.model.person.GithubUsername;
25-
import seedu.address.model.person.Name;
26-
import seedu.address.model.person.Person;
27-
import seedu.address.model.person.StudentId;
28-
import seedu.address.model.person.Telegram;
29-
import seedu.address.model.person.lab.LabList;
23+
import seedu.address.model.student.Email;
24+
import seedu.address.model.student.GithubUsername;
25+
import seedu.address.model.student.Name;
26+
import seedu.address.model.student.Student;
27+
import seedu.address.model.student.StudentId;
28+
import seedu.address.model.student.Telegram;
29+
import seedu.address.model.student.lab.LabList;
3030
import seedu.address.model.tag.Tag;
3131

3232
/**
@@ -37,7 +37,7 @@ public class EditCommand extends Command {
3737
public static final String COMMAND_WORD = "edit";
3838

3939
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the student identified "
40-
+ "by the index number used in the displayed person list. "
40+
+ "by the index number used in the displayed student list. "
4141
+ "Existing values will be overwritten by the input values.\n"
4242
+ "Parameters: INDEX (must be a positive integer) "
4343
+ "[" + PREFIX_NAME + "NAME] "
@@ -49,51 +49,51 @@ public class EditCommand extends Command {
4949
+ "Example: " + COMMAND_WORD + " 1 "
5050
+ PREFIX_EMAIL + "johndoe@example.com";
5151

52-
public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited student: %1$s";
52+
public static final String MESSAGE_EDIT_STUDENT_SUCCESS = "Edited student: %1$s";
5353
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
54-
public static final String MESSAGE_DUPLICATE_PERSON = "This student already exists in the TAddressBook.";
54+
public static final String MESSAGE_DUPLICATE_STUDENT = "This student already exists in the TAddressBook.";
5555

5656
private final Index index;
57-
private final EditPersonDescriptor editPersonDescriptor;
57+
private final EditStudentDescriptor editStudentDescriptor;
5858

5959
/**
6060
* @param index of the Student in the filtered Student list to edit
61-
* @param editPersonDescriptor details to edit the Student with
61+
* @param editStudentDescriptor details to edit the Student with
6262
*/
63-
public EditCommand(Index index, EditPersonDescriptor editPersonDescriptor) {
63+
public EditCommand(Index index, EditStudentDescriptor editStudentDescriptor) {
6464
requireNonNull(index);
65-
requireNonNull(editPersonDescriptor);
65+
requireNonNull(editStudentDescriptor);
6666

6767
this.index = index;
68-
this.editPersonDescriptor = new EditPersonDescriptor(editPersonDescriptor);
68+
this.editStudentDescriptor = new EditStudentDescriptor(editStudentDescriptor);
6969
}
7070

7171
@Override
7272
public CommandResult execute(Model model) throws CommandException {
7373
requireNonNull(model);
74-
List<Person> lastShownList = model.getFilteredPersonList();
74+
List<Student> lastShownList = model.getFilteredStudentList();
7575

7676
if (index.getZeroBased() >= lastShownList.size()) {
77-
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
77+
throw new CommandException(Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX);
7878
}
7979

80-
Person personToEdit = lastShownList.get(index.getZeroBased());
81-
Person editedPerson = createEditedPerson(personToEdit, editPersonDescriptor);
80+
Student studentToEdit = lastShownList.get(index.getZeroBased());
81+
Student editedStudent = createEditedStudent(studentToEdit, editStudentDescriptor);
8282

83-
if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) {
84-
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
83+
if (!studentToEdit.isSameStudent(editedStudent) && model.hasStudent(editedStudent)) {
84+
throw new CommandException(MESSAGE_DUPLICATE_STUDENT);
8585
}
8686

87-
model.setPerson(personToEdit, editedPerson);
88-
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
89-
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, editedPerson));
87+
model.setStudent(studentToEdit, editedStudent);
88+
model.updateFilteredStudentList(PREDICATE_SHOW_ALL_STUDENTS);
89+
return new CommandResult(String.format(MESSAGE_EDIT_STUDENT_SUCCESS, editedStudent));
9090
}
9191

9292
/**
93-
* Creates and returns a {@code Person} with the details of {@code studentToEdit}
93+
* Creates and returns a {@code Student} with the details of {@code studentToEdit}
9494
* edited with {@code editStudentDescriptor}.
9595
*/
96-
private static Person createEditedPerson(Person studentToEdit, EditPersonDescriptor editStudentDescriptor) {
96+
private static Student createEditedStudent(Student studentToEdit, EditStudentDescriptor editStudentDescriptor) {
9797
assert studentToEdit != null;
9898

9999
Name updatedName = editStudentDescriptor.getName().orElse(studentToEdit.getName());
@@ -104,10 +104,10 @@ private static Person createEditedPerson(Person studentToEdit, EditPersonDescrip
104104
Telegram updatedTelegram = editStudentDescriptor.getTelegram().orElse(studentToEdit.getTelegram());
105105
StudentId updatedStudentId = editStudentDescriptor.getStudentId().orElse(studentToEdit.getStudentId());
106106
LabList updatedLabList = studentToEdit.getLabs();
107-
Person p = new Person(updatedName, updatedEmail, updatedTags, updatedGithubUsername, updatedTelegram,
107+
Student s = new Student(updatedName, updatedEmail, updatedTags, updatedGithubUsername, updatedTelegram,
108108
updatedStudentId);
109-
p.setLabs(updatedLabList);
110-
return p;
109+
s.setLabs(updatedLabList);
110+
return s;
111111
}
112112

113113
@Override
@@ -125,28 +125,28 @@ public boolean equals(Object other) {
125125
// state check
126126
EditCommand e = (EditCommand) other;
127127
return index.equals(e.index)
128-
&& editPersonDescriptor.equals(e.editPersonDescriptor);
128+
&& editStudentDescriptor.equals(e.editStudentDescriptor);
129129
}
130130

131131
/**
132132
* Stores the details to edit the Student with. Each non-empty field value will replace the
133133
* corresponding field value of the Student.
134134
*/
135-
public static class EditPersonDescriptor {
135+
public static class EditStudentDescriptor {
136136
private Name name;
137137
private Email email;
138138
private Set<Tag> tags;
139139
private GithubUsername githubUsername;
140140
private Telegram telegram;
141141
private StudentId studentId;
142142

143-
public EditPersonDescriptor() {}
143+
public EditStudentDescriptor() {}
144144

145145
/**
146146
* Copy constructor.
147147
* A defensive copy of {@code tags} is used internally.
148148
*/
149-
public EditPersonDescriptor(EditPersonDescriptor toCopy) {
149+
public EditStudentDescriptor(EditStudentDescriptor toCopy) {
150150
setName(toCopy.name);
151151
setEmail(toCopy.email);
152152
setTags(toCopy.tags);
@@ -227,12 +227,12 @@ public boolean equals(Object other) {
227227
}
228228

229229
// instanceof handles nulls
230-
if (!(other instanceof EditPersonDescriptor)) {
230+
if (!(other instanceof EditStudentDescriptor)) {
231231
return false;
232232
}
233233

234234
// state check
235-
EditPersonDescriptor e = (EditPersonDescriptor) other;
235+
EditStudentDescriptor e = (EditStudentDescriptor) other;
236236

237237
return getName().equals(e.getName())
238238
&& getEmail().equals(e.getEmail())

0 commit comments

Comments
 (0)