From fa2b17aabb0d683d0179d8b484da47973d631c37 Mon Sep 17 00:00:00 2001
From: Hwww23 <122247552+Hwww23@users.noreply.github.com>
Date: Tue, 19 Mar 2024 21:54:21 +0800
Subject: [PATCH 01/10] Add dates to Student details
---
docs/UserGuide.md | 5 +-
.../java/seedu/address/logic/Messages.java | 4 +-
.../address/logic/commands/AddCommand.java | 3 +
.../address/logic/commands/EditCommand.java | 16 ++++-
.../logic/parser/AddCommandParser.java | 7 +-
.../seedu/address/logic/parser/CliSyntax.java | 1 +
.../address/logic/parser/ParserUtil.java | 19 ++++++
.../seedu/address/model/person/DateTime.java | 68 +++++++++++++++++++
.../seedu/address/model/person/Person.java | 11 ++-
.../address/model/util/SampleDataUtil.java | 19 ++++--
.../address/storage/JsonAdaptedDateTime.java | 32 +++++++++
.../address/storage/JsonAdaptedPerson.java | 18 ++++-
.../java/seedu/address/ui/PersonCard.java | 11 +++
src/main/resources/view/PersonListCard.fxml | 1 +
.../duplicatePersonAddressBook.json | 2 +
.../typicalPersonsAddressBook.json | 7 ++
.../logic/commands/CommandTestUtil.java | 6 ++
.../logic/parser/AddCommandParserTest.java | 32 ++++++---
.../address/logic/parser/ParserUtilTest.java | 51 ++++++++++++++
.../address/model/person/DateTimeTest.java | 24 +++++++
.../address/model/person/PersonTest.java | 3 +-
.../storage/JsonAdaptedPersonTest.java | 41 +++++++----
.../seedu/address/testutil/PersonBuilder.java | 14 +++-
.../address/testutil/TypicalPersons.java | 10 +--
24 files changed, 360 insertions(+), 45 deletions(-)
create mode 100644 src/main/java/seedu/address/model/person/DateTime.java
create mode 100644 src/main/java/seedu/address/storage/JsonAdaptedDateTime.java
create mode 100644 src/test/java/seedu/address/model/person/DateTimeTest.java
diff --git a/docs/UserGuide.md b/docs/UserGuide.md
index 8a77a9f114c..e7427dd1c86 100644
--- a/docs/UserGuide.md
+++ b/docs/UserGuide.md
@@ -76,15 +76,16 @@ Format: `help`
Adds a student to the address book.
-Format: `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS [g/GRADE] [s/SUBJECT] [t/TAG]…`
+Format: `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS [g/GRADE] [s/SUBJECT] [d/DATETIME] [t/TAG]…`
:bulb: **Tip:**
A person can have any number of tags (including 0)
* Grade should only contain a single letter from A to D, with plus(+), minus(-) or neither.
+* DateTime should be in yyyy-mm-dd hhmm
Examples:
-* `add n/John Doe p/98765432 e/johnd@example.com a/John street, block 123, #01-01 g/B+ s/Mathematics`
+* `add n/John Doe p/98765432 e/johnd@example.com a/John street, block 123, #01-01 g/B+ s/Mathematics d/2024-02-03 1800`
* `add n/Betsy Crowe t/friend e/betsycrowe@example.com a/Newgate Prison p/1234567 t/criminal`
### Listing all persons : `list`
diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java
index e72813c4c67..2ee222b143d 100644
--- a/src/main/java/seedu/address/logic/Messages.java
+++ b/src/main/java/seedu/address/logic/Messages.java
@@ -47,7 +47,9 @@ public static String format(Person person) {
.append(person.getGrade())
.append("; Subject: ")
.append(person.getSubject())
- .append("; Tags: ");
+ .append("; DateTime: ");
+ person.getDateTimes().forEach(builder::append);
+ builder.append("; Tags: ");
person.getTags().forEach(builder::append);
return builder.toString();
}
diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java
index db1da7bfdc8..6128ed35ab5 100644
--- a/src/main/java/seedu/address/logic/commands/AddCommand.java
+++ b/src/main/java/seedu/address/logic/commands/AddCommand.java
@@ -2,6 +2,7 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
+import static seedu.address.logic.parser.CliSyntax.PREFIX_DATETIME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
@@ -30,6 +31,7 @@ public class AddCommand extends Command {
+ PREFIX_ADDRESS + "ADDRESS "
+ "[" + PREFIX_GRADE + "GRADE] "
+ "[" + PREFIX_SUBJECT + "SUBJECT] "
+ + "[" + PREFIX_DATETIME + "DATETIME] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
@@ -38,6 +40,7 @@ public class AddCommand extends Command {
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_GRADE + "4.0 "
+ PREFIX_SUBJECT + "Mathematics "
+ + PREFIX_DATETIME + "2024-03-02 1800"
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";
diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java
index 94ff22d919b..63119d4dca2 100644
--- a/src/main/java/seedu/address/logic/commands/EditCommand.java
+++ b/src/main/java/seedu/address/logic/commands/EditCommand.java
@@ -2,6 +2,7 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
+import static seedu.address.logic.parser.CliSyntax.PREFIX_DATETIME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
@@ -24,6 +25,7 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Address;
+import seedu.address.model.person.DateTime;
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
@@ -49,6 +51,7 @@ public class EditCommand extends Command {
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_GRADE + "GRADE] "
+ "[" + PREFIX_SUBJECT + "SUBJECT] "
+ + "[" + PREFIX_DATETIME + "DATETIME] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
@@ -107,10 +110,11 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Grade updatedGrade = personToEdit.getGrade();
Subject updatedSubject = personToEdit.getSubject();
+ Set updatedDateTime = editPersonDescriptor.getDateTime().orElse(personToEdit.getDateTimes());
Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());
return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress,
- updatedGrade, updatedSubject, updatedTags);
+ updatedGrade, updatedSubject, updatedDateTime, updatedTags);
}
@Override
@@ -146,6 +150,7 @@ public static class EditPersonDescriptor {
private Phone phone;
private Email email;
private Address address;
+ private Set dateTime;
private Set tags;
public EditPersonDescriptor() {}
@@ -159,6 +164,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setPhone(toCopy.phone);
setEmail(toCopy.email);
setAddress(toCopy.address);
+ setDateTime(toCopy.dateTime);
setTags(toCopy.tags);
}
@@ -201,6 +207,14 @@ public Optional getAddress() {
return Optional.ofNullable(address);
}
+ public void setDateTime(Set dateTime) {
+ this.dateTime = (dateTime != null) ? new HashSet<>(dateTime) : null;
+ }
+
+ public Optional> getDateTime() {
+ return (dateTime != null) ? Optional.of(Collections.unmodifiableSet(dateTime)) : Optional.empty();
+ }
+
/**
* Sets {@code tags} to this object's {@code tags}.
* A defensive copy of {@code tags} is used internally.
diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java
index 51a45a8cf98..7532a841661 100644
--- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java
+++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java
@@ -2,6 +2,7 @@
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
+import static seedu.address.logic.parser.CliSyntax.PREFIX_DATETIME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
@@ -15,6 +16,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.DateTime;
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
@@ -36,7 +38,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_GRADE, PREFIX_SUBJECT);
+ PREFIX_GRADE, PREFIX_SUBJECT, PREFIX_DATETIME);
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL)
|| !argMultimap.getPreamble().isEmpty()) {
@@ -57,9 +59,10 @@ public AddCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_SUBJECT).isPresent()) {
subject = ParserUtil.parseSubject(argMultimap.getValue(PREFIX_SUBJECT).get());
}
+ Set dateTimeList = ParserUtil.parseDateTimes(argMultimap.getAllValues(PREFIX_DATETIME));
Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));
- Person student = new Person(name, phone, email, address, grade, subject, tagList);
+ Person student = new Person(name, phone, email, address, grade, subject, dateTimeList, tagList);
return new AddCommand(student);
}
diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java
index 320743a43c4..99ed37079fc 100644
--- a/src/main/java/seedu/address/logic/parser/CliSyntax.java
+++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java
@@ -13,4 +13,5 @@ public class CliSyntax {
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_GRADE = new Prefix("g/");
public static final Prefix PREFIX_SUBJECT = new Prefix("s/");
+ public static final Prefix PREFIX_DATETIME = new Prefix("d/");
}
diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java
index fb377de4813..f3a2e1d5cc5 100644
--- a/src/main/java/seedu/address/logic/parser/ParserUtil.java
+++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java
@@ -10,6 +10,7 @@
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Address;
+import seedu.address.model.person.DateTime;
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
@@ -153,4 +154,22 @@ public static Subject parseSubject(String subject) throws ParseException {
}
return new Subject(trimmedSubject);
}
+
+ public static DateTime parseDateTime(String dateTime) throws ParseException {
+ requireNonNull(dateTime);
+ String trimmedDateTime = dateTime.trim();
+ if (!DateTime.isValidDateTime(trimmedDateTime)) {
+ throw new ParseException(DateTime.MESSAGE_CONSTRAINTS);
+ }
+ return new DateTime(trimmedDateTime);
+ }
+
+ public static Set parseDateTimes(Collection dateTimes) throws ParseException {
+ requireNonNull(dateTimes);
+ final Set dateTimeSet = new HashSet<>();
+ for (String dateTime : dateTimes) {
+ dateTimeSet.add(parseDateTime(dateTime));
+ }
+ return dateTimeSet;
+ }
}
diff --git a/src/main/java/seedu/address/model/person/DateTime.java b/src/main/java/seedu/address/model/person/DateTime.java
new file mode 100644
index 00000000000..298ba960614
--- /dev/null
+++ b/src/main/java/seedu/address/model/person/DateTime.java
@@ -0,0 +1,68 @@
+package seedu.address.model.person;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeParseException;
+import java.time.format.ResolverStyle;
+
+import static java.util.Objects.requireNonNull;
+import static seedu.address.commons.util.AppUtil.checkArgument;
+
+public class DateTime {
+ public static final String MESSAGE_CONSTRAINTS = "DateTime should be in the format yyyy-mm-dd hhmm and after current day and time";
+ public static final String VALIDATION_REGEX = "\\d{4}-\\d{2}-\\d{2} \\d{4}";
+ public static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd HHmm")
+ .withResolverStyle(ResolverStyle.STRICT);
+
+ public final String value;
+
+ /**
+ * Constructs a {@code DateTime}.
+ *
+ * @param dateTime A valid dateTime.
+ */
+ public DateTime(String dateTime) {
+ requireNonNull(dateTime);
+ checkArgument(isValidDateTime(dateTime), MESSAGE_CONSTRAINTS);
+ value = dateTime;
+ }
+
+ public static boolean isValidDateTime(String test) {
+ return test.matches(VALIDATION_REGEX) && isValidDateTimeFormat(test) && isAfterToday(test);
+ }
+
+ private static boolean isValidDateTimeFormat(String test) {
+ try {
+ formatter.parse(test);
+ return true;
+ } catch (DateTimeParseException e) {
+ return false;
+ }
+ }
+
+ private static boolean isAfterToday(String test) {
+ LocalDateTime now = LocalDateTime.now();
+ LocalDateTime dateTime = LocalDateTime.parse(test, DateTimeFormatter.ofPattern("uuuu-MM-dd HHmm"));
+ return !dateTime.isBefore(now);
+ }
+
+ @Override
+ public String toString() {
+ return '[' + value + ']';
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this) {
+ return true;
+ }
+
+ // instanceof handles nulls
+ if (!(other instanceof DateTime)) {
+ return false;
+ }
+
+ DateTime dateTime = (DateTime) other;
+ return value.equals(dateTime.value);
+ }
+}
diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java
index 00bbb58b5fc..ad745afe467 100644
--- a/src/main/java/seedu/address/model/person/Person.java
+++ b/src/main/java/seedu/address/model/person/Person.java
@@ -25,19 +25,21 @@ public class Person {
private final Address address;
private final Grade grade;
private final Subject subject;
+ private final Set dateTimes = new HashSet<>();
private final Set tags = new HashSet<>();
/**
* Every field must be present and not null.
*/
- public Person(Name name, Phone phone, Email email, Address address, Grade grade, Subject subject, Set tags) {
- requireAllNonNull(name, phone, email, address, grade, subject, tags);
+ public Person(Name name, Phone phone, Email email, Address address, Grade grade, Subject subject, Set dateTimes, Set tags) {
+ requireAllNonNull(name, phone, email, address, grade, subject, dateTimes, tags);
this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
this.grade = grade;
this.subject = subject;
+ this.dateTimes.addAll(dateTimes);
this.tags.addAll(tags);
}
@@ -64,6 +66,9 @@ public Grade getGrade() {
public Subject getSubject() {
return subject;
}
+ public Set getDateTimes() {
+ return Collections.unmodifiableSet(dateTimes);
+ }
/**
* Returns an immutable tag set, which throws {@code UnsupportedOperationException}
@@ -106,6 +111,7 @@ public boolean equals(Object other) {
&& phone.equals(otherPerson.phone)
&& email.equals(otherPerson.email)
&& address.equals(otherPerson.address)
+ && dateTimes.equals(otherPerson.dateTimes)
&& tags.equals(otherPerson.tags);
}
@@ -124,6 +130,7 @@ public String toString() {
.add("address", address)
.add("grade", grade)
.add("subject", subject)
+ .add("dateTimes", dateTimes)
.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 b0367e7f177..5ed405aef2f 100644
--- a/src/main/java/seedu/address/model/util/SampleDataUtil.java
+++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java
@@ -7,6 +7,7 @@
import seedu.address.model.AddressBook;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Address;
+import seedu.address.model.person.DateTime;
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
@@ -27,22 +28,22 @@ 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"), EMPTY_GRADE, EMPTY_SUBJECT,
- getTagSet("friends")),
+ getDateTimeSet("2024-03-02 1800"), 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"), EMPTY_GRADE, EMPTY_SUBJECT,
- getTagSet("colleagues", "friends")),
+ getDateTimeSet("2024-03-02 1800", "2024-03-04 2000"), 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"), EMPTY_GRADE, EMPTY_SUBJECT,
- getTagSet("neighbours")),
+ getDateTimeSet("2024-03-02 1800", "2024-03-21 1600"), 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"), EMPTY_GRADE, EMPTY_SUBJECT,
- getTagSet("family")),
+ getDateTimeSet("2024-03-14 2100"), 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"), EMPTY_GRADE, EMPTY_SUBJECT,
- getTagSet("classmates")),
+ getDateTimeSet("2024-03-18 2200"), 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"), EMPTY_GRADE, EMPTY_SUBJECT,
- getTagSet("colleagues"))
+ getDateTimeSet("2024-03-28 2300"), getTagSet("colleagues"))
};
}
@@ -63,4 +64,10 @@ public static Set getTagSet(String... strings) {
.collect(Collectors.toSet());
}
+ public static Set getDateTimeSet(String... strings) {
+ return Arrays.stream(strings)
+ .map(DateTime::new)
+ .collect(Collectors.toSet());
+ }
+
}
diff --git a/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java b/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java
new file mode 100644
index 00000000000..82487d77a97
--- /dev/null
+++ b/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java
@@ -0,0 +1,32 @@
+package seedu.address.storage;
+
+import seedu.address.commons.exceptions.IllegalValueException;
+import seedu.address.model.person.DateTime;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonValue;
+
+public class JsonAdaptedDateTime {
+ private final String dateTime;
+
+ @JsonCreator
+ public JsonAdaptedDateTime(String dateTime) {
+ this.dateTime = dateTime;
+ }
+
+ public JsonAdaptedDateTime(DateTime source) {
+ dateTime = source.value;
+ }
+
+ @JsonValue
+ public String getDateTime() {
+ return dateTime;
+ }
+
+ public DateTime toModelType() throws IllegalValueException {
+ if (!DateTime.isValidDateTime(dateTime)) {
+ throw new IllegalValueException(DateTime.MESSAGE_CONSTRAINTS);
+ }
+ return new DateTime(dateTime);
+ }
+}
diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java
index 4f0c8ba43b4..4ed709e21d9 100644
--- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java
+++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java
@@ -11,6 +11,7 @@
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.person.Address;
+import seedu.address.model.person.DateTime;
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
@@ -32,6 +33,7 @@ class JsonAdaptedPerson {
private final String address;
private final String grade;
private final String subject;
+ private final List dateTimes = new ArrayList<>();
private final List tags = new ArrayList<>();
/**
@@ -41,13 +43,16 @@ class JsonAdaptedPerson {
public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone,
@JsonProperty("email") String email, @JsonProperty("address") String address,
@JsonProperty("grade") String grade, @JsonProperty("subject") String subject,
- @JsonProperty("tags") List tags) {
+ @JsonProperty("dateTimes") List dateTimes, @JsonProperty("tags") List tags) {
this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
this.grade = grade;
this.subject = subject;
+ if (tags != null) {
+ this.dateTimes.addAll(dateTimes);
+ }
if (tags != null) {
this.tags.addAll(tags);
}
@@ -63,6 +68,9 @@ public JsonAdaptedPerson(Person source) {
address = source.getAddress().value;
grade = source.getGrade().value;
subject = source.getSubject().value;
+ dateTimes.addAll(source.getDateTimes().stream()
+ .map(JsonAdaptedDateTime::new)
+ .collect(Collectors.toList()));
tags.addAll(source.getTags().stream()
.map(JsonAdaptedTag::new)
.collect(Collectors.toList()));
@@ -79,6 +87,11 @@ public Person toModelType() throws IllegalValueException {
personTags.add(tag.toModelType());
}
+ final List personDateTimes = new ArrayList<>();
+ for (JsonAdaptedDateTime dateTime : dateTimes) {
+ personDateTimes.add(dateTime.toModelType());
+ }
+
if (name == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName()));
}
@@ -127,8 +140,9 @@ public Person toModelType() throws IllegalValueException {
}
final Subject modelSubject = new Subject(subject);
+ final Set modelDateTimes = new HashSet<>(personDateTimes);
final Set modelTags = new HashSet<>(personTags);
- return new Person(modelName, modelPhone, modelEmail, modelAddress, modelGrade, modelSubject, modelTags);
+ return new Person(modelName, modelPhone, modelEmail, modelAddress, modelGrade, modelSubject, modelDateTimes, modelTags);
}
}
diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java
index ca87e4f1d87..95201467405 100644
--- a/src/main/java/seedu/address/ui/PersonCard.java
+++ b/src/main/java/seedu/address/ui/PersonCard.java
@@ -1,5 +1,7 @@
package seedu.address.ui;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
import java.util.Comparator;
import javafx.fxml.FXML;
@@ -43,6 +45,8 @@ public class PersonCard extends UiPart {
@FXML
private Label subject;
@FXML
+ private FlowPane dateTimes;
+ @FXML
private FlowPane tags;
/**
@@ -58,6 +62,13 @@ public PersonCard(Person person, int displayedIndex) {
email.setText(person.getEmail().value);
grade.setText(person.getGrade().value);
subject.setText(person.getSubject().value);
+ dateTimes.setHgap(5);
+ person.getDateTimes().stream()
+ .sorted(Comparator.comparing(dateTime -> dateTime.value))
+ .forEach(dateTime -> dateTimes.getChildren()
+ .add(new Label(LocalDateTime.parse(dateTime.value,
+ DateTimeFormatter.ofPattern("uuuu-MM-dd HHmm"))
+ .format(DateTimeFormatter.ofPattern("MMM d uuuu h:mma")))));
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 9e18c41bc30..51d79475371 100644
--- a/src/main/resources/view/PersonListCard.fxml
+++ b/src/main/resources/view/PersonListCard.fxml
@@ -33,6 +33,7 @@
+
diff --git a/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json
index b79129992bb..6a9a482c548 100644
--- a/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json
+++ b/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json
@@ -6,6 +6,7 @@
"address": "123, Jurong West Ave 6, #08-111",
"grade": "A",
"subject": "English",
+ "dateTimes": [ "2024-03-02 1800" ],
"tags": [ "friends" ]
}, {
"name": "Alice Pauline",
@@ -13,6 +14,7 @@
"email": "pauline@example.com",
"grade": "A",
"subject": "Maths",
+ "dateTimes": [ "2024-03-21 1800" ],
"address": "4th street"
} ]
}
diff --git a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json
index f4fd0a9db70..4d747cf1d2f 100644
--- a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json
+++ b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json
@@ -7,6 +7,7 @@
"address" : "123, Jurong West Ave 6, #08-111",
"grade": "A",
"subject": "English",
+ "dateTimes": [ "2024-03-02 1800" ],
"tags" : [ "friends" ]
}, {
"name" : "Benson Meier",
@@ -15,6 +16,7 @@
"address" : "311, Clementi Ave 2, #02-25",
"grade": "A",
"subject": "English",
+ "dateTimes": [ "2024-03-02 1800" ],
"tags" : [ "owesMoney", "friends" ]
}, {
"name" : "Carl Kurz",
@@ -23,6 +25,7 @@
"address" : "wall street",
"grade": "A",
"subject": "English",
+ "dateTimes": [ ],
"tags" : [ ]
}, {
"name" : "Daniel Meier",
@@ -31,6 +34,7 @@
"address" : "10th street",
"grade": "A",
"subject": "English",
+ "dateTimes": [ "2024-03-02 1800" ],
"tags" : [ "friends" ]
}, {
"name" : "Elle Meyer",
@@ -39,6 +43,7 @@
"address" : "michegan ave",
"grade": "A",
"subject": "English",
+ "dateTimes": [ "2024-03-02 1800" ],
"tags" : [ ]
}, {
"name" : "Fiona Kunz",
@@ -47,6 +52,7 @@
"address" : "little tokyo",
"grade": "A",
"subject": "English",
+ "dateTimes": [ "2024-03-02 1800" ],
"tags" : [ ]
}, {
"name" : "George Best",
@@ -55,6 +61,7 @@
"address" : "4th street",
"grade": "A",
"subject": "English",
+ "dateTimes": [ "2024-03-02 1800" ],
"tags" : [ ]
} ]
}
diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java
index 7b517421502..0f5eb8a8b8d 100644
--- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java
+++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java
@@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
+import static seedu.address.logic.parser.CliSyntax.PREFIX_DATETIME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
@@ -40,6 +41,8 @@ public class CommandTestUtil {
public static final String VALID_GRADE_BOB = "B-";
public static final String VALID_SUBJECT_AMY = "Mathematics";
public static final String VALID_SUBJECT_BOB = "English";
+ public static final String VALID_DATETIME_MAR = "2024-03-04 1800";
+ public static final String VALID_DATETIME_FEB = "2024-02-03 1800";
public static final String VALID_TAG_HUSBAND = "husband";
public static final String VALID_TAG_FRIEND = "friend";
@@ -55,6 +58,8 @@ public class CommandTestUtil {
public static final String GRADE_DESC_BOB = " " + PREFIX_GRADE + VALID_GRADE_BOB;
public static final String SUBJECT_DESC_AMY = " " + PREFIX_SUBJECT + VALID_SUBJECT_AMY;
public static final String SUBJECT_DESC_BOB = " " + PREFIX_SUBJECT + VALID_SUBJECT_BOB;
+ public static final String DATETIME_DESC_MAR = " " + PREFIX_DATETIME + VALID_DATETIME_MAR;
+ public static final String DATETIME_DESC_FEB = " " + PREFIX_DATETIME + VALID_DATETIME_FEB;
public static final String TAG_DESC_FRIEND = " " + PREFIX_TAG + VALID_TAG_FRIEND;
public static final String TAG_DESC_HUSBAND = " " + PREFIX_TAG + VALID_TAG_HUSBAND;
@@ -65,6 +70,7 @@ public class CommandTestUtil {
public static final String INVALID_ADDRESS_DESC = " " + PREFIX_ADDRESS; // empty string not allowed for addresses
public static final String INVALID_GRADE_DESC = " " + PREFIX_GRADE + "C++"; // extra + not allowed
public static final String INVALID_SUBJECT_DESC = " " + PREFIX_SUBJECT; // empty string not allowed for subject
+ public static final String INVALID_DATETIME_DESC = " " + PREFIX_DATETIME + "2024-02-31 1800"; // invalid date not allowed in tags
public static final String INVALID_TAG_DESC = " " + PREFIX_TAG + "hubby*"; // '*' not allowed in tags
public static final String PREAMBLE_WHITESPACE = "\t \r \n";
diff --git a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java
index f271c6179bb..f7c84291a16 100644
--- a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java
+++ b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java
@@ -3,11 +3,14 @@
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_BOB;
+import static seedu.address.logic.commands.CommandTestUtil.DATETIME_DESC_FEB;
+import static seedu.address.logic.commands.CommandTestUtil.DATETIME_DESC_MAR;
import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.GRADE_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.GRADE_DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_ADDRESS_DESC;
+import static seedu.address.logic.commands.CommandTestUtil.INVALID_DATETIME_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_EMAIL_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_GRADE_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_NAME_DESC;
@@ -31,6 +34,7 @@
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_FRIEND;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
+import static seedu.address.logic.parser.CliSyntax.PREFIX_DATETIME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
@@ -78,7 +82,7 @@ public void parse_allFieldsPresent_success() {
@Test
public void parse_repeatedNonTagValue_failure() {
String validExpectedPersonString = NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB
- + ADDRESS_DESC_BOB + GRADE_DESC_BOB + SUBJECT_DESC_BOB + TAG_DESC_FRIEND;
+ + ADDRESS_DESC_BOB + GRADE_DESC_BOB + SUBJECT_DESC_BOB + DATETIME_DESC_FEB + TAG_DESC_FRIEND;
// multiple names
assertParseFailure(parser, NAME_DESC_AMY + validExpectedPersonString,
@@ -109,7 +113,7 @@ public void parse_repeatedNonTagValue_failure() {
validExpectedPersonString + PHONE_DESC_AMY + EMAIL_DESC_AMY + NAME_DESC_AMY + ADDRESS_DESC_AMY
+ validExpectedPersonString,
Messages.getErrorMessageForDuplicatePrefixes(PREFIX_NAME, PREFIX_ADDRESS, PREFIX_EMAIL, PREFIX_PHONE,
- PREFIX_GRADE, PREFIX_SUBJECT));
+ PREFIX_GRADE, PREFIX_SUBJECT, PREFIX_DATETIME));
// invalid value followed by valid value
@@ -175,6 +179,11 @@ public void parse_optionalFieldsMissing_success() {
expectedPerson = new PersonBuilder(AMY).withTags().withSubject("Mathematics").build();
assertParseSuccess(parser, NAME_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY + ADDRESS_DESC_AMY
+ SUBJECT_DESC_AMY, new AddCommand(expectedPerson));
+
+ // one dateTime
+ expectedPerson = new PersonBuilder(AMY).withTags().build();
+ assertParseSuccess(parser, NAME_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY + ADDRESS_DESC_AMY
+ + DATETIME_DESC_MAR, new AddCommand(expectedPerson));
}
@Test
@@ -206,31 +215,36 @@ public void parse_compulsoryFieldMissing_failure() {
public void parse_invalidValue_failure() {
// invalid name
assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB
- + GRADE_DESC_BOB + SUBJECT_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Name.MESSAGE_CONSTRAINTS);
+ + GRADE_DESC_BOB + SUBJECT_DESC_BOB + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Name.MESSAGE_CONSTRAINTS);
// invalid phone
assertParseFailure(parser, NAME_DESC_BOB + INVALID_PHONE_DESC + EMAIL_DESC_BOB + ADDRESS_DESC_BOB
- + GRADE_DESC_BOB + SUBJECT_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Phone.MESSAGE_CONSTRAINTS);
+ + GRADE_DESC_BOB + SUBJECT_DESC_BOB + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Phone.MESSAGE_CONSTRAINTS);
// invalid email
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + INVALID_EMAIL_DESC + ADDRESS_DESC_BOB
- + GRADE_DESC_BOB + SUBJECT_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Email.MESSAGE_CONSTRAINTS);
+ + GRADE_DESC_BOB + SUBJECT_DESC_BOB + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Email.MESSAGE_CONSTRAINTS);
// invalid address
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + INVALID_ADDRESS_DESC
- + GRADE_DESC_BOB + SUBJECT_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND,
+ + GRADE_DESC_BOB + SUBJECT_DESC_BOB + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND,
Address.MESSAGE_CONSTRAINTS);
// invalid grade
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB
- + INVALID_GRADE_DESC + SUBJECT_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND,
+ + INVALID_GRADE_DESC + SUBJECT_DESC_BOB + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND,
Grade.MESSAGE_CONSTRAINTS);
// invalid subject
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB
- + GRADE_DESC_BOB + INVALID_SUBJECT_DESC + TAG_DESC_HUSBAND + TAG_DESC_FRIEND,
+ + GRADE_DESC_BOB + INVALID_SUBJECT_DESC + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND,
Subject.MESSAGE_CONSTRAINTS);
+ // invalid dateTime
+ assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB
+ + GRADE_DESC_BOB + SUBJECT_DESC_BOB + INVALID_DATETIME_DESC + TAG_DESC_HUSBAND + TAG_DESC_FRIEND,
+ Address.MESSAGE_CONSTRAINTS);
+
// invalid tag
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB
+ INVALID_TAG_DESC + VALID_TAG_FRIEND, Tag.MESSAGE_CONSTRAINTS);
@@ -241,7 +255,7 @@ public void parse_invalidValue_failure() {
// non-empty preamble
assertParseFailure(parser, PREAMBLE_NON_EMPTY + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB
- + ADDRESS_DESC_BOB + GRADE_DESC_BOB + SUBJECT_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND,
+ + ADDRESS_DESC_BOB + GRADE_DESC_BOB + SUBJECT_DESC_BOB + DATETIME_DESC_FEB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND,
String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}
}
diff --git a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java
index 7a7319c1c90..0c1c962176e 100644
--- a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java
+++ b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java
@@ -8,6 +8,7 @@
import java.util.Arrays;
import java.util.Collections;
+import java.util.Date;
import java.util.HashSet;
import java.util.Set;
@@ -15,6 +16,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Address;
+import seedu.address.model.person.DateTime;
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
@@ -29,6 +31,7 @@ public class ParserUtilTest {
private static final String INVALID_EMAIL = "example.com";
private static final String INVALID_GRADE = "C++";
private static final String INVALID_SUBJECT = " ";
+ private static final String INVALID_DATETIME = "2024-02-31 2500";
private static final String INVALID_TAG = "#friend";
private static final String VALID_NAME = "Rachel Walker";
@@ -37,6 +40,8 @@ public class ParserUtilTest {
private static final String VALID_EMAIL = "rachel@example.com";
private static final String VALID_GRADE = "B-";
private static final String VALID_SUBJECT = "English";
+ private static final String VALID_DATETIME_1 = "2024-02-03 1800";
+ private static final String VALID_DATETIME_2 = "2024-03-04 1900";
private static final String VALID_TAG_1 = "friend";
private static final String VALID_TAG_2 = "neighbour";
@@ -200,6 +205,52 @@ void parseSubject_validValueWithWhitespace_returnsTrimmedSubject() throws Except
assertEquals(expectedSubject, ParserUtil.parseSubject(subjectWithWhitespace));
}
+ @Test
+ public void parseDateTime_null_throwsNullPointerException() {
+ assertThrows(NullPointerException.class, () -> ParserUtil.parseDateTime(null));
+ }
+
+ @Test
+ public void parseDateTime_invalidValue_throwsParseException() {
+ assertThrows(ParseException.class, () -> ParserUtil.parseDateTime(INVALID_DATETIME));
+ }
+
+ @Test
+ public void parseDateTime_validValueWithoutWhitespace_returnsDateTime() throws Exception {
+ DateTime expectedDateTime = new DateTime(VALID_DATETIME_1);
+ assertEquals(expectedDateTime, ParserUtil.parseDateTime(VALID_DATETIME_1));
+ }
+
+ @Test
+ public void parseDateTime_validValueWithWhitespace_returnsTrimmedDateTime() throws Exception {
+ String dateTimeWithWhitespace = WHITESPACE + VALID_DATETIME_1 + WHITESPACE;
+ DateTime expectedDateTime = new DateTime(VALID_DATETIME_1);
+ assertEquals(expectedDateTime, ParserUtil.parseDateTime(dateTimeWithWhitespace));
+ }
+
+ @Test
+ public void parseDateTimes_null_throwsNullPointerException() {
+ assertThrows(NullPointerException.class, () -> ParserUtil.parseDateTimes(null));
+ }
+
+ @Test
+ public void parseDateTimes_collectionWithInvalidDateTimes_throwsParseException() {
+ assertThrows(ParseException.class, () -> ParserUtil.parseDateTimes(Arrays.asList(VALID_DATETIME_1, INVALID_DATETIME)));
+ }
+
+ @Test
+ public void parseDateTimes_emptyCollection_returnsEmptySet() throws Exception {
+ assertTrue(ParserUtil.parseDateTimes(Collections.emptyList()).isEmpty());
+ }
+
+ @Test
+ public void parseDateTimes_collectionWithValidDateTimes_returnsDateTimeSet() throws Exception {
+ Set actualDateTimeSet = ParserUtil.parseDateTimes(Arrays.asList(VALID_DATETIME_1, VALID_DATETIME_2));
+ Set expectedDateTimeSet = new HashSet(Arrays.asList(new DateTime(VALID_DATETIME_1), new DateTime(VALID_DATETIME_2)));
+
+ assertEquals(expectedDateTimeSet, actualDateTimeSet);
+ }
+
@Test
public void parseTag_null_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> ParserUtil.parseTag(null));
diff --git a/src/test/java/seedu/address/model/person/DateTimeTest.java b/src/test/java/seedu/address/model/person/DateTimeTest.java
new file mode 100644
index 00000000000..d78181f9e85
--- /dev/null
+++ b/src/test/java/seedu/address/model/person/DateTimeTest.java
@@ -0,0 +1,24 @@
+package seedu.address.model.person;
+
+import static seedu.address.testutil.Assert.assertThrows;
+
+import org.junit.jupiter.api.Test;
+
+public class DateTimeTest {
+ @Test
+ public void constructor_null_throwsNullPointerException() {
+ assertThrows(NullPointerException.class, () -> new DateTime(null));
+ }
+
+ @Test
+ public void constructor_invalidDateTime_throwsIllegalArgumentException() {
+ String invalidDateTime = "";
+ assertThrows(IllegalArgumentException.class, () -> new DateTime(invalidDateTime));
+ }
+
+ @Test
+ public void isValidDateTime() {
+ // null tag name
+ assertThrows(NullPointerException.class, () -> DateTime.isValidDateTime(null));
+ }
+}
diff --git a/src/test/java/seedu/address/model/person/PersonTest.java b/src/test/java/seedu/address/model/person/PersonTest.java
index ffba9b88cc4..5f54fe3d3c8 100644
--- a/src/test/java/seedu/address/model/person/PersonTest.java
+++ b/src/test/java/seedu/address/model/person/PersonTest.java
@@ -94,7 +94,8 @@ public void equals() {
public void toStringMethod() {
String expected = Person.class.getCanonicalName() + "{name=" + ALICE.getName() + ", phone=" + ALICE.getPhone()
+ ", email=" + ALICE.getEmail() + ", address=" + ALICE.getAddress()
- + ", grade=" + ALICE.getGrade() + ", subject=" + ALICE.getSubject() + ", tags=" + ALICE.getTags() + "}";
+ + ", grade=" + ALICE.getGrade() + ", subject=" + ALICE.getSubject()
+ + ", dateTimes =" + ALICE.getDateTimes() + ", tags=" + ALICE.getTags() + "}";
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 de9ff23b7a1..6f0b337d65c 100644
--- a/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java
+++ b/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java
@@ -13,6 +13,7 @@
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.person.Address;
+import seedu.address.model.person.DateTime;
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
@@ -26,6 +27,7 @@ public class JsonAdaptedPersonTest {
private static final String INVALID_EMAIL = "example.com";
private static final String INVALID_GRADE = "E";
private static final String INVALID_SUBJECT = " ";
+ private static final String INVALID_DATETIME = "2024-02-31 2500";
private static final String INVALID_TAG = "#friend";
private static final String VALID_NAME = BENSON.getName().toString();
@@ -34,6 +36,9 @@ public class JsonAdaptedPersonTest {
private static final String VALID_ADDRESS = BENSON.getAddress().toString();
private static final String VALID_GRADE = BENSON.getGrade().toString();
private static final String VALID_SUBJECT = BENSON.getSubject().toString();
+ private static final List VALID_DATETIME = BENSON.getDateTimes().stream()
+ .map(JsonAdaptedDateTime::new)
+ .collect(Collectors.toList());
private static final List VALID_TAGS = BENSON.getTags().stream()
.map(JsonAdaptedTag::new)
.collect(Collectors.toList());
@@ -48,7 +53,7 @@ public void toModelType_validPersonDetails_returnsPerson() throws Exception {
public void toModelType_invalidName_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(INVALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
- VALID_GRADE, VALID_SUBJECT, VALID_TAGS);
+ VALID_GRADE, VALID_SUBJECT, VALID_DATETIME, VALID_TAGS);
String expectedMessage = Name.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
@@ -56,7 +61,7 @@ public void toModelType_invalidName_throwsIllegalValueException() {
@Test
public void toModelType_nullName_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(null, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
- VALID_GRADE, VALID_SUBJECT, VALID_TAGS);
+ VALID_GRADE, VALID_SUBJECT, VALID_DATETIME, VALID_TAGS);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
@@ -65,7 +70,7 @@ public void toModelType_nullName_throwsIllegalValueException() {
public void toModelType_invalidPhone_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, INVALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
- VALID_GRADE, VALID_SUBJECT, VALID_TAGS);
+ VALID_GRADE, VALID_SUBJECT, VALID_DATETIME, VALID_TAGS);
String expectedMessage = Phone.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
@@ -73,7 +78,7 @@ public void toModelType_invalidPhone_throwsIllegalValueException() {
@Test
public void toModelType_nullPhone_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, null, VALID_EMAIL, VALID_ADDRESS,
- VALID_GRADE, VALID_SUBJECT, VALID_TAGS);
+ VALID_GRADE, VALID_SUBJECT, VALID_DATETIME, VALID_TAGS);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
@@ -82,7 +87,7 @@ public void toModelType_nullPhone_throwsIllegalValueException() {
public void toModelType_invalidEmail_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, INVALID_EMAIL, VALID_ADDRESS,
- VALID_GRADE, VALID_SUBJECT, VALID_TAGS);
+ VALID_GRADE, VALID_SUBJECT, VALID_DATETIME, VALID_TAGS);
String expectedMessage = Email.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
@@ -90,7 +95,7 @@ public void toModelType_invalidEmail_throwsIllegalValueException() {
@Test
public void toModelType_nullEmail_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, null, VALID_ADDRESS,
- VALID_GRADE, VALID_SUBJECT, VALID_TAGS);
+ VALID_GRADE, VALID_SUBJECT, VALID_DATETIME, VALID_TAGS);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
@@ -99,7 +104,7 @@ public void toModelType_nullEmail_throwsIllegalValueException() {
public void toModelType_invalidAddress_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_ADDRESS,
- VALID_GRADE, VALID_SUBJECT, VALID_TAGS);
+ VALID_GRADE, VALID_SUBJECT, VALID_DATETIME, VALID_TAGS);
String expectedMessage = Address.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
@@ -107,7 +112,7 @@ public void toModelType_invalidAddress_throwsIllegalValueException() {
@Test
public void toModelType_nullAddress_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, null,
- VALID_GRADE, VALID_SUBJECT, VALID_TAGS);
+ VALID_GRADE, VALID_SUBJECT, VALID_DATETIME, VALID_TAGS);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
@@ -116,7 +121,7 @@ public void toModelType_nullAddress_throwsIllegalValueException() {
public void toModelType_invalidGrade_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
- INVALID_GRADE, VALID_SUBJECT, VALID_TAGS);
+ INVALID_GRADE, VALID_SUBJECT, VALID_DATETIME, VALID_TAGS);
String expectedMessage = Grade.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
@@ -124,7 +129,7 @@ public void toModelType_invalidGrade_throwsIllegalValueException() {
@Test
public void toModelType_nullGrade_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
- null, VALID_SUBJECT, VALID_TAGS);
+ null, VALID_SUBJECT, VALID_DATETIME, VALID_TAGS);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Grade.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
@@ -133,7 +138,7 @@ public void toModelType_nullGrade_throwsIllegalValueException() {
public void toModelType_invalidSubject_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
- VALID_GRADE, INVALID_SUBJECT, VALID_TAGS);
+ VALID_GRADE, INVALID_SUBJECT, VALID_DATETIME, VALID_TAGS);
String expectedMessage = Subject.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
@@ -141,18 +146,28 @@ public void toModelType_invalidSubject_throwsIllegalValueException() {
@Test
public void toModelType_nullSubject_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
- VALID_GRADE, null, VALID_TAGS);
+ VALID_GRADE, null, VALID_DATETIME, VALID_TAGS);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Subject.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
+ @Test
+ public void toModelType_invalidDateTimes_throwsIllegalValueException() {
+ List invalidDateTimes = new ArrayList<>(VALID_DATETIME);
+ invalidDateTimes.add(new JsonAdaptedDateTime(INVALID_DATETIME));
+ JsonAdaptedPerson person =
+ new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS,
+ VALID_GRADE, VALID_SUBJECT, invalidDateTimes, VALID_TAGS);
+ assertThrows(IllegalValueException.class, person::toModelType);
+ }
+
@Test
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,
- VALID_GRADE, VALID_SUBJECT, invalidTags);
+ VALID_GRADE, VALID_SUBJECT, VALID_DATETIME, invalidTags);
assertThrows(IllegalValueException.class, person::toModelType);
}
diff --git a/src/test/java/seedu/address/testutil/PersonBuilder.java b/src/test/java/seedu/address/testutil/PersonBuilder.java
index c243794c388..b299c5cb137 100644
--- a/src/test/java/seedu/address/testutil/PersonBuilder.java
+++ b/src/test/java/seedu/address/testutil/PersonBuilder.java
@@ -4,6 +4,7 @@
import java.util.Set;
import seedu.address.model.person.Address;
+import seedu.address.model.person.DateTime;
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
@@ -31,6 +32,7 @@ public class PersonBuilder {
private Address address;
private Grade grade;
private Subject subject;
+ private Set dateTimes;
private Set tags;
/**
@@ -43,6 +45,7 @@ public PersonBuilder() {
address = new Address(DEFAULT_ADDRESS);
grade = new Grade(DEFAULT_GRADE);
subject = new Subject(DEFAULT_SUBJECT);
+ dateTimes = new HashSet<>();
tags = new HashSet<>();
}
@@ -56,6 +59,7 @@ public PersonBuilder(Person personToCopy) {
address = personToCopy.getAddress();
grade = personToCopy.getGrade();
subject = personToCopy.getSubject();
+ dateTimes = new HashSet<>(personToCopy.getDateTimes());
tags = new HashSet<>(personToCopy.getTags());
}
@@ -115,8 +119,16 @@ public PersonBuilder withSubject(String subject) {
return this;
}
+ /**
+ * Sets the {@code DateTime} of the {@code Person} that we are building.
+ */
+ public PersonBuilder withDateTimes(String ... dateTimes) {
+ this.dateTimes = SampleDataUtil.getDateTimeSet(dateTimes);
+ return this;
+ }
+
public Person build() {
- return new Person(name, phone, email, address, grade, subject, tags);
+ return new Person(name, phone, email, address, grade, subject, dateTimes, tags);
}
}
diff --git a/src/test/java/seedu/address/testutil/TypicalPersons.java b/src/test/java/seedu/address/testutil/TypicalPersons.java
index 160ec2e7785..a966bd03afe 100644
--- a/src/test/java/seedu/address/testutil/TypicalPersons.java
+++ b/src/test/java/seedu/address/testutil/TypicalPersons.java
@@ -33,19 +33,19 @@ public class TypicalPersons {
.withTags("owesMoney", "friends").build();
public static final Person CARL = new PersonBuilder().withName("Carl Kurz").withPhone("95352563")
.withEmail("heinz@example.com").withAddress("wall street")
- .withGrade("A").withSubject("Maths").build();
+ .withDateTimes("2024-03-02 1800").withGrade("A").withSubject("Maths").build();
public static final Person DANIEL = new PersonBuilder().withName("Daniel Meier").withPhone("87652533")
.withEmail("cornelia@example.com").withAddress("10th street")
- .withGrade("B+").withSubject("Maths").withTags("friends").build();
+ .withDateTimes("2024-04-02 1900").withGrade("B+").withSubject("Maths").withTags("friends").build();
public static final Person ELLE = new PersonBuilder().withName("Elle Meyer").withPhone("9482224")
.withEmail("werner@example.com").withAddress("michegan ave")
- .withGrade("B-").withSubject("English").build();
+ .withDateTimes("2024-05-02 2000").withGrade("B-").withSubject("English").build();
public static final Person FIONA = new PersonBuilder().withName("Fiona Kunz").withPhone("9482427")
.withEmail("lydia@example.com").withAddress("little tokyo")
- .withGrade("C").withSubject("English").build();
+ .withDateTimes("2024-06-02 2100").withGrade("C").withSubject("English").build();
public static final Person GEORGE = new PersonBuilder().withName("George Best").withPhone("9482442")
.withEmail("anna@example.com").withAddress("4th street")
- .withGrade("D").withSubject("Chinese").build();
+ .withDateTimes("2024-07-02 2200").withGrade("D").withSubject("Chinese").build();
// Manually added
public static final Person HOON = new PersonBuilder().withName("Hoon Meier").withPhone("8482424")
From 87f1df003ac8198254363158e533e0374dff38fa Mon Sep 17 00:00:00 2001
From: Hwww23 <122247552+Hwww23@users.noreply.github.com>
Date: Tue, 19 Mar 2024 22:11:27 +0800
Subject: [PATCH 02/10] Update for build error
---
README.md | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index 7b6fc847036..9c4ea0200ec 100644
--- a/README.md
+++ b/README.md
@@ -6,15 +6,14 @@
This project is an application designed to help tutors efficiently manage students. 👩🏫👨🏫
### Value Proposition
-Provide tutors with access to contact details and schedules of their students.
-- Allows the tutor to view the students that they are currently teaching in one glance.
-- Allows updating contact details
+Provide tutors with access to contact details and schedules of their students.
+- Allows the tutor to view the students that they are currently teaching in one glance.
+- Allows updating contact details
- Provides easy lookup of students
-- Filter contacts by subjects or grade level
+- Filter contacts by subjects or grade level
- Shows fee details of student
For the detailed documentation of this project, see [TutorsGo Product Website](https://ay2324s2-cs2103-f15-2.github.io/tp/)
### Acknowledgements
* This project is based on the AddressBook-Level3 project created by the [SE-EDU initiative](https://se-education.org).
-
From 7b13fe5a346f0329660c393311f6dc0928fa0348 Mon Sep 17 00:00:00 2001
From: Hwww23 <122247552+Hwww23@users.noreply.github.com>
Date: Tue, 19 Mar 2024 22:37:13 +0800
Subject: [PATCH 03/10] no message
---
.../seedu/address/model/person/DateTime.java | 136 +++++++++---------
.../address/storage/JsonAdaptedDateTime.java | 64 ++++-----
.../address/model/person/DateTimeTest.java | 48 +++----
3 files changed, 124 insertions(+), 124 deletions(-)
diff --git a/src/main/java/seedu/address/model/person/DateTime.java b/src/main/java/seedu/address/model/person/DateTime.java
index 298ba960614..c4d94d37d11 100644
--- a/src/main/java/seedu/address/model/person/DateTime.java
+++ b/src/main/java/seedu/address/model/person/DateTime.java
@@ -1,68 +1,68 @@
-package seedu.address.model.person;
-
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-import java.time.format.DateTimeParseException;
-import java.time.format.ResolverStyle;
-
-import static java.util.Objects.requireNonNull;
-import static seedu.address.commons.util.AppUtil.checkArgument;
-
-public class DateTime {
- public static final String MESSAGE_CONSTRAINTS = "DateTime should be in the format yyyy-mm-dd hhmm and after current day and time";
- public static final String VALIDATION_REGEX = "\\d{4}-\\d{2}-\\d{2} \\d{4}";
- public static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd HHmm")
- .withResolverStyle(ResolverStyle.STRICT);
-
- public final String value;
-
- /**
- * Constructs a {@code DateTime}.
- *
- * @param dateTime A valid dateTime.
- */
- public DateTime(String dateTime) {
- requireNonNull(dateTime);
- checkArgument(isValidDateTime(dateTime), MESSAGE_CONSTRAINTS);
- value = dateTime;
- }
-
- public static boolean isValidDateTime(String test) {
- return test.matches(VALIDATION_REGEX) && isValidDateTimeFormat(test) && isAfterToday(test);
- }
-
- private static boolean isValidDateTimeFormat(String test) {
- try {
- formatter.parse(test);
- return true;
- } catch (DateTimeParseException e) {
- return false;
- }
- }
-
- private static boolean isAfterToday(String test) {
- LocalDateTime now = LocalDateTime.now();
- LocalDateTime dateTime = LocalDateTime.parse(test, DateTimeFormatter.ofPattern("uuuu-MM-dd HHmm"));
- return !dateTime.isBefore(now);
- }
-
- @Override
- public String toString() {
- return '[' + value + ']';
- }
-
- @Override
- public boolean equals(Object other) {
- if (other == this) {
- return true;
- }
-
- // instanceof handles nulls
- if (!(other instanceof DateTime)) {
- return false;
- }
-
- DateTime dateTime = (DateTime) other;
- return value.equals(dateTime.value);
- }
-}
+package seedu.address.model.person;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeParseException;
+import java.time.format.ResolverStyle;
+
+import static java.util.Objects.requireNonNull;
+import static seedu.address.commons.util.AppUtil.checkArgument;
+
+public class DateTime {
+ public static final String MESSAGE_CONSTRAINTS = "DateTime should be in the format yyyy-mm-dd hhmm and after current day and time";
+ public static final String VALIDATION_REGEX = "\\d{4}-\\d{2}-\\d{2} \\d{4}";
+ public static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd HHmm")
+ .withResolverStyle(ResolverStyle.STRICT);
+
+ public final String value;
+
+ /**
+ * Constructs a {@code DateTime}.
+ *
+ * @param dateTime A valid dateTime.
+ */
+ public DateTime(String dateTime) {
+ requireNonNull(dateTime);
+ checkArgument(isValidDateTime(dateTime), MESSAGE_CONSTRAINTS);
+ value = dateTime;
+ }
+
+ public static boolean isValidDateTime(String test) {
+ return test.matches(VALIDATION_REGEX) && isValidDateTimeFormat(test) && isAfterToday(test);
+ }
+
+ private static boolean isValidDateTimeFormat(String test) {
+ try {
+ formatter.parse(test);
+ return true;
+ } catch (DateTimeParseException e) {
+ return false;
+ }
+ }
+
+ private static boolean isAfterToday(String test) {
+ LocalDateTime now = LocalDateTime.now();
+ LocalDateTime dateTime = LocalDateTime.parse(test, DateTimeFormatter.ofPattern("uuuu-MM-dd HHmm"));
+ return !dateTime.isBefore(now);
+ }
+
+ @Override
+ public String toString() {
+ return '[' + value + ']';
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this) {
+ return true;
+ }
+
+ // instanceof handles nulls
+ if (!(other instanceof DateTime)) {
+ return false;
+ }
+
+ DateTime dateTime = (DateTime) other;
+ return value.equals(dateTime.value);
+ }
+}
diff --git a/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java b/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java
index 82487d77a97..5a99e61bc81 100644
--- a/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java
+++ b/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java
@@ -1,32 +1,32 @@
-package seedu.address.storage;
-
-import seedu.address.commons.exceptions.IllegalValueException;
-import seedu.address.model.person.DateTime;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonValue;
-
-public class JsonAdaptedDateTime {
- private final String dateTime;
-
- @JsonCreator
- public JsonAdaptedDateTime(String dateTime) {
- this.dateTime = dateTime;
- }
-
- public JsonAdaptedDateTime(DateTime source) {
- dateTime = source.value;
- }
-
- @JsonValue
- public String getDateTime() {
- return dateTime;
- }
-
- public DateTime toModelType() throws IllegalValueException {
- if (!DateTime.isValidDateTime(dateTime)) {
- throw new IllegalValueException(DateTime.MESSAGE_CONSTRAINTS);
- }
- return new DateTime(dateTime);
- }
-}
+package seedu.address.storage;
+
+import seedu.address.commons.exceptions.IllegalValueException;
+import seedu.address.model.person.DateTime;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonValue;
+
+public class JsonAdaptedDateTime {
+ private final String dateTime;
+
+ @JsonCreator
+ public JsonAdaptedDateTime(String dateTime) {
+ this.dateTime = dateTime;
+ }
+
+ public JsonAdaptedDateTime(DateTime source) {
+ dateTime = source.value;
+ }
+
+ @JsonValue
+ public String getDateTime() {
+ return dateTime;
+ }
+
+ public DateTime toModelType() throws IllegalValueException {
+ if (!DateTime.isValidDateTime(dateTime)) {
+ throw new IllegalValueException(DateTime.MESSAGE_CONSTRAINTS);
+ }
+ return new DateTime(dateTime);
+ }
+}
diff --git a/src/test/java/seedu/address/model/person/DateTimeTest.java b/src/test/java/seedu/address/model/person/DateTimeTest.java
index d78181f9e85..a4ca7ed4d21 100644
--- a/src/test/java/seedu/address/model/person/DateTimeTest.java
+++ b/src/test/java/seedu/address/model/person/DateTimeTest.java
@@ -1,24 +1,24 @@
-package seedu.address.model.person;
-
-import static seedu.address.testutil.Assert.assertThrows;
-
-import org.junit.jupiter.api.Test;
-
-public class DateTimeTest {
- @Test
- public void constructor_null_throwsNullPointerException() {
- assertThrows(NullPointerException.class, () -> new DateTime(null));
- }
-
- @Test
- public void constructor_invalidDateTime_throwsIllegalArgumentException() {
- String invalidDateTime = "";
- assertThrows(IllegalArgumentException.class, () -> new DateTime(invalidDateTime));
- }
-
- @Test
- public void isValidDateTime() {
- // null tag name
- assertThrows(NullPointerException.class, () -> DateTime.isValidDateTime(null));
- }
-}
+package seedu.address.model.person;
+
+import static seedu.address.testutil.Assert.assertThrows;
+
+import org.junit.jupiter.api.Test;
+
+public class DateTimeTest {
+ @Test
+ public void constructor_null_throwsNullPointerException() {
+ assertThrows(NullPointerException.class, () -> new DateTime(null));
+ }
+
+ @Test
+ public void constructor_invalidDateTime_throwsIllegalArgumentException() {
+ String invalidDateTime = "";
+ assertThrows(IllegalArgumentException.class, () -> new DateTime(invalidDateTime));
+ }
+
+ @Test
+ public void isValidDateTime() {
+ // null tag name
+ assertThrows(NullPointerException.class, () -> DateTime.isValidDateTime(null));
+ }
+}
From 5b1d673c93b046e126bc29987e3622aa515d8770 Mon Sep 17 00:00:00 2001
From: Hwww23 <122247552+Hwww23@users.noreply.github.com>
Date: Tue, 19 Mar 2024 23:01:37 +0800
Subject: [PATCH 04/10] no message
---
.../seedu/address/logic/parser/ParserUtil.java | 9 +++++++++
.../seedu/address/model/person/DateTime.java | 17 +++++++++++------
.../java/seedu/address/model/person/Person.java | 3 ++-
.../address/storage/JsonAdaptedDateTime.java | 17 ++++++++++++++---
.../address/storage/JsonAdaptedPerson.java | 6 ++++--
5 files changed, 40 insertions(+), 12 deletions(-)
diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java
index f3a2e1d5cc5..b79f098d007 100644
--- a/src/main/java/seedu/address/logic/parser/ParserUtil.java
+++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java
@@ -155,6 +155,12 @@ public static Subject parseSubject(String subject) throws ParseException {
return new Subject(trimmedSubject);
}
+ /**
+ * Parses a {@code String dateTime} into a {@code dateTime}.
+ * Leading and trailing whitespaces will be trimmed.
+ *
+ * @throws ParseException if the given {@code dateTime} is invalid.
+ */
public static DateTime parseDateTime(String dateTime) throws ParseException {
requireNonNull(dateTime);
String trimmedDateTime = dateTime.trim();
@@ -164,6 +170,9 @@ public static DateTime parseDateTime(String dateTime) throws ParseException {
return new DateTime(trimmedDateTime);
}
+ /**
+ * Parses {@code Collection dateTimes} into a {@code Set}.
+ */
public static Set parseDateTimes(Collection dateTimes) throws ParseException {
requireNonNull(dateTimes);
final Set dateTimeSet = new HashSet<>();
diff --git a/src/main/java/seedu/address/model/person/DateTime.java b/src/main/java/seedu/address/model/person/DateTime.java
index c4d94d37d11..9ab9a12aabd 100644
--- a/src/main/java/seedu/address/model/person/DateTime.java
+++ b/src/main/java/seedu/address/model/person/DateTime.java
@@ -1,17 +1,22 @@
package seedu.address.model.person;
+import static java.util.Objects.requireNonNull;
+import static seedu.address.commons.util.AppUtil.checkArgument;
+
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.format.ResolverStyle;
-import static java.util.Objects.requireNonNull;
-import static seedu.address.commons.util.AppUtil.checkArgument;
-
+/**
+ * Represents a dateTime in the address book.
+ * Guarantees: immutable; dateTime is valid as declared in {@link #isValidDateTime(String)}
+ */
public class DateTime {
- public static final String MESSAGE_CONSTRAINTS = "DateTime should be in the format yyyy-mm-dd hhmm and after current day and time";
+ public static final String MESSAGE_CONSTRAINTS = "DateTime should be in the format yyyy-mm-dd hhmm "
+ + "and after current day and time";
public static final String VALIDATION_REGEX = "\\d{4}-\\d{2}-\\d{2} \\d{4}";
- public static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd HHmm")
+ public static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("uuuu-MM-dd HHmm")
.withResolverStyle(ResolverStyle.STRICT);
public final String value;
@@ -33,7 +38,7 @@ public static boolean isValidDateTime(String test) {
private static boolean isValidDateTimeFormat(String test) {
try {
- formatter.parse(test);
+ FORMATTER.parse(test);
return true;
} catch (DateTimeParseException e) {
return false;
diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java
index ad745afe467..50cb0b960a1 100644
--- a/src/main/java/seedu/address/model/person/Person.java
+++ b/src/main/java/seedu/address/model/person/Person.java
@@ -31,7 +31,8 @@ public class Person {
/**
* Every field must be present and not null.
*/
- public Person(Name name, Phone phone, Email email, Address address, Grade grade, Subject subject, Set dateTimes, Set tags) {
+ public Person(Name name, Phone phone, Email email, Address address, Grade grade, Subject subject
+ , Set dateTimes, Set tags) {
requireAllNonNull(name, phone, email, address, grade, subject, dateTimes, tags);
this.name = name;
this.phone = phone;
diff --git a/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java b/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java
index 5a99e61bc81..9e5d9851dd3 100644
--- a/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java
+++ b/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java
@@ -1,19 +1,25 @@
package seedu.address.storage;
-import seedu.address.commons.exceptions.IllegalValueException;
-import seedu.address.model.person.DateTime;
-
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
+import seedu.address.commons.exceptions.IllegalValueException;
+import seedu.address.model.person.DateTime;
+
public class JsonAdaptedDateTime {
private final String dateTime;
+ /**
+ * Constructs a {@code JsonAdaptedDateTime} with the given {@code dateTime}.
+ */
@JsonCreator
public JsonAdaptedDateTime(String dateTime) {
this.dateTime = dateTime;
}
+ /**
+ * Converts a given {@code DateTime} into this class for Jackson use.
+ */
public JsonAdaptedDateTime(DateTime source) {
dateTime = source.value;
}
@@ -23,6 +29,11 @@ public String getDateTime() {
return dateTime;
}
+ /**
+ * Converts this Jackson-friendly adapted dateTime object into the model's {@code dateTime} object.
+ *
+ * @throws IllegalValueException if there were any data constraints violated in the adapted dateTime.
+ */
public DateTime toModelType() throws IllegalValueException {
if (!DateTime.isValidDateTime(dateTime)) {
throw new IllegalValueException(DateTime.MESSAGE_CONSTRAINTS);
diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java
index 4ed709e21d9..e92a39568c9 100644
--- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java
+++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java
@@ -43,7 +43,8 @@ class JsonAdaptedPerson {
public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone,
@JsonProperty("email") String email, @JsonProperty("address") String address,
@JsonProperty("grade") String grade, @JsonProperty("subject") String subject,
- @JsonProperty("dateTimes") List dateTimes, @JsonProperty("tags") List tags) {
+ @JsonProperty("dateTimes") List dateTimes
+ , @JsonProperty("tags") List tags) {
this.name = name;
this.phone = phone;
this.email = email;
@@ -142,7 +143,8 @@ public Person toModelType() throws IllegalValueException {
final Set modelDateTimes = new HashSet<>(personDateTimes);
final Set modelTags = new HashSet<>(personTags);
- return new Person(modelName, modelPhone, modelEmail, modelAddress, modelGrade, modelSubject, modelDateTimes, modelTags);
+ return new Person(modelName, modelPhone, modelEmail, modelAddress, modelGrade, modelSubject
+ , modelDateTimes, modelTags);
}
}
From 55dd1382a22b1b18830525b468bbe6547bb637e2 Mon Sep 17 00:00:00 2001
From: Hwww23 <122247552+Hwww23@users.noreply.github.com>
Date: Tue, 19 Mar 2024 23:05:38 +0800
Subject: [PATCH 05/10] no message
---
src/main/java/seedu/address/model/person/Person.java | 4 ++--
.../java/seedu/address/storage/JsonAdaptedDateTime.java | 4 ++++
.../java/seedu/address/storage/JsonAdaptedPerson.java | 8 ++++----
3 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java
index 50cb0b960a1..325b02501f9 100644
--- a/src/main/java/seedu/address/model/person/Person.java
+++ b/src/main/java/seedu/address/model/person/Person.java
@@ -31,8 +31,8 @@ public class Person {
/**
* Every field must be present and not null.
*/
- public Person(Name name, Phone phone, Email email, Address address, Grade grade, Subject subject
- , Set dateTimes, Set tags) {
+ public Person(Name name, Phone phone, Email email, Address address, Grade grade, Subject subject,
+ Set dateTimes, Set tags) {
requireAllNonNull(name, phone, email, address, grade, subject, dateTimes, tags);
this.name = name;
this.phone = phone;
diff --git a/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java b/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java
index 9e5d9851dd3..62388277b5d 100644
--- a/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java
+++ b/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java
@@ -5,7 +5,11 @@
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.person.DateTime;
+import seedu.address.model.person.Person;
+/**
+ * Jackson-friendly version of {@link DateTime}.
+ */
public class JsonAdaptedDateTime {
private final String dateTime;
diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java
index e92a39568c9..2207370fffa 100644
--- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java
+++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java
@@ -43,8 +43,8 @@ class JsonAdaptedPerson {
public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone,
@JsonProperty("email") String email, @JsonProperty("address") String address,
@JsonProperty("grade") String grade, @JsonProperty("subject") String subject,
- @JsonProperty("dateTimes") List dateTimes
- , @JsonProperty("tags") List tags) {
+ @JsonProperty("dateTimes") List dateTimes,
+ @JsonProperty("tags") List tags) {
this.name = name;
this.phone = phone;
this.email = email;
@@ -143,8 +143,8 @@ public Person toModelType() throws IllegalValueException {
final Set modelDateTimes = new HashSet<>(personDateTimes);
final Set modelTags = new HashSet<>(personTags);
- return new Person(modelName, modelPhone, modelEmail, modelAddress, modelGrade, modelSubject
- , modelDateTimes, modelTags);
+ return new Person(modelName, modelPhone, modelEmail, modelAddress, modelGrade, modelSubject,
+ modelDateTimes, modelTags);
}
}
From 499da490f8617305ae57e081955ac2d24d7ff190 Mon Sep 17 00:00:00 2001
From: Hwww23 <122247552+Hwww23@users.noreply.github.com>
Date: Tue, 19 Mar 2024 23:07:29 +0800
Subject: [PATCH 06/10] no message
---
src/main/java/seedu/address/storage/JsonAdaptedDateTime.java | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java b/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java
index 62388277b5d..8faa75b62ce 100644
--- a/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java
+++ b/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java
@@ -5,7 +5,6 @@
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.person.DateTime;
-import seedu.address.model.person.Person;
/**
* Jackson-friendly version of {@link DateTime}.
From b9db5e2e9c1d69d1e74cb0beaf51937503cc8815 Mon Sep 17 00:00:00 2001
From: Hwww23 <122247552+Hwww23@users.noreply.github.com>
Date: Tue, 19 Mar 2024 23:16:52 +0800
Subject: [PATCH 07/10] no message
---
.../address/logic/commands/CommandTestUtil.java | 3 ++-
.../address/logic/parser/AddCommandParserTest.java | 13 ++++++++-----
.../seedu/address/logic/parser/ParserUtilTest.java | 7 ++++---
.../address/storage/JsonAdaptedPersonTest.java | 1 -
4 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java
index 0f5eb8a8b8d..e3327170120 100644
--- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java
+++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java
@@ -70,7 +70,8 @@ public class CommandTestUtil {
public static final String INVALID_ADDRESS_DESC = " " + PREFIX_ADDRESS; // empty string not allowed for addresses
public static final String INVALID_GRADE_DESC = " " + PREFIX_GRADE + "C++"; // extra + not allowed
public static final String INVALID_SUBJECT_DESC = " " + PREFIX_SUBJECT; // empty string not allowed for subject
- public static final String INVALID_DATETIME_DESC = " " + PREFIX_DATETIME + "2024-02-31 1800"; // invalid date not allowed in tags
+ public static final String INVALID_DATETIME_DESC = " " + PREFIX_DATETIME
+ + "2024-02-31 1800"; // invalid date not allowed in tags
public static final String INVALID_TAG_DESC = " " + PREFIX_TAG + "hubby*"; // '*' not allowed in tags
public static final String PREAMBLE_WHITESPACE = "\t \r \n";
diff --git a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java
index f7c84291a16..5d87b3ebf4d 100644
--- a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java
+++ b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java
@@ -215,15 +215,18 @@ public void parse_compulsoryFieldMissing_failure() {
public void parse_invalidValue_failure() {
// invalid name
assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB
- + GRADE_DESC_BOB + SUBJECT_DESC_BOB + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Name.MESSAGE_CONSTRAINTS);
+ + GRADE_DESC_BOB + SUBJECT_DESC_BOB + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND,
+ Name.MESSAGE_CONSTRAINTS);
// invalid phone
assertParseFailure(parser, NAME_DESC_BOB + INVALID_PHONE_DESC + EMAIL_DESC_BOB + ADDRESS_DESC_BOB
- + GRADE_DESC_BOB + SUBJECT_DESC_BOB + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Phone.MESSAGE_CONSTRAINTS);
+ + GRADE_DESC_BOB + SUBJECT_DESC_BOB + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND,
+ Phone.MESSAGE_CONSTRAINTS);
// invalid email
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + INVALID_EMAIL_DESC + ADDRESS_DESC_BOB
- + GRADE_DESC_BOB + SUBJECT_DESC_BOB + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Email.MESSAGE_CONSTRAINTS);
+ + GRADE_DESC_BOB + SUBJECT_DESC_BOB + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND,
+ Email.MESSAGE_CONSTRAINTS);
// invalid address
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + INVALID_ADDRESS_DESC
@@ -255,7 +258,7 @@ public void parse_invalidValue_failure() {
// non-empty preamble
assertParseFailure(parser, PREAMBLE_NON_EMPTY + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB
- + ADDRESS_DESC_BOB + GRADE_DESC_BOB + SUBJECT_DESC_BOB + DATETIME_DESC_FEB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND,
- String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
+ + ADDRESS_DESC_BOB + GRADE_DESC_BOB + SUBJECT_DESC_BOB + DATETIME_DESC_FEB + TAG_DESC_HUSBAND
+ + TAG_DESC_FRIEND, String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}
}
diff --git a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java
index 0c1c962176e..cb9cfde4fd3 100644
--- a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java
+++ b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java
@@ -8,7 +8,6 @@
import java.util.Arrays;
import java.util.Collections;
-import java.util.Date;
import java.util.HashSet;
import java.util.Set;
@@ -235,7 +234,8 @@ public void parseDateTimes_null_throwsNullPointerException() {
@Test
public void parseDateTimes_collectionWithInvalidDateTimes_throwsParseException() {
- assertThrows(ParseException.class, () -> ParserUtil.parseDateTimes(Arrays.asList(VALID_DATETIME_1, INVALID_DATETIME)));
+ assertThrows(ParseException.class, () -> ParserUtil.parseDateTimes(Arrays.asList(VALID_DATETIME_1,
+ INVALID_DATETIME)));
}
@Test
@@ -246,7 +246,8 @@ public void parseDateTimes_emptyCollection_returnsEmptySet() throws Exception {
@Test
public void parseDateTimes_collectionWithValidDateTimes_returnsDateTimeSet() throws Exception {
Set actualDateTimeSet = ParserUtil.parseDateTimes(Arrays.asList(VALID_DATETIME_1, VALID_DATETIME_2));
- Set expectedDateTimeSet = new HashSet(Arrays.asList(new DateTime(VALID_DATETIME_1), new DateTime(VALID_DATETIME_2)));
+ Set expectedDateTimeSet = new HashSet(Arrays.asList(new DateTime(VALID_DATETIME_1),
+ new DateTime(VALID_DATETIME_2)));
assertEquals(expectedDateTimeSet, actualDateTimeSet);
}
diff --git a/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java b/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java
index 6f0b337d65c..b81258cbc9b 100644
--- a/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java
+++ b/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java
@@ -13,7 +13,6 @@
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.person.Address;
-import seedu.address.model.person.DateTime;
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
From 67f6acf555f88775181e347cf8ca3d15e07eb4cd Mon Sep 17 00:00:00 2001
From: Hwww23 <122247552+Hwww23@users.noreply.github.com>
Date: Wed, 20 Mar 2024 00:51:04 +0800
Subject: [PATCH 08/10] Fixing gradletest issues
---
.../seedu/address/model/person/DateTime.java | 35 +++++++++----------
.../seedu/address/model/person/Person.java | 2 +-
.../typicalPersonsAddressBook.json | 14 ++++----
.../logic/parser/AddCommandParserTest.java | 10 ++----
.../address/logic/parser/ParserUtilTest.java | 2 ++
.../address/model/person/PersonTest.java | 2 +-
.../seedu/address/testutil/PersonBuilder.java | 2 +-
.../address/testutil/TypicalPersons.java | 21 +++++++----
8 files changed, 46 insertions(+), 42 deletions(-)
diff --git a/src/main/java/seedu/address/model/person/DateTime.java b/src/main/java/seedu/address/model/person/DateTime.java
index 9ab9a12aabd..fef24b789ba 100644
--- a/src/main/java/seedu/address/model/person/DateTime.java
+++ b/src/main/java/seedu/address/model/person/DateTime.java
@@ -3,7 +3,6 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;
-import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.format.ResolverStyle;
@@ -13,8 +12,7 @@
* Guarantees: immutable; dateTime is valid as declared in {@link #isValidDateTime(String)}
*/
public class DateTime {
- public static final String MESSAGE_CONSTRAINTS = "DateTime should be in the format yyyy-mm-dd hhmm "
- + "and after current day and time";
+ public static final String MESSAGE_CONSTRAINTS = "DateTime should be in the format yyyy-mm-dd hhmm";
public static final String VALIDATION_REGEX = "\\d{4}-\\d{2}-\\d{2} \\d{4}";
public static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("uuuu-MM-dd HHmm")
.withResolverStyle(ResolverStyle.STRICT);
@@ -29,11 +27,11 @@ public class DateTime {
public DateTime(String dateTime) {
requireNonNull(dateTime);
checkArgument(isValidDateTime(dateTime), MESSAGE_CONSTRAINTS);
- value = dateTime;
+ this.value = dateTime;
}
public static boolean isValidDateTime(String test) {
- return test.matches(VALIDATION_REGEX) && isValidDateTimeFormat(test) && isAfterToday(test);
+ return test.matches(VALIDATION_REGEX) && isValidDateTimeFormat(test);
}
private static boolean isValidDateTimeFormat(String test) {
@@ -45,17 +43,6 @@ private static boolean isValidDateTimeFormat(String test) {
}
}
- private static boolean isAfterToday(String test) {
- LocalDateTime now = LocalDateTime.now();
- LocalDateTime dateTime = LocalDateTime.parse(test, DateTimeFormatter.ofPattern("uuuu-MM-dd HHmm"));
- return !dateTime.isBefore(now);
- }
-
- @Override
- public String toString() {
- return '[' + value + ']';
- }
-
@Override
public boolean equals(Object other) {
if (other == this) {
@@ -67,7 +54,19 @@ public boolean equals(Object other) {
return false;
}
- DateTime dateTime = (DateTime) other;
- return value.equals(dateTime.value);
+ DateTime otherDateTime = (DateTime) other;
+ return value.equals(otherDateTime.value);
+ }
+
+ @Override
+ public int hashCode() {
+ return value.hashCode();
+ }
+
+ /**
+ * Format state as text for viewing.
+ */
+ public String toString() {
+ return '[' + value + ']';
}
}
diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java
index 325b02501f9..51f2924ca6c 100644
--- a/src/main/java/seedu/address/model/person/Person.java
+++ b/src/main/java/seedu/address/model/person/Person.java
@@ -119,7 +119,7 @@ public boolean equals(Object other) {
@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing your own
- return Objects.hash(name, phone, email, address, tags);
+ return Objects.hash(name, phone, email, address, dateTimes, tags);
}
@Override
diff --git a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json
index 4d747cf1d2f..84564f39c66 100644
--- a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json
+++ b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json
@@ -7,7 +7,7 @@
"address" : "123, Jurong West Ave 6, #08-111",
"grade": "A",
"subject": "English",
- "dateTimes": [ "2024-03-02 1800" ],
+ "dateTimes": [ ],
"tags" : [ "friends" ]
}, {
"name" : "Benson Meier",
@@ -16,7 +16,7 @@
"address" : "311, Clementi Ave 2, #02-25",
"grade": "A",
"subject": "English",
- "dateTimes": [ "2024-03-02 1800" ],
+ "dateTimes": [ "2024-02-03 1800" ],
"tags" : [ "owesMoney", "friends" ]
}, {
"name" : "Carl Kurz",
@@ -25,7 +25,7 @@
"address" : "wall street",
"grade": "A",
"subject": "English",
- "dateTimes": [ ],
+ "dateTimes": [ "2024-02-03 1800" ],
"tags" : [ ]
}, {
"name" : "Daniel Meier",
@@ -34,7 +34,7 @@
"address" : "10th street",
"grade": "A",
"subject": "English",
- "dateTimes": [ "2024-03-02 1800" ],
+ "dateTimes": [ "2024-02-03 1800" ],
"tags" : [ "friends" ]
}, {
"name" : "Elle Meyer",
@@ -43,7 +43,7 @@
"address" : "michegan ave",
"grade": "A",
"subject": "English",
- "dateTimes": [ "2024-03-02 1800" ],
+ "dateTimes": [ "2024-02-03 1800" ],
"tags" : [ ]
}, {
"name" : "Fiona Kunz",
@@ -52,7 +52,7 @@
"address" : "little tokyo",
"grade": "A",
"subject": "English",
- "dateTimes": [ "2024-03-02 1800" ],
+ "dateTimes": [ "2024-02-03 1800" ],
"tags" : [ ]
}, {
"name" : "George Best",
@@ -61,7 +61,7 @@
"address" : "4th street",
"grade": "A",
"subject": "English",
- "dateTimes": [ "2024-03-02 1800" ],
+ "dateTimes": [ "2024-02-03 1800" ],
"tags" : [ ]
} ]
}
diff --git a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java
index 5d87b3ebf4d..07d8a05dc2a 100644
--- a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java
+++ b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java
@@ -50,6 +50,7 @@
import seedu.address.logic.Messages;
import seedu.address.logic.commands.AddCommand;
import seedu.address.model.person.Address;
+import seedu.address.model.person.DateTime;
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
@@ -113,7 +114,7 @@ public void parse_repeatedNonTagValue_failure() {
validExpectedPersonString + PHONE_DESC_AMY + EMAIL_DESC_AMY + NAME_DESC_AMY + ADDRESS_DESC_AMY
+ validExpectedPersonString,
Messages.getErrorMessageForDuplicatePrefixes(PREFIX_NAME, PREFIX_ADDRESS, PREFIX_EMAIL, PREFIX_PHONE,
- PREFIX_GRADE, PREFIX_SUBJECT, PREFIX_DATETIME));
+ PREFIX_GRADE, PREFIX_SUBJECT));
// invalid value followed by valid value
@@ -179,11 +180,6 @@ public void parse_optionalFieldsMissing_success() {
expectedPerson = new PersonBuilder(AMY).withTags().withSubject("Mathematics").build();
assertParseSuccess(parser, NAME_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY + ADDRESS_DESC_AMY
+ SUBJECT_DESC_AMY, new AddCommand(expectedPerson));
-
- // one dateTime
- expectedPerson = new PersonBuilder(AMY).withTags().build();
- assertParseSuccess(parser, NAME_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY + ADDRESS_DESC_AMY
- + DATETIME_DESC_MAR, new AddCommand(expectedPerson));
}
@Test
@@ -246,7 +242,7 @@ public void parse_invalidValue_failure() {
// invalid dateTime
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB
+ GRADE_DESC_BOB + SUBJECT_DESC_BOB + INVALID_DATETIME_DESC + TAG_DESC_HUSBAND + TAG_DESC_FRIEND,
- Address.MESSAGE_CONSTRAINTS);
+ DateTime.MESSAGE_CONSTRAINTS);
// invalid tag
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB
diff --git a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java
index cb9cfde4fd3..5e88ca9f1a7 100644
--- a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java
+++ b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java
@@ -6,9 +6,11 @@
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import org.junit.jupiter.api.Test;
diff --git a/src/test/java/seedu/address/model/person/PersonTest.java b/src/test/java/seedu/address/model/person/PersonTest.java
index 5f54fe3d3c8..bcf3034eeb2 100644
--- a/src/test/java/seedu/address/model/person/PersonTest.java
+++ b/src/test/java/seedu/address/model/person/PersonTest.java
@@ -95,7 +95,7 @@ public void toStringMethod() {
String expected = Person.class.getCanonicalName() + "{name=" + ALICE.getName() + ", phone=" + ALICE.getPhone()
+ ", email=" + ALICE.getEmail() + ", address=" + ALICE.getAddress()
+ ", grade=" + ALICE.getGrade() + ", subject=" + ALICE.getSubject()
- + ", dateTimes =" + ALICE.getDateTimes() + ", tags=" + ALICE.getTags() + "}";
+ + ", dateTimes=" + ALICE.getDateTimes() + ", tags=" + ALICE.getTags() + "}";
assertEquals(expected, ALICE.toString());
}
}
diff --git a/src/test/java/seedu/address/testutil/PersonBuilder.java b/src/test/java/seedu/address/testutil/PersonBuilder.java
index b299c5cb137..094697e4e9d 100644
--- a/src/test/java/seedu/address/testutil/PersonBuilder.java
+++ b/src/test/java/seedu/address/testutil/PersonBuilder.java
@@ -24,7 +24,7 @@ public class PersonBuilder {
public static final String DEFAULT_EMAIL = "amy@gmail.com";
public static final String DEFAULT_ADDRESS = "123, Jurong West Ave 6, #08-111";
public static final String DEFAULT_GRADE = "A";
- public static final String DEFAULT_SUBJECT = "Maths";
+ public static final String DEFAULT_SUBJECT = "English";
private Name name;
private Phone phone;
diff --git a/src/test/java/seedu/address/testutil/TypicalPersons.java b/src/test/java/seedu/address/testutil/TypicalPersons.java
index a966bd03afe..cceff212610 100644
--- a/src/test/java/seedu/address/testutil/TypicalPersons.java
+++ b/src/test/java/seedu/address/testutil/TypicalPersons.java
@@ -25,27 +25,34 @@ 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")
+ .withPhone("94351253").withGrade("A").withSubject("English")
.withTags("friends").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").build();
+ .withTags("owesMoney", "friends")
+ .withDateTimes("2024-02-03 1800")
+ .withGrade("A").withSubject("English").build();
public static final Person CARL = new PersonBuilder().withName("Carl Kurz").withPhone("95352563")
.withEmail("heinz@example.com").withAddress("wall street")
- .withDateTimes("2024-03-02 1800").withGrade("A").withSubject("Maths").build();
+ .withDateTimes("2024-02-03 1800")
+ .withGrade("A").withSubject("English").build();
public static final Person DANIEL = new PersonBuilder().withName("Daniel Meier").withPhone("87652533")
.withEmail("cornelia@example.com").withAddress("10th street")
- .withDateTimes("2024-04-02 1900").withGrade("B+").withSubject("Maths").withTags("friends").build();
+ .withGrade("A").withSubject("English").withTags("friends")
+ .withDateTimes("2024-02-03 1800").build();
public static final Person ELLE = new PersonBuilder().withName("Elle Meyer").withPhone("9482224")
.withEmail("werner@example.com").withAddress("michegan ave")
- .withDateTimes("2024-05-02 2000").withGrade("B-").withSubject("English").build();
+ .withGrade("A").withSubject("English")
+ .withDateTimes("2024-02-03 1800").build();
public static final Person FIONA = new PersonBuilder().withName("Fiona Kunz").withPhone("9482427")
.withEmail("lydia@example.com").withAddress("little tokyo")
- .withDateTimes("2024-06-02 2100").withGrade("C").withSubject("English").build();
+ .withGrade("A").withSubject("English")
+ .withDateTimes("2024-02-03 1800").build();
public static final Person GEORGE = new PersonBuilder().withName("George Best").withPhone("9482442")
.withEmail("anna@example.com").withAddress("4th street")
- .withDateTimes("2024-07-02 2200").withGrade("D").withSubject("Chinese").build();
+ .withGrade("A").withSubject("English")
+ .withDateTimes("2024-02-03 1800").build();
// Manually added
public static final Person HOON = new PersonBuilder().withName("Hoon Meier").withPhone("8482424")
From 95f84975b9c2e1caaef5be54b225638d3ffde881 Mon Sep 17 00:00:00 2001
From: Hwww23 <122247552+Hwww23@users.noreply.github.com>
Date: Wed, 20 Mar 2024 00:55:11 +0800
Subject: [PATCH 09/10] no message
---
.../java/seedu/address/logic/parser/AddCommandParserTest.java | 1 -
src/test/java/seedu/address/logic/parser/ParserUtilTest.java | 2 --
2 files changed, 3 deletions(-)
diff --git a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java
index 07d8a05dc2a..72ea0019acb 100644
--- a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java
+++ b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java
@@ -34,7 +34,6 @@
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_FRIEND;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
-import static seedu.address.logic.parser.CliSyntax.PREFIX_DATETIME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
diff --git a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java
index 5e88ca9f1a7..cb9cfde4fd3 100644
--- a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java
+++ b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java
@@ -6,11 +6,9 @@
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
import org.junit.jupiter.api.Test;
From 2437d61e2601210eb6e58fcf4999036ed3b1c382 Mon Sep 17 00:00:00 2001
From: Hwww23 <122247552+Hwww23@users.noreply.github.com>
Date: Wed, 20 Mar 2024 01:17:22 +0800
Subject: [PATCH 10/10] no message
---
src/main/resources/view/DarkTheme.css | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/main/resources/view/DarkTheme.css b/src/main/resources/view/DarkTheme.css
index 36e6b001cd8..4894bcbea98 100644
--- a/src/main/resources/view/DarkTheme.css
+++ b/src/main/resources/view/DarkTheme.css
@@ -350,3 +350,12 @@
-fx-background-radius: 2;
-fx-font-size: 11;
}
+
+#dateTimes .label {
+ -fx-text-fill: white;
+ -fx-background-color: #3e7b91;
+ -fx-padding: 1 3 1 3;
+ -fx-border-radius: 2;
+ -fx-background-radius: 2;
+ -fx-font-size: 11;
+}