Skip to content

Commit 765aea8

Browse files
authored
Merge pull request #101 from getsquared/remark-command
Add Remark Command
2 parents f80287e + d8f769d commit 765aea8

33 files changed

+606
-111
lines changed

docs/UserGuide.md

Lines changed: 85 additions & 59 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public CommandResult execute(Model model) throws CommandException {
6969

7070
Person policyAddedPerson = new Person(personToAddPolicy.getName(), personToAddPolicy.getPhone(),
7171
personToAddPolicy.getEmail(), personToAddPolicy.getAddress(), personToAddPolicy.getBirthday(),
72-
personToAddPolicy.getPriority(), personToAddPolicy.getLastMet(), personToAddPolicy.getSchedule(),
73-
personToAddPolicy.getTags(), updatedPolicyList);
72+
personToAddPolicy.getPriority(), personToAddPolicy.getRemark(), personToAddPolicy.getLastMet(),
73+
personToAddPolicy.getSchedule(), personToAddPolicy.getTags(), updatedPolicyList);
7474

7575
model.setPerson(personToAddPolicy, policyAddedPerson);
7676
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public CommandResult execute(Model model) throws CommandException {
6565

6666
Person policyDeletedPerson = new Person(personToDeletePolicy.getName(), personToDeletePolicy.getPhone(),
6767
personToDeletePolicy.getEmail(), personToDeletePolicy.getAddress(), personToDeletePolicy.getBirthday(),
68-
personToDeletePolicy.getPriority(), personToDeletePolicy.getLastMet(),
68+
personToDeletePolicy.getPriority(), personToDeletePolicy.getRemark(), personToDeletePolicy.getLastMet(),
6969
personToDeletePolicy.getSchedule(), personToDeletePolicy.getTags(), updatedPolicyList);
7070

7171
model.setPerson(personToDeletePolicy, policyDeletedPerson);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import seedu.address.model.person.Phone;
3333
import seedu.address.model.person.PolicyList;
3434
import seedu.address.model.person.Priority;
35+
import seedu.address.model.person.Remark;
3536
import seedu.address.model.person.Schedule;
3637
import seedu.address.model.tag.Tag;
3738

@@ -111,13 +112,14 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
111112
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
112113
Birthday updatedBirthday = editPersonDescriptor.getBirthday().orElse(personToEdit.getBirthday());
113114
Priority updatedPriority = editPersonDescriptor.getPriority().orElse(personToEdit.getPriority());
115+
Remark updatedRemark = personToEdit.getRemark(); // edit command does not allow editing remarks
114116
LastMet currentLastMet = personToEdit.getLastMet();
115117
Schedule currentSchedule = personToEdit.getSchedule();
116118
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());
117119
PolicyList currentPolicyList = personToEdit.getPolicyList();
118120

119121
return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedBirthday, updatedPriority,
120-
currentLastMet, currentSchedule, updatedTags, currentPolicyList);
122+
updatedRemark, currentLastMet, currentSchedule, updatedTags, currentPolicyList);
121123
}
122124

123125
@Override

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public CommandResult execute(Model model) throws CommandException {
6666
Person metPerson = new Person(
6767
personToMeet.getName(), personToMeet.getPhone(), personToMeet.getEmail(),
6868
personToMeet.getAddress(), personToMeet.getBirthday(), personToMeet.getPriority(),
69-
this.lastMet, personToMeet.getSchedule(), personToMeet.getTags(), personToMeet.getPolicyList());
69+
personToMeet.getRemark(), this.lastMet, personToMeet.getSchedule(), personToMeet.getTags(),
70+
personToMeet.getPolicyList());
7071

