diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index ffe3aa5b603..f572e99c0f9 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -30,6 +30,7 @@ import seedu.address.model.person.Name; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; +import seedu.address.model.preferredtime.PreferredTime; import seedu.address.model.tag.Tag; /** @@ -106,8 +107,11 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress()); Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); Map updatedGames = editPersonDescriptor.getGames().orElse(personToEdit.getGames()); + Set updatedPreferredTimes = + editPersonDescriptor.getPreferredTimes().orElse(personToEdit.getPreferredTimes()); - return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags, updatedGames); + return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags, + updatedGames, updatedPreferredTimes); } @Override @@ -145,6 +149,7 @@ public static class EditPersonDescriptor { private Address address; private Set tags; private Map games; + private Set preferredTimes; public EditPersonDescriptor() {} @@ -160,6 +165,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { setAddress(toCopy.address); setTags(toCopy.tags); setGames(toCopy.games); + setPreferredTimes(toCopy.preferredTimes); } /** @@ -234,6 +240,26 @@ public void setGames(Map games) { public Optional> getGames() { return (games != null) ? Optional.of(Collections.unmodifiableMap(games)) : Optional.empty(); } + + /** + * Sets {@code preferredTimes} to this object's {@code preferredTimes}. + * A defensive copy of {@code preferredTimes} is used internally. + */ + public void setPreferredTimes(Set preferredTimes) { + this.preferredTimes = (preferredTimes != null) ? new HashSet<>(preferredTimes) : null; + } + + /** + * Returns an unmodifiable preferredTime set, which throws {@code UnsupportedOperationException} + * if modification is attempted. + * Returns {@code Optional#empty()} if {@code preferredTimes} is null. + */ + public Optional> getPreferredTimes() { + return (preferredTimes != null) + ? Optional.of(Collections.unmodifiableSet(preferredTimes)) + : Optional.empty(); + } + @Override public boolean equals(Object other) { if (other == this) { diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 0fc878c27b6..00b78379874 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -6,6 +6,7 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_GAME; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PREFERREDTIME; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import java.util.Map; @@ -20,6 +21,7 @@ import seedu.address.model.person.Name; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; +import seedu.address.model.preferredtime.PreferredTime; import seedu.address.model.tag.Tag; /** @@ -35,7 +37,7 @@ public class AddCommandParser implements Parser { public AddCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG, - PREFIX_GAME); + PREFIX_GAME, PREFIX_PREFERREDTIME); if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL) || !argMultimap.getPreamble().isEmpty()) { @@ -49,11 +51,10 @@ public AddCommand parse(String args) throws ParseException { Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); Map gameList = ParserUtil.parseGames(argMultimap.getAllValues(PREFIX_GAME)); + Set preferredTimeList = + ParserUtil.parsePreferredTimes(argMultimap.getAllValues(PREFIX_PREFERREDTIME)); - // TODO: use get a Set with the help of ParserUtil - // TODO: update the Person construction - - Person person = new Person(name, phone, email, address, tagList, gameList); + Person person = new Person(name, phone, email, address, tagList, gameList, preferredTimeList); return new AddCommand(person); } diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index cceaa0db58e..a5c0ba29d91 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -19,6 +19,7 @@ import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.Phone; +import seedu.address.model.preferredtime.PreferredTime; import seedu.address.model.tag.Tag; /** @@ -202,6 +203,31 @@ public static Map parseGames(Collection games) throws Pars } - // TODO: parsePreferredTime and parsePreferredTimes + /** + * Parses a {@code String preferredTime} into a {@code PreferredTime}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code preferredTime} is invalid. + */ + public static PreferredTime parsePreferredTime(String preferredTime) throws ParseException { + requireNonNull(preferredTime); + String trimmedPreferredTime = preferredTime.trim(); + if (!PreferredTime.isValidPreferredTime(trimmedPreferredTime)) { + throw new ParseException(PreferredTime.MESSAGE_CONSTRAINTS); + } + return new PreferredTime(trimmedPreferredTime); + } + + /** + * Parses {@code Collection preferredTimes} into a {@code Set}. + */ + public static Set parsePreferredTimes(Collection preferredTimes) throws ParseException { + requireNonNull(preferredTimes); + final Set preferredTimeSet = new HashSet<>(); + for (String preferredTime : preferredTimes) { + preferredTimeSet.add(parsePreferredTime(preferredTime)); + } + return preferredTimeSet; + } } diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 69eaf801c66..cfbaea03cbf 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -11,6 +11,7 @@ import seedu.address.commons.util.ToStringBuilder; import seedu.address.model.game.Game; +import seedu.address.model.preferredtime.PreferredTime; import seedu.address.model.tag.Tag; /** @@ -28,21 +29,21 @@ public class Person { private final Address address; private final Set tags = new HashSet<>(); private final Map games = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - - // TODO: update the preferredTime field - // TODO: update the constructors and some other method + private final Set preferredTimes = new HashSet<>(); /** * Every field must be present and not null. */ - public Person(Name name, Phone phone, Email email, Address address, Set tags, Map games) { - requireAllNonNull(name, phone, email, address, tags, games); + public Person(Name name, Phone phone, Email email, Address address, Set tags, + Map games, Set preferredTimes) { + requireAllNonNull(name, phone, email, address, tags, games, preferredTimes); this.name = name; this.phone = phone; this.email = email; this.address = address; this.tags.addAll(tags); this.games.putAll(games); + this.preferredTimes.addAll(preferredTimes); } public Name getName() { @@ -76,6 +77,15 @@ public Set getTags() { public Map getGames() { return games; } + + /** + * Returns an immutable tag set, which throws {@code UnsupportedOperationException} + * if modification is attempted. + */ + public Set getPreferredTimes() { + return Collections.unmodifiableSet(preferredTimes); + } + /** * Returns true if both persons have the same name. * This defines a weaker notion of equality between two persons. @@ -110,14 +120,15 @@ public boolean equals(Object other) { && email.equals(otherPerson.email) && address.equals(otherPerson.address) && tags.equals(otherPerson.tags) - && games.equals(otherPerson.games); + && games.equals(otherPerson.games) + && preferredTimes.equals(otherPerson.preferredTimes); } @Override public int hashCode() { // use this method for custom fields hashing instead of implementing your own - return Objects.hash(name, phone, email, address, tags, games); + return Objects.hash(name, phone, email, address, tags, games, preferredTimes); } @Override @@ -129,6 +140,7 @@ public String toString() { .add("address", address) .add("tags", tags) .add("games", games) + .add("preferred times", preferredTimes) .toString(); } diff --git a/src/main/java/seedu/address/model/preferredtime/PreferredTime.java b/src/main/java/seedu/address/model/preferredtime/PreferredTime.java index 44f7a8782f9..b2773f25bac 100644 --- a/src/main/java/seedu/address/model/preferredtime/PreferredTime.java +++ b/src/main/java/seedu/address/model/preferredtime/PreferredTime.java @@ -17,14 +17,13 @@ public class PreferredTime { "PreferredTime should consists of Day and Time in the format 'Day HHmm'.\n" + "There should be exactly one space in between"; public static final String VALIDATION_REGEX = "(\\p{L}+)\\s(\\d{4})$"; - private static final Pattern VALIDATED_PATTERN = Pattern.compile(VALIDATION_REGEX); + public static final Pattern VALIDATED_PATTERN = Pattern.compile(VALIDATION_REGEX); public final String preferredTime; public final Day day; public final Time time; - // TODO: constructor /** * Constructs a {@code PreferredTime}. * diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 7f479b1d3b1..9618457501a 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -17,6 +17,7 @@ import seedu.address.model.person.Name; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; +import seedu.address.model.preferredtime.PreferredTime; import seedu.address.model.tag.Tag; @@ -32,23 +33,28 @@ 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"), - getTagSet("friends"), - sample), + getTagSet("friends"), sample, + getPreferredTimeSet("Monday 2100")), new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), - getTagSet("colleagues", "friends"), getGameMap("LoL")), + getTagSet("colleagues", "friends"), getGameMap("LoL"), + getPreferredTimeSet("Monday 2030")), 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"), - getTagSet("neighbours"), getGameMap("LoL")), + getTagSet("neighbours"), getGameMap("LoL"), + getPreferredTimeSet("Saturday 1900")), new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), - getTagSet("family"), getGameMap("LoL")), + getTagSet("family"), getGameMap("LoL"), + getPreferredTimeSet("Tuesday 2100", "Thursday 1900")), new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), new Address("Blk 47 Tampines Street 20, #17-35"), - getTagSet("classmates"), getGameMap("LoL")), + getTagSet("classmates"), getGameMap("LoL"), + getPreferredTimeSet("Sunday 1800")), new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), new Address("Blk 45 Aljunied Street 85, #11-31"), - getTagSet("colleagues"), getGameMap("LoL")) + getTagSet("colleagues"), getGameMap("LoL"), + getPreferredTimeSet("Friday 2100")) }; } @@ -80,4 +86,13 @@ public static Map getGameMap(String... strings) { return gameMap; } + /** + * Returns a preferredTime set containing the list of strings given. + */ + public static Set getPreferredTimeSet(String... strings) { + return Arrays.stream(strings) + .map(PreferredTime::new) + .collect(Collectors.toSet()); + } + } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index 1252757da8a..cab409290dd 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -18,6 +18,7 @@ import seedu.address.model.person.Name; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; +import seedu.address.model.preferredtime.PreferredTime; import seedu.address.model.tag.Tag; /** @@ -33,6 +34,7 @@ class JsonAdaptedPerson { private final String address; private final List tags = new ArrayList<>(); private final List games = new ArrayList<>(); + private final List preferredTimes = new ArrayList<>(); /** @@ -42,7 +44,8 @@ class JsonAdaptedPerson { public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone, @JsonProperty("email") String email, @JsonProperty("address") String address, @JsonProperty("tags") List tags, - @JsonProperty("games") List games) { + @JsonProperty("games") List games, + @JsonProperty("preferred times") List preferredTimes) { this.name = name; this.phone = phone; this.email = email; @@ -53,6 +56,9 @@ public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone if (games != null) { this.games.addAll(games); } + if (preferredTimes != null) { + this.preferredTimes.addAll(preferredTimes); + } } /** @@ -69,6 +75,9 @@ public JsonAdaptedPerson(Person source) { games.addAll(source.getGames().values().stream() .map(JsonAdaptedGame::new) .collect(Collectors.toList())); + preferredTimes.addAll(source.getPreferredTimes().stream() + .map(JsonAdaptedPreferredTime::new) + .collect(Collectors.toList())); } /** @@ -85,6 +94,10 @@ public Person toModelType() throws IllegalValueException { for (JsonAdaptedGame game : games) { personGames.put(game.getGameName(), game.toModelType()); } + final List personPreferredTimes = new ArrayList<>(); + for (JsonAdaptedPreferredTime preferredTime: preferredTimes) { + personPreferredTimes.add(preferredTime.toModelType()); + } if (name == null) { throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName())); @@ -120,8 +133,9 @@ public Person toModelType() throws IllegalValueException { final Set modelTags = new HashSet<>(personTags); final Map modelGames = new HashMap<>(personGames); + final Set modelPreferredTimes = new HashSet<>(personPreferredTimes); - return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags, modelGames); + return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags, modelGames, modelPreferredTimes); } } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPreferredTime.java b/src/main/java/seedu/address/storage/JsonAdaptedPreferredTime.java new file mode 100644 index 00000000000..2d04ab1f775 --- /dev/null +++ b/src/main/java/seedu/address/storage/JsonAdaptedPreferredTime.java @@ -0,0 +1,69 @@ +package seedu.address.storage; + +import static seedu.address.model.preferredtime.PreferredTime.VALIDATED_PATTERN; + +import java.util.regex.Matcher; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.preferredtime.Day; +import seedu.address.model.preferredtime.PreferredTime; +import seedu.address.model.preferredtime.Time; + + + +/** + * Jackson-friendly version of {@link PreferredTime}. + */ +public class JsonAdaptedPreferredTime { + + private final String preferredTime; + + /** + * Constructs a {@code JsonAdaptedPreferredTime} with the given {@code preferredTime}. + */ + @JsonCreator + public JsonAdaptedPreferredTime(String preferredTime) { + this.preferredTime = preferredTime; + } + + /** + * Converts a given {@code PreferredTime} into this class for Jackson use. + */ + public JsonAdaptedPreferredTime(PreferredTime source) { + preferredTime = source.preferredTime; + } + + @JsonValue + public String getPreferredTime() { + return preferredTime; + } + + /** + * Converts this Jackson-friendly adapted game object into the model's {@code PreferredTime} object. + * + * @throws IllegalValueException if there were any data constraints violated in the adapted preferred time. + */ + public PreferredTime toModelType() throws IllegalValueException { + if (!PreferredTime.isValidPreferredTime(preferredTime)) { + throw new IllegalValueException(PreferredTime.MESSAGE_CONSTRAINTS); + } + + Matcher matcher = VALIDATED_PATTERN.matcher(preferredTime); // should always match as checked + if (!matcher.matches()) { + throw new IllegalArgumentException("Invalid preferred time format: " + preferredTime); + } + + if (!Day.isValidDay(matcher.group(1))) { + throw new IllegalValueException(Day.MESSAGE_CONSTRAINTS); + } + + if (!Time.isValidTime(matcher.group(2))) { + throw new IllegalValueException(Time.MESSAGE_CONSTRAINTS); + } + + return new PreferredTime(preferredTime); + } +} diff --git a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json index 72262099d35..d283bdb6e69 100644 --- a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json @@ -5,42 +5,49 @@ "phone" : "94351253", "email" : "alice@example.com", "address" : "123, Jurong West Ave 6, #08-111", - "tags" : [ "friends" ] + "tags" : [ "friends" ], + "preferred times": ["Monday 1200"] }, { "name" : "Benson Meier", "phone" : "98765432", "email" : "johnd@example.com", "address" : "311, Clementi Ave 2, #02-25", - "tags" : [ "owesMoney", "friends" ] + "tags" : [ "owesMoney", "friends" ], + "preferred times": [ ] }, { "name" : "Carl Kurz", "phone" : "95352563", "email" : "heinz@example.com", "address" : "wall street", - "tags" : [ ] + "tags" : [ ], + "preferred times": [ ] }, { "name" : "Daniel Meier", "phone" : "87652533", "email" : "cornelia@example.com", "address" : "10th street", - "tags" : [ "friends" ] + "tags" : [ "friends" ], + "preferred times": [ ] }, { "name" : "Elle Meyer", "phone" : "9482224", "email" : "werner@example.com", "address" : "michegan ave", - "tags" : [ ] + "tags" : [ ], + "preferred times": [ ] }, { "name" : "Fiona Kunz", "phone" : "9482427", "email" : "lydia@example.com", "address" : "little tokyo", - "tags" : [ ] + "tags" : [ ], + "preferred times": [ ] }, { "name" : "George Best", "phone" : "9482442", "email" : "anna@example.com", "address" : "4th street", - "tags" : [ ] + "tags" : [ ], + "preferred times": [ ] } ] } diff --git a/src/test/java/seedu/address/model/person/PersonTest.java b/src/test/java/seedu/address/model/person/PersonTest.java index dabb3743f39..ae01ee0ff97 100644 --- a/src/test/java/seedu/address/model/person/PersonTest.java +++ b/src/test/java/seedu/address/model/person/PersonTest.java @@ -88,13 +88,17 @@ public void equals() { // different tags -> returns false editedAlice = new PersonBuilder(ALICE).withTags(VALID_TAG_HUSBAND).build(); assertFalse(ALICE.equals(editedAlice)); + + // different tags -> returns false + editedAlice = new PersonBuilder(ALICE).withPreferredTimes("Monday 2100").build(); + assertFalse(ALICE.equals(editedAlice)); } @Test public void toStringMethod() { String expected = Person.class.getCanonicalName() + "{name=" + ALICE.getName() + ", phone=" + ALICE.getPhone() + ", email=" + ALICE.getEmail() + ", address=" + ALICE.getAddress() + ", tags=" + ALICE.getTags() - + ", games=" + ALICE.getGames() + "}"; + + ", games=" + ALICE.getGames() + ", preferred times=" + ALICE.getPreferredTimes() + "}"; assertEquals(expected, ALICE.toString()); } } diff --git a/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java b/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java index 47cbf0f098e..330256f69a4 100644 --- a/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java +++ b/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java @@ -23,6 +23,7 @@ public class JsonAdaptedPersonTest { private static final String INVALID_ADDRESS = " "; private static final String INVALID_EMAIL = "example.com"; private static final String INVALID_TAG = "#friend"; + private static final String INVALID_PREFERREDTIME = "Monday 4500"; private static final String VALID_NAME = BENSON.getName().toString(); private static final String VALID_PHONE = BENSON.getPhone().toString(); @@ -34,6 +35,9 @@ public class JsonAdaptedPersonTest { private static final List VALID_GAMES = BENSON.getGames().values().stream() .map(JsonAdaptedGame::new) .collect(Collectors.toList()); + private static final List VALID_PREFERREDTIME = BENSON.getPreferredTimes().stream() + .map(JsonAdaptedPreferredTime::new) + .collect(Collectors.toList()); @Test public void toModelType_validPersonDetails_returnsPerson() throws Exception { @@ -43,8 +47,8 @@ public void toModelType_validPersonDetails_returnsPerson() throws Exception { @Test public void toModelType_invalidName_throwsIllegalValueException() { - JsonAdaptedPerson person = - new JsonAdaptedPerson(INVALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, VALID_TAGS, VALID_GAMES); + JsonAdaptedPerson person = new JsonAdaptedPerson(INVALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, + VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME); String expectedMessage = Name.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @@ -52,16 +56,15 @@ public void toModelType_invalidName_throwsIllegalValueException() { @Test public void toModelType_nullName_throwsIllegalValueException() { JsonAdaptedPerson person = new JsonAdaptedPerson(null, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_TAGS, VALID_GAMES); + VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @Test public void toModelType_invalidPhone_throwsIllegalValueException() { - JsonAdaptedPerson person = - new JsonAdaptedPerson(VALID_NAME, INVALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_TAGS, VALID_GAMES); + JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, INVALID_PHONE, VALID_EMAIL, VALID_ADDRESS, + VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME); String expectedMessage = Phone.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @@ -69,15 +72,15 @@ public void toModelType_invalidPhone_throwsIllegalValueException() { @Test public void toModelType_nullPhone_throwsIllegalValueException() { JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, null, VALID_EMAIL, VALID_ADDRESS, - VALID_TAGS, VALID_GAMES); + VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @Test public void toModelType_invalidEmail_throwsIllegalValueException() { - JsonAdaptedPerson person = - new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, INVALID_EMAIL, VALID_ADDRESS, VALID_TAGS, VALID_GAMES); + JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, INVALID_EMAIL, VALID_ADDRESS, + VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME); String expectedMessage = Email.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @@ -85,15 +88,15 @@ public void toModelType_invalidEmail_throwsIllegalValueException() { @Test public void toModelType_nullEmail_throwsIllegalValueException() { JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, null, VALID_ADDRESS, - VALID_TAGS, VALID_GAMES); + VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @Test public void toModelType_invalidAddress_throwsIllegalValueException() { - JsonAdaptedPerson person = - new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_ADDRESS, VALID_TAGS, VALID_GAMES); + JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_ADDRESS, + VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME); String expectedMessage = Address.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @@ -101,7 +104,7 @@ public void toModelType_invalidAddress_throwsIllegalValueException() { @Test public void toModelType_nullAddress_throwsIllegalValueException() { JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, null, - VALID_TAGS, VALID_GAMES); + VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @@ -110,8 +113,17 @@ public void toModelType_nullAddress_throwsIllegalValueException() { public void toModelType_invalidTags_throwsIllegalValueException() { List invalidTags = new ArrayList<>(VALID_TAGS); invalidTags.add(new JsonAdaptedTag(INVALID_TAG)); - JsonAdaptedPerson person = - new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, invalidTags, VALID_GAMES); + JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, + invalidTags, VALID_GAMES, VALID_PREFERREDTIME); + assertThrows(IllegalValueException.class, person::toModelType); + } + + @Test + public void toModelType_invalidPreferredTimes_throwsIllegalValueException() { + List invalidPreferredTimes = new ArrayList<>(VALID_PREFERREDTIME); + invalidPreferredTimes.add(new JsonAdaptedPreferredTime(INVALID_PREFERREDTIME)); + JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, + VALID_TAGS, VALID_GAMES, invalidPreferredTimes); assertThrows(IllegalValueException.class, person::toModelType); } diff --git a/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java b/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java index 54af27408bb..2722ff9d6aa 100644 --- a/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java +++ b/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java @@ -41,6 +41,7 @@ public EditPersonDescriptorBuilder(Person person) { descriptor.setAddress(person.getAddress()); descriptor.setTags(person.getTags()); descriptor.setGames(person.getGames()); + descriptor.setPreferredTimes(person.getPreferredTimes()); } /** diff --git a/src/test/java/seedu/address/testutil/PersonBuilder.java b/src/test/java/seedu/address/testutil/PersonBuilder.java index 9363c0d3871..05fb7b6fc0d 100644 --- a/src/test/java/seedu/address/testutil/PersonBuilder.java +++ b/src/test/java/seedu/address/testutil/PersonBuilder.java @@ -11,6 +11,7 @@ import seedu.address.model.person.Name; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; +import seedu.address.model.preferredtime.PreferredTime; import seedu.address.model.tag.Tag; import seedu.address.model.util.SampleDataUtil; @@ -30,6 +31,7 @@ public class PersonBuilder { private Address address; private Set tags; private Map games; + private Set preferredTimes; /** * Creates a {@code PersonBuilder} with the default details. @@ -41,6 +43,7 @@ public PersonBuilder() { address = new Address(DEFAULT_ADDRESS); tags = new HashSet<>(); games = new HashMap<>(); + preferredTimes = new HashSet<>(); } /** @@ -53,6 +56,7 @@ public PersonBuilder(Person personToCopy) { address = personToCopy.getAddress(); tags = new HashSet<>(personToCopy.getTags()); games = new HashMap<>(personToCopy.getGames()); + preferredTimes = new HashSet<>(personToCopy.getPreferredTimes()); } /** @@ -78,6 +82,16 @@ public PersonBuilder withGames(String ... games) { this.games = SampleDataUtil.getGameMap(games); return this; } + + /** + * Parses the {@code preferredTimes} into a {@code Set} + * and set it to the {@code Person} that we are building. + */ + public PersonBuilder withPreferredTimes(String ... preferredTimes) { + this.preferredTimes = SampleDataUtil.getPreferredTimeSet(preferredTimes); + return this; + } + /** * Sets the {@code Address} of the {@code Person} that we are building. */ @@ -103,7 +117,7 @@ public PersonBuilder withEmail(String email) { } public Person build() { - return new Person(name, phone, email, address, tags, games); + return new Person(name, phone, email, address, tags, games, preferredTimes); } } diff --git a/src/test/java/seedu/address/testutil/TypicalPersons.java b/src/test/java/seedu/address/testutil/TypicalPersons.java index 56e8b23d7f2..2f7fb99b384 100644 --- a/src/test/java/seedu/address/testutil/TypicalPersons.java +++ b/src/test/java/seedu/address/testutil/TypicalPersons.java @@ -26,11 +26,12 @@ public class TypicalPersons { public static final Person ALICE = new PersonBuilder().withName("Alice Pauline") .withAddress("123, Jurong West Ave 6, #08-111").withEmail("alice@example.com") .withPhone("94351253") - .withTags("friends").withGames().build(); + .withTags("friends").withGames() + .withPreferredTimes("Monday 1200").build(); public static final Person BENSON = new PersonBuilder().withName("Benson Meier") .withAddress("311, Clementi Ave 2, #02-25") .withEmail("johnd@example.com").withPhone("98765432") - .withTags("owesMoney", "friends").withGames().build(); + .withTags("owesMoney", "friends").withGames().withPreferredTimes().build(); public static final Person CARL = new PersonBuilder().withName("Carl Kurz").withPhone("95352563") .withEmail("heinz@example.com").withAddress("wall street").build(); public static final Person DANIEL = new PersonBuilder().withName("Daniel Meier").withPhone("87652533") @@ -53,7 +54,7 @@ public class TypicalPersons { .withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY).withTags(VALID_TAG_FRIEND).build(); public static final Person BOB = new PersonBuilder().withName(VALID_NAME_BOB).withPhone(VALID_PHONE_BOB) .withEmail(VALID_EMAIL_BOB).withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND) - .withGames().build(); + .withGames().withPreferredTimes().build(); public static final String KEYWORD_MATCHING_MEIER = "Meier"; // A keyword that matches MEIER