From 540e73ddb5b8b7c30e5124d6d4054ebd7ae4144a Mon Sep 17 00:00:00 2001 From: lambraydon Date: Mon, 2 Oct 2023 10:32:32 +0800 Subject: [PATCH 001/380] Add hello.txt file --- hello.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 hello.txt diff --git a/hello.txt b/hello.txt new file mode 100644 index 00000000000..e69de29bb2d From 0234903e17e2fab81754b6261152054bf8b734b2 Mon Sep 17 00:00:00 2001 From: yihfei Date: Mon, 2 Oct 2023 19:13:56 +0800 Subject: [PATCH 002/380] Add Remark.java, RemarkCommand.java and RemarkCommandParser.java to handle remarks --- .../address/logic/commands/RemarkCommand.java | 60 +++++++++++++++++++ .../logic/parser/AddressBookParser.java | 13 ++-- .../seedu/address/logic/parser/CliSyntax.java | 2 + .../logic/parser/RemarkCommandParser.java | 35 +++++++++++ .../seedu/address/model/person/Remark.java | 53 ++++++++++++++++ 5 files changed, 154 insertions(+), 9 deletions(-) create mode 100644 src/main/java/seedu/address/logic/commands/RemarkCommand.java create mode 100644 src/main/java/seedu/address/logic/parser/RemarkCommandParser.java create mode 100644 src/main/java/seedu/address/model/person/Remark.java diff --git a/src/main/java/seedu/address/logic/commands/RemarkCommand.java b/src/main/java/seedu/address/logic/commands/RemarkCommand.java new file mode 100644 index 00000000000..83cb7216a60 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/RemarkCommand.java @@ -0,0 +1,60 @@ +package seedu.address.logic.commands; + +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; + +/** + * Changes the remark of an existing person in the address book. + */ +public class RemarkCommand extends Command { + public static final String COMMAND_WORD = "remark"; + + 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. " + + "Existing remark will be overwritten by the input.\n" + + "Parameters: INDEX (must be a positive integer) " + + "r/ [REMARK]\n" + + "Example: " + COMMAND_WORD + " 1 " + + "r/ Likes to swim."; + + public static final String MESSAGE_ARGUMENTS = "Index: %1$d, Remark: %2$s"; + + private final Index index; + 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 + */ + public RemarkCommand(Index index, String remark) { + requireAllNonNull(index, remark); + + this.index = index; + this.remark = remark; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + throw new CommandException( + String.format(MESSAGE_ARGUMENTS, index.getOneBased(), remark)); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof RemarkCommand)) { + return false; + } + + RemarkCommand e = (RemarkCommand) other; + return index.equals(e.index) + && remark.equals(e.remark); + } + +} \ No newline at end of file diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 3149ee07e0b..9d310fdf629 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -8,15 +8,7 @@ import java.util.regex.Pattern; import seedu.address.commons.core.LogsCenter; -import seedu.address.logic.commands.AddCommand; -import seedu.address.logic.commands.ClearCommand; -import seedu.address.logic.commands.Command; -import seedu.address.logic.commands.DeleteCommand; -import seedu.address.logic.commands.EditCommand; -import seedu.address.logic.commands.ExitCommand; -import seedu.address.logic.commands.FindCommand; -import seedu.address.logic.commands.HelpCommand; -import seedu.address.logic.commands.ListCommand; +import seedu.address.logic.commands.*; import seedu.address.logic.parser.exceptions.ParseException; /** @@ -77,6 +69,9 @@ public Command parseCommand(String userInput) throws ParseException { case HelpCommand.COMMAND_WORD: return new HelpCommand(); + case RemarkCommand.COMMAND_WORD: + return new RemarkCommandParser().parse(arguments); + default: logger.finer("This user input caused a ParseException: " + userInput); throw new ParseException(MESSAGE_UNKNOWN_COMMAND); diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 75b1a9bf119..16669d93bb1 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -12,4 +12,6 @@ public class CliSyntax { public static final Prefix PREFIX_ADDRESS = new Prefix("a/"); public static final Prefix PREFIX_TAG = new Prefix("t/"); + public static final Prefix PREFIX_REMARK = new Prefix("r/"); + } diff --git a/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java b/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java new file mode 100644 index 00000000000..c6a8905b994 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java @@ -0,0 +1,35 @@ +package seedu.address.logic.parser; + +import static java.util.Objects.requireNonNull; +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; + +import seedu.address.commons.core.index.Index; +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.logic.commands.RemarkCommand; +import seedu.address.logic.parser.exceptions.ParseException; + + + +public class RemarkCommandParser implements Parser { + + public RemarkCommand parse(String args) throws ParseException { + requireNonNull(args); + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, + PREFIX_REMARK); + + Index index; + try { + index = ParserUtil.parseIndex(argMultimap.getPreamble()); + } catch (IllegalValueException ive) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, + RemarkCommand.MESSAGE_USAGE), ive); + } + + String remark = argMultimap.getValue(PREFIX_REMARK).orElse(""); + + return new RemarkCommand(index, remark); + } + + +} diff --git a/src/main/java/seedu/address/model/person/Remark.java b/src/main/java/seedu/address/model/person/Remark.java new file mode 100644 index 00000000000..f57262a96b1 --- /dev/null +++ b/src/main/java/seedu/address/model/person/Remark.java @@ -0,0 +1,53 @@ +package seedu.address.model.person; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + +/** + * Represents a Person's address in the address book. + * Guarantees: immutable; is valid as declared in {@link #isValidRemark(String)} + */ +public class Remark { + + public static final String MESSAGE_CONSTRAINTS = "Remarks can take any values, and it should not be blank"; + + /* + * The first character of the remark must not be a whitespace, + * otherwise " " (a blank string) becomes a valid input. + */ + public static final String VALIDATION_REGEX = "[^\\s].*"; + + public final String value; + + public Remark(String remark) { + requireNonNull(remark); + value = remark; + } + + + @Override + public String toString() { + return value; + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof Remark)) { + return false; + } + + Remark otherRemark = (Remark) other; + return value.equals(otherRemark.value); + } + + @Override + public int hashCode() { + return value.hashCode(); + } + +} From 0b1d86e2983aba1bf8be4694204819f8479c6ba3 Mon Sep 17 00:00:00 2001 From: yihfei Date: Tue, 3 Oct 2023 13:35:02 +0800 Subject: [PATCH 003/380] Add Remark Tests and update Remark class to work --- .../address/logic/commands/EditCommand.java | 9 +- .../address/logic/commands/RemarkCommand.java | 42 ++++++- .../logic/parser/AddCommandParser.java | 10 +- .../logic/parser/RemarkCommandParser.java | 4 +- .../seedu/address/model/person/Person.java | 10 +- .../address/model/util/SampleDataUtil.java | 19 ++-- .../address/storage/JsonAdaptedPerson.java | 21 ++-- .../java/seedu/address/ui/PersonCard.java | 3 + src/main/resources/view/PersonListCard.fxml | 1 + .../logic/commands/CommandTestUtil.java | 5 +- .../logic/commands/RemarkCommandTest.java | 107 ++++++++++++++++++ .../logic/parser/AddressBookParserTest.java | 101 ----------------- .../storage/JsonAdaptedPersonTest.java | 20 ++-- .../seedu/address/testutil/PersonBuilder.java | 17 ++- .../address/testutil/TypicalPersons.java | 2 +- 15 files changed, 214 insertions(+), 157 deletions(-) create mode 100644 src/test/java/seedu/address/logic/commands/RemarkCommandTest.java delete mode 100644 src/test/java/seedu/address/logic/parser/AddressBookParserTest.java diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 4b581c7331e..2f1d90c79c7 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -21,11 +21,7 @@ import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; -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.tag.Tag; /** @@ -99,9 +95,10 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone()); Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail()); Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress()); + Remark updatedRemark = personToEdit.getRemark(); Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); - return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags); + return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedRemark, updatedTags); } @Override diff --git a/src/main/java/seedu/address/logic/commands/RemarkCommand.java b/src/main/java/seedu/address/logic/commands/RemarkCommand.java index 83cb7216a60..eaab4116f45 100644 --- a/src/main/java/seedu/address/logic/commands/RemarkCommand.java +++ b/src/main/java/seedu/address/logic/commands/RemarkCommand.java @@ -1,9 +1,16 @@ package seedu.address.logic.commands; import seedu.address.commons.core.index.Index; +import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; +import seedu.address.model.person.Person; +import seedu.address.model.person.Remark; + +import java.util.List; + import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; /** * Changes the remark of an existing person in the address book. @@ -11,6 +18,9 @@ public class RemarkCommand extends Command { public static final String COMMAND_WORD = "remark"; + public static final String MESSAGE_ADD_REMARK_SUCCESS = "Added remark to Person: %1$s"; + public static final String MESSAGE_DELETE_REMARK_SUCCESS = "Removed remark from Person: %1$s"; + 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. " @@ -23,22 +33,44 @@ public class RemarkCommand extends Command { public static final String MESSAGE_ARGUMENTS = "Index: %1$d, Remark: %2$s"; private final Index index; - private final String remark; + private final Remark remark; /** * @param index of the person in the filtered person list to edit the remark * @param remark of the person to be updated to */ - public RemarkCommand(Index index, String remark) { + public RemarkCommand(Index index, Remark remark) { requireAllNonNull(index, remark); - this.index = index; this.remark = remark; } @Override public CommandResult execute(Model model) throws CommandException { - throw new CommandException( - String.format(MESSAGE_ARGUMENTS, index.getOneBased(), remark)); + List lastShownList = model.getFilteredPersonList(); + + if (index.getZeroBased() >= lastShownList.size()) { + 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()); + + model.setPerson(personToEdit, editedPerson); + model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); + + return new CommandResult(generateSuccessMessage(editedPerson)); + } + + /** + * Generates a command execution success message based on whether + * the remark is added to or removed from + * {@code personToEdit}. + */ + private String generateSuccessMessage(Person personToEdit) { + String message = !remark.value.isEmpty() ? MESSAGE_ADD_REMARK_SUCCESS : MESSAGE_DELETE_REMARK_SUCCESS; + return String.format(message, personToEdit); } @Override diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 4ff1a97ed77..ccc4229d89c 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -12,11 +12,7 @@ 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.tag.Tag; /** @@ -44,8 +40,8 @@ public AddCommand parse(String args) throws ParseException { Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); - - Person person = new Person(name, phone, email, address, tagList); + Remark remark = new Remark(""); + Person person = new Person(name, phone, email, address, remark, tagList); return new AddCommand(person); } diff --git a/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java b/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java index c6a8905b994..20a4dcac0b8 100644 --- a/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java @@ -8,7 +8,7 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.logic.commands.RemarkCommand; import seedu.address.logic.parser.exceptions.ParseException; - +import seedu.address.model.person.Remark; public class RemarkCommandParser implements Parser { @@ -28,7 +28,7 @@ public RemarkCommand parse(String args) throws ParseException { String remark = argMultimap.getValue(PREFIX_REMARK).orElse(""); - return new RemarkCommand(index, remark); + return new RemarkCommand(index, new Remark(remark)); } diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index abe8c46b535..7319f14aecf 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -21,20 +21,23 @@ public class Person { private final Phone phone; private final Email email; + // Data fields private final Address address; private final Set tags = new HashSet<>(); + private final Remark remark; /** * Every field must be present and not null. */ - public Person(Name name, Phone phone, Email email, Address address, Set tags) { + public Person(Name name, Phone phone, Email email, Address address, Remark remark, Set tags) { requireAllNonNull(name, phone, email, address, tags); this.name = name; this.phone = phone; this.email = email; this.address = address; this.tags.addAll(tags); + this.remark = remark; } public Name getName() { @@ -53,6 +56,10 @@ public Address getAddress() { return address; } + public Remark getRemark() { + return remark; + } + /** * Returns an immutable tag set, which throws {@code UnsupportedOperationException} * if modification is attempted. @@ -110,6 +117,7 @@ public String toString() { .add("phone", phone) .add("email", email) .add("address", address) + .add("remark", remark) .add("tags", tags) .toString(); } diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 1806da4facf..97c02d88b05 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -6,36 +6,33 @@ import seedu.address.model.AddressBook; import seedu.address.model.ReadOnlyAddressBook; -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.tag.Tag; /** * Contains utility methods for populating {@code AddressBook} with sample data. */ public class SampleDataUtil { + public static final Remark EMPTY_REMARK = new Remark(""); public static Person[] getSamplePersons() { return new Person[] { new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), - new Address("Blk 30 Geylang Street 29, #06-40"), + new Address("Blk 30 Geylang Street 29, #06-40"), EMPTY_REMARK, getTagSet("friends")), new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), - new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), + new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), EMPTY_REMARK, getTagSet("colleagues", "friends")), new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), - new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), + new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), EMPTY_REMARK, getTagSet("neighbours")), new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), - new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), + new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), EMPTY_REMARK, getTagSet("family")), new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), - new Address("Blk 47 Tampines Street 20, #17-35"), + new Address("Blk 47 Tampines Street 20, #17-35"), EMPTY_REMARK, getTagSet("classmates")), new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), - new Address("Blk 45 Aljunied Street 85, #11-31"), + new Address("Blk 45 Aljunied Street 85, #11-31"), EMPTY_REMARK, getTagSet("colleagues")) }; } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index bd1ca0f56c8..2308e713553 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -10,11 +10,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import seedu.address.commons.exceptions.IllegalValueException; -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.tag.Tag; /** @@ -28,6 +24,8 @@ class JsonAdaptedPerson { private final String phone; private final String email; private final String address; + + private final String remark; private final List tags = new ArrayList<>(); /** @@ -36,11 +34,12 @@ class JsonAdaptedPerson { @JsonCreator public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone, @JsonProperty("email") String email, @JsonProperty("address") String address, - @JsonProperty("tags") List tags) { + @JsonProperty("remark") String remark, @JsonProperty("tags") List tags) { this.name = name; this.phone = phone; this.email = email; this.address = address; + this.remark = remark; if (tags != null) { this.tags.addAll(tags); } @@ -54,6 +53,7 @@ public JsonAdaptedPerson(Person source) { phone = source.getPhone().value; email = source.getEmail().value; address = source.getAddress().value; + remark = source.getRemark().value; tags.addAll(source.getTags().stream() .map(JsonAdaptedTag::new) .collect(Collectors.toList())); @@ -77,6 +77,7 @@ public Person toModelType() throws IllegalValueException { throw new IllegalValueException(Name.MESSAGE_CONSTRAINTS); } final Name modelName = new Name(name); + final Remark modelRemark = new Remark(""); //TODO: Implement parsing and marshalling in the storage commit if (phone == null) { throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName())); @@ -103,7 +104,13 @@ public Person toModelType() throws IllegalValueException { final Address modelAddress = new Address(address); final Set modelTags = new HashSet<>(personTags); - return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags); + + if (remark == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Remark.class.getSimpleName())); + } + + + return new Person(modelName, modelPhone, modelEmail, modelAddress, modelRemark, modelTags); } } diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index 094c42cda82..133b001267c 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -40,6 +40,8 @@ public class PersonCard extends UiPart { private Label email; @FXML private FlowPane tags; + @FXML + private Label remark; /** * Creates a {@code PersonCode} with the given {@code Person} and index to display. @@ -52,6 +54,7 @@ public PersonCard(Person person, int displayedIndex) { phone.setText(person.getPhone().value); address.setText(person.getAddress().value); email.setText(person.getEmail().value); + remark.setText(person.getRemark().value); person.getTags().stream() .sorted(Comparator.comparing(tag -> tag.tagName)) .forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index f5e812e25e6..1bff2cd09eb 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -31,6 +31,7 @@