7172
model.setPerson(personToMeet, metPerson);
7273
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public CommandResult execute(Model model) throws CommandException {
5757
Person metPerson = new Person(
5858
personToMeet.getName(), personToMeet.getPhone(), personToMeet.getEmail(),
5959
personToMeet.getAddress(), personToMeet.getBirthday(), personToMeet.getPriority(),
60-
personToMeet.getLastMet(), personToMeet.getSchedule(), personToMeet.getTags(),
60+
personToMeet.getRemark(), personToMeet.getLastMet(), personToMeet.getSchedule(), personToMeet.getTags(),
6161
personToMeet.getPolicyList());
6262

6363
metPerson.getSchedule().markIsDone();
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package seedu.address.logic.commands;
2+
3+
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
4+
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK;
5+
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;
6+
7+
import java.util.List;
8+
9+
import seedu.address.commons.core.index.Index;
10+
import seedu.address.logic.Messages;
11+
import seedu.address.logic.commands.exceptions.CommandException;
12+
import seedu.address.model.Model;
13+
import seedu.address.model.person.Person;
14+
import seedu.address.model.person.Remark;
15+
16+
17+
18+
/**
19+
* Changes the remark of an existing person in the address book.
20+
*/
21+
public class RemarkCommand extends Command {
22+
23+
public static final String COMMAND_WORD = "remark";
24+
25+
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the remark of the person identified "
26+
+ "by the index number used in the last person listing. "
27+
+ "Existing remark will be overwritten by the input.\n"
28+
+ "Parameters: INDEX (must be a positive integer) "
29+
+ PREFIX_REMARK + "[REMARK]\n"
30+
+ "Example: " + COMMAND_WORD + " 1 "
31+
+ PREFIX_REMARK + "Likes to swim.";
32+
33+
public static final String MESSAGE_ADD_REMARK_SUCCESS = "Added remark to Person: %1$s";
34+
public static final String MESSAGE_DELETE_REMARK_SUCCESS = "Removed remark from Person: %1$s";
35+
36+
private final Index index;
37+
private final Remark remark;
38+
39+
/**
40+
* @param index of the person in the filtered person list to edit the remark
41+
* @param remark of the person to be updated to
42+
*/
43+
public RemarkCommand(Index index, Remark remark) {
44+
requireAllNonNull(index, remark);
45+
46+
this.index = index;
47+
this.remark = remark;
48+
}
49+
@Override
50+
public CommandResult execute(Model model) throws CommandException {
51+
List<Person> lastShownList = model.getFilteredPersonList();
52+
53+
if (index.getZeroBased() >= lastShownList.size()) {
54+
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
55+
}
56+
57+
Person personToEdit = lastShownList.get(index.getZeroBased());
58+
Person editedPerson = new Person(
59+
personToEdit.getName(), personToEdit.getPhone(), personToEdit.getEmail(), personToEdit.getAddress(),
60+
personToEdit.getBirthday(), personToEdit.getPriority(), remark, personToEdit.getLastMet(),
61+
personToEdit.getSchedule(), personToEdit.getTags(), personToEdit.getPolicyList());
62+
63+
model.setPerson(personToEdit, editedPerson);
64+
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
65+
model.setDisplayClient(editedPerson);
66+
67+
return new CommandResult(generateSuccessMessage(editedPerson));
68+
}
69+
70+
/**
71+
* Generates a command execution success message based on whether
72+
* the remark is added to or removed from
73+
* {@code personToEdit}.
74+
*/
75+
private String generateSuccessMessage(Person editedPerson) {
76+
String message = !remark.value.isEmpty() ? MESSAGE_ADD_REMARK_SUCCESS : MESSAGE_DELETE_REMARK_SUCCESS;
77+
return String.format(message, Messages.format(editedPerson));
78+
}
79+
80+
@Override
81+
public boolean equals(Object other) {
82+
// short circuit if same object
83+
if (other == this) {
84+
return true;
85+
}
86+
87+
// instanceof handles nulls
88+
if (!(other instanceof RemarkCommand)) {
89+
return false;
90+
}
91+
92+
// state check
93+
RemarkCommand e = (RemarkCommand) other;
94+
return index.equals(e.index)
95+
&& remark.equals(e.remark);
96+
}
97+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public CommandResult execute(Model model) throws CommandException {
6666
Person metPerson = new Person(
6767
personToMeet.getName(), personToMeet.getPhone(), personToMeet.getEmail(),
6868
personToMeet.getAddress(), personToMeet.getBirthday(), personToMeet.getPriority(),
69-
personToMeet.getLastMet(), this.schedule, personToMeet.getTags(), personToMeet.getPolicyList());
69+
personToMeet.getRemark(), personToMeet.getLastMet(), this.schedule, personToMeet.getTags(),
70+
personToMeet.getPolicyList());
7071

7172
model.setPerson(personToMeet, metPerson);
7273
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);

src/main/java/seedu/address/logic/parser/AddCommandParser.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import seedu.address.model.person.Person;
2222
import seedu.address.model.person.Phone;
2323
import seedu.address.model.person.Priority;
24+
import seedu.address.model.person.Remark;
2425
import seedu.address.model.tag.Tag;
2526

2627
/**
@@ -52,9 +53,10 @@ public AddCommand parse(String args) throws ParseException {
5253
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
5354
Birthday birthday = ParserUtil.parseBirthday(argMultimap.getValue(PREFIX_BIRTHDAY).get());
5455
Priority priority = ParserUtil.parsePriority(argMultimap.getValue(PREFIX_PRIORITY).get());
56+
Remark remark = new Remark(""); // add command does not allow adding remarks straight away
5557
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));
5658

57-
Person person = new Person(name, phone, email, address, birthday, priority, tagList);
59+
Person person = new Person(name, phone, email, address, birthday, priority, remark, tagList);
5860

5961
return new AddCommand(person);
6062
}

src/main/java/seedu/address/logic/parser/AddressBookParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import seedu.address.logic.commands.LastMetCommand;
2222
import seedu.address.logic.commands.ListCommand;
2323
import seedu.address.logic.commands.MarkCommand;
24+
import seedu.address.logic.commands.RemarkCommand;
2425
import seedu.address.logic.commands.ScheduleCommand;
2526
import seedu.address.logic.commands.SortCommand;
2627
import seedu.address.logic.commands.ViewCommand;
@@ -78,6 +79,9 @@ public Command parseCommand(String userInput) throws ParseException {
7879
case ViewCommand.COMMAND_WORD:
7980
return new ViewCommandParser().parse(arguments);
8081

82+
case RemarkCommand.COMMAND_WORD:
83+
return new RemarkCommandParser().parse(arguments);
84+
8185
case LastMetCommand.COMMAND_WORD:
8286
return new LastMetCommandParser().parse(arguments);
8387

src/main/java/seedu/address/logic/parser/CliSyntax.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class CliSyntax {
1414
public static final Prefix PREFIX_SCHEDULE = new Prefix("d/");
1515
public static final Prefix PREFIX_BIRTHDAY = new Prefix("d/");
1616
public static final Prefix PREFIX_PRIORITY = new Prefix("p/");
17+
public static final Prefix PREFIX_REMARK = new Prefix("r/");
1718
public static final Prefix PREFIX_TAG = new Prefix("t/");
1819
public static final Prefix PREFIX_POLICYNAME = new Prefix("n/");
1920
public static final Prefix PREFIX_POLICYID = new Prefix("i/");
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package seedu.address.logic.parser;
2+
3+
import static java.util.Objects.requireNonNull;
4+
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
5+
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK;
6+
7+
import seedu.address.commons.core.index.Index;
8+
import seedu.address.commons.exceptions.IllegalValueException;
9+
import seedu.address.logic.commands.RemarkCommand;
10+
import seedu.address.logic.parser.exceptions.ParseException;
11+
import seedu.address.model.person.Remark;
12+
13+
/**
14+
* Parses input arguments and creates a new {@code RemarkCommand} object
15+
*/
16+
public class RemarkCommandParser implements Parser<RemarkCommand> {
17+
/**
18+
* Parses the given {@code String} of arguments in the context of the {@code RemarkCommand}
19+
* and returns a {@code RemarkCommand} object for execution.
20+
* @throws ParseException if the user input does not conform the expected format
21+
*/
22+
public RemarkCommand parse(String args) throws ParseException {
23+
requireNonNull(args);
24+
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_REMARK);
25+
26+
Index index;
27+
try {
28+
index = ParserUtil.parseIndex(argMultimap.getPreamble());
29+
} catch (IllegalValueException ive) {
30+
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, RemarkCommand.MESSAGE_USAGE), ive);
31+
}
32+
33+
String remark = argMultimap.getValue(PREFIX_REMARK).orElse("");
34+
35+
return new RemarkCommand(index, new Remark(remark));
36+
}
37+
}

