From afdfa165b761a9111a6ce9d78950c0d7faa10bcf Mon Sep 17 00:00:00 2001 From: Clara Date: Sun, 18 Oct 2020 21:27:39 +0800 Subject: [PATCH 01/10] Add from's LocalDateTime getter in Meeting --- .../java/seedu/address/model/meeting/meeting/Meeting.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/seedu/address/model/meeting/meeting/Meeting.java b/src/main/java/seedu/address/model/meeting/meeting/Meeting.java index 0811834e6e8..e239af0de75 100644 --- a/src/main/java/seedu/address/model/meeting/meeting/Meeting.java +++ b/src/main/java/seedu/address/model/meeting/meeting/Meeting.java @@ -2,6 +2,7 @@ import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; +import java.time.LocalDateTime; import java.util.Objects; import seedu.address.model.util.Contacts; @@ -47,6 +48,10 @@ public From getFrom() { return from; } + public LocalDateTime getFromLocalDateTime() { + return from.getLocalDateTime().get(); + } + public To getTo() { return to; } From 79d1b098d35b5fa55addfbed92112a597490032a Mon Sep 17 00:00:00 2001 From: Clara Date: Sun, 18 Oct 2020 21:44:41 +0800 Subject: [PATCH 02/10] Support sorting of internalList --- .../model/meeting/meeting/UniqueMeetingList.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/seedu/address/model/meeting/meeting/UniqueMeetingList.java b/src/main/java/seedu/address/model/meeting/meeting/UniqueMeetingList.java index e9c9855396b..ac531ce648a 100644 --- a/src/main/java/seedu/address/model/meeting/meeting/UniqueMeetingList.java +++ b/src/main/java/seedu/address/model/meeting/meeting/UniqueMeetingList.java @@ -3,6 +3,7 @@ import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; +import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -10,12 +11,14 @@ import javafx.collections.ObservableList; import seedu.address.model.meeting.meeting.exceptions.DuplicateMeetingException; import seedu.address.model.meeting.meeting.exceptions.MeetingNotFoundException; +import seedu.address.model.meeting.util.MeetingComparator; public class UniqueMeetingList implements Iterable { private final ObservableList internalList = FXCollections.observableArrayList(); private final ObservableList internalUnmodifiableList = FXCollections.unmodifiableObservableList(internalList); + private final MeetingComparator meetingComparator = new MeetingComparator(); /** * Returns true if the list contains an equivalent meeting as the given argument. @@ -35,6 +38,7 @@ public void add(Meeting toAdd) { throw new DuplicateMeetingException(); } internalList.add(toAdd); + sortList(); } /** @@ -56,6 +60,7 @@ public void setMeeting(Meeting target, Meeting editedMeeting) { } internalList.set(index, editedMeeting); + sortList(); } /** @@ -72,6 +77,7 @@ public void remove(Meeting toRemove) { public void setMeetings(UniqueMeetingList replacement) { requireNonNull(replacement); internalList.setAll(replacement.internalList); + sortList(); } /** @@ -85,6 +91,7 @@ public void setMeetings(List meetings) { } internalList.setAll(meetings); + sortList(); } /** @@ -94,8 +101,17 @@ public ObservableList asUnmodifiableObservableList() { return internalUnmodifiableList; } + /** + * Sort the list by From's value + * + */ + public void sortList() { + Collections.sort(internalList, meetingComparator); + } + @Override public Iterator iterator() { + Collections.sort(internalList, new MeetingComparator()); return internalList.iterator(); } From 5c3ae1beb96cd1f195dc3cadb568e9ab94b1867c Mon Sep 17 00:00:00 2001 From: Clara Date: Sun, 18 Oct 2020 21:45:13 +0800 Subject: [PATCH 03/10] Add getter for DateTime's value --- src/main/java/seedu/address/model/util/DateTime.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/seedu/address/model/util/DateTime.java b/src/main/java/seedu/address/model/util/DateTime.java index 93ba13c7d5a..b7d6a082550 100644 --- a/src/main/java/seedu/address/model/util/DateTime.java +++ b/src/main/java/seedu/address/model/util/DateTime.java @@ -87,6 +87,15 @@ public DateTime(Optional date) { } + /** + * Returns the LocalDateTime value object. + * + * @return the value of DateTime. + */ + public Optional getLocalDateTime() { + return value; + } + /** * Returns true if a given string is a valid DateTime. * From 0b70a18199ae18e918828f09ef9445f5425bfe75 Mon Sep 17 00:00:00 2001 From: Clara Date: Sun, 18 Oct 2020 21:45:37 +0800 Subject: [PATCH 04/10] Add comparator for meeting, sorted by From --- .../model/meeting/util/MeetingComparator.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/java/seedu/address/model/meeting/util/MeetingComparator.java diff --git a/src/main/java/seedu/address/model/meeting/util/MeetingComparator.java b/src/main/java/seedu/address/model/meeting/util/MeetingComparator.java new file mode 100644 index 00000000000..064fb89ccbc --- /dev/null +++ b/src/main/java/seedu/address/model/meeting/util/MeetingComparator.java @@ -0,0 +1,15 @@ +package seedu.address.model.meeting.util; + +import java.time.LocalDateTime; +import java.util.Comparator; + +import seedu.address.model.meeting.meeting.Meeting; + +public class MeetingComparator implements Comparator { + public int compare(Meeting a, Meeting b) { + LocalDateTime aFrom = a.getFromLocalDateTime(); + LocalDateTime bFrom = b.getFromLocalDateTime(); + + return aFrom.compareTo(bFrom); + } +} From 0bca6cc0e582434154f7d9f92af6e2ef0d00166e Mon Sep 17 00:00:00 2001 From: Clara Date: Sun, 18 Oct 2020 21:57:44 +0800 Subject: [PATCH 05/10] Add javadoc for MeetingComparator --- .../seedu/address/model/meeting/util/MeetingComparator.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/seedu/address/model/meeting/util/MeetingComparator.java b/src/main/java/seedu/address/model/meeting/util/MeetingComparator.java index 064fb89ccbc..85176eb9725 100644 --- a/src/main/java/seedu/address/model/meeting/util/MeetingComparator.java +++ b/src/main/java/seedu/address/model/meeting/util/MeetingComparator.java @@ -5,7 +5,13 @@ import seedu.address.model.meeting.meeting.Meeting; +/** + * Represents a Comparator for Meeting which sorts by From. + */ public class MeetingComparator implements Comparator { + /** + * Compares Meetings by From in ascending order. + */ public int compare(Meeting a, Meeting b) { LocalDateTime aFrom = a.getFromLocalDateTime(); LocalDateTime bFrom = b.getFromLocalDateTime(); From 00f570d759de7b809e2128f013ef38841fc31610 Mon Sep 17 00:00:00 2001 From: Clara Date: Sun, 18 Oct 2020 22:50:58 +0800 Subject: [PATCH 06/10] Support sorting when constructing MeetingBook using toBeCopied Meetings --- .../java/seedu/address/model/meeting/MeetingBook.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/seedu/address/model/meeting/MeetingBook.java b/src/main/java/seedu/address/model/meeting/MeetingBook.java index 5c8068d8512..199ea95c7b7 100644 --- a/src/main/java/seedu/address/model/meeting/MeetingBook.java +++ b/src/main/java/seedu/address/model/meeting/MeetingBook.java @@ -27,6 +27,14 @@ public MeetingBook() {} public MeetingBook(ReadOnlyMeetingBook toBeCopied) { this(); resetData(toBeCopied); + sortMeetings(); + } + + /** + * Sorts the content of the meeting list by From in ascending order. + */ + public void sortMeetings() { + this.meetings.sortList(); } /** From a36300f702051f3b22e61de31f926fa827d60b7d Mon Sep 17 00:00:00 2001 From: Clara Date: Sun, 18 Oct 2020 22:53:00 +0800 Subject: [PATCH 07/10] Ensure list is sorted before iterating --- .../seedu/address/model/meeting/meeting/UniqueMeetingList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/model/meeting/meeting/UniqueMeetingList.java b/src/main/java/seedu/address/model/meeting/meeting/UniqueMeetingList.java index ac531ce648a..fa3db340fb2 100644 --- a/src/main/java/seedu/address/model/meeting/meeting/UniqueMeetingList.java +++ b/src/main/java/seedu/address/model/meeting/meeting/UniqueMeetingList.java @@ -111,7 +111,7 @@ public void sortList() { @Override public Iterator iterator() { - Collections.sort(internalList, new MeetingComparator()); + sortList(); return internalList.iterator(); } From 4bbf1064b339bbeac8d85a773752f55c9faaa518 Mon Sep 17 00:00:00 2001 From: Clara Date: Sun, 18 Oct 2020 22:54:09 +0800 Subject: [PATCH 08/10] Fix From ordering of test case TypicalMeetings's ArrayList --- src/test/java/seedu/address/testutil/TypicalMeetings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/seedu/address/testutil/TypicalMeetings.java b/src/test/java/seedu/address/testutil/TypicalMeetings.java index 993748ad04d..991a71a99c9 100644 --- a/src/test/java/seedu/address/testutil/TypicalMeetings.java +++ b/src/test/java/seedu/address/testutil/TypicalMeetings.java @@ -83,6 +83,6 @@ public static MeetingBook getTypicalMeetingBook() { } public static List getTypicalMeeting() { - return new ArrayList<>(Arrays.asList(MEETING_A, MEETING_B)); + return new ArrayList<>(Arrays.asList(MEETING_B, MEETING_A)); } } From 8a7b1a4bca318494a178778338a4b618f53d2611 Mon Sep 17 00:00:00 2001 From: Clara Date: Mon, 19 Oct 2020 00:06:33 +0800 Subject: [PATCH 09/10] Switch ordering of From and To in MeetingListCard --- src/main/resources/view/MeetingListCard.fxml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/view/MeetingListCard.fxml b/src/main/resources/view/MeetingListCard.fxml index 9aeaca1a77c..e51427e0862 100644 --- a/src/main/resources/view/MeetingListCard.fxml +++ b/src/main/resources/view/MeetingListCard.fxml @@ -27,8 +27,8 @@