src/main/java/seedu/address/model/ModelManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ public void addPolicy(Person target, Policy policy) {
132132
PolicyList newPolicyList = target.getPolicyList();
133133
newPolicyList.addPolicy(policy);
134134
setPerson(target, new Person(target.getName(), target.getPhone(), target.getEmail(), target.getAddress(),
135-
target.getBirthday(), target.getPriority(), target.getLastMet(), target.getSchedule(), target.getTags(),
136-
newPolicyList));
135+
target.getBirthday(), target.getPriority(), target.getRemark(),
136+
target.getLastMet(), target.getSchedule(), target.getTags(), newPolicyList));
137137
}
138138

139139
/**
@@ -146,8 +146,8 @@ public void deletePolicy(Person target, String policyId) {
146146
PolicyList newPolicyList = target.getPolicyList();
147147
newPolicyList.deletePolicy(policyId);
148148
setPerson(target, new Person(target.getName(), target.getPhone(), target.getEmail(), target.getAddress(),
149-
target.getBirthday(), target.getPriority(), target.getLastMet(), target.getSchedule(), target.getTags(),
150-
newPolicyList));
149+
target.getBirthday(), target.getPriority(), target.getRemark(),
150+
target.getLastMet(), target.getSchedule(), target.getTags(), newPolicyList));
151151
}
152152

153153
//=========== Filtered Person List Accessors =============================================================

src/main/java/seedu/address/model/person/Person.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class Person {
2828
private final Address address;
2929
private final Birthday birthday;
3030
private final Priority priority;
31+
private final Remark remark;
3132
private final LastMet lastMet;
3233
private final Schedule schedule;
3334
private final Set<Tag> tags = new HashSet<>();
@@ -37,14 +38,15 @@ public class Person {
3738
* Every field must be present and not null.
3839
*/
3940
public Person(Name name, Phone phone, Email email, Address address, Birthday birthday, Priority priority,
40-
Set<Tag> tags) {
41+
Remark remark, Set<Tag> tags) {
4142
requireAllNonNull(name, phone, email, address, birthday, priority, tags);
4243
this.name = name;
4344
this.phone = phone;
4445
this.email = email;
4546
this.address = address;
4647
this.birthday = birthday;
4748
this.priority = priority;
49+
this.remark = remark;
4850
this.lastMet = new LastMet(LocalDate.now());
4951
this.schedule = new Schedule(LocalDateTime.now(), true);
5052
this.tags.addAll(tags);
@@ -55,14 +57,15 @@ public Person(Name name, Phone phone, Email email, Address address, Birthday bir
5557
* Person constructor used for subsequent LastMet, Schedule and Mark Commands.
5658
*/
5759
public Person(Name name, Phone phone, Email email, Address address, Birthday birthday,
58-
Priority priority, LastMet lastmet, Schedule schedule, Set<Tag> tags, PolicyList policyList) {
60+
Priority priority, Remark remark, LastMet lastmet, Schedule schedule, Set<Tag> tags, PolicyList policyList) {
5961
requireAllNonNull(name, phone, email, address, birthday, tags, policyList);
6062
this.name = name;
6163
this.phone = phone;
6264
this.email = email;
6365
this.address = address;
6466
this.birthday = birthday;
6567
this.priority = priority;
68+
this.remark = remark;
6669
this.lastMet = checkNullLastMet(lastmet);
6770
this.schedule = checkNullSchedule(schedule);
6871
this.tags.addAll(tags);
@@ -93,6 +96,10 @@ public Priority getPriority() {
9396
return priority;
9497
}
9598

99+
public Remark getRemark() {
100+
return remark;
101+
}
102+
96103
public LastMet getLastMet() {
97104
return lastMet;
98105
}
@@ -203,6 +210,7 @@ public String toString() {
203210
.add("address", address)
204211
.add("birthday", birthday)
205212
.add("priority", priority)
213+
.add("remark", remark)
206214
.add("tags", tags)
207215
.add("policies", policyList)
208216
.toString();

src/main/java/seedu/address/model/person/PriorityValue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ public static String[] getShortPriorities() {
6666

6767
@Override
6868
public String toString() {
69-
return this.name().toLowerCase();
69+
return this.name().toUpperCase();
7070
}
7171
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package seedu.address.model.person;
2+
3+
import static java.util.Objects.requireNonNull;
4+
5+
/**
6+
* Represents a Person's remark in the address book.
7+
* Guarantees: immutable; is always valid
8+
*/
9+
public class Remark {
10+
public final String value;
11+
12+
/**
13+
* Constructs an {@code Remark}.
14+
*
15+
* @param remark A valid remark.
16+
*/
17+
public Remark(String remark) {
18+
requireNonNull(remark);
19+
value = remark;
20+
}
21+
22+
@Override
23+
public String toString() {
24+
return value;
25+
}
26+
27+
@Override
28+
public boolean equals(Object other) {
29+
if (other == this) {
30+
return true;
31+
}
32+
33+
// instanceof handles nulls
34+
if (!(other instanceof Remark)) {
35+
return false;
36+
}
37+
38+
Remark otherRemark = (Remark) other;
39+
return value.equals(otherRemark.value);
40+
}
41+
42+
@Override
43+
public int hashCode() {
44+
return value.hashCode();
45+
}
46+
}

0 commit comments

Comments
 (0)