forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from whitesnowx/133-multiplesorting
Sort Persons Functionality for MeetingList & Implement MultiComparator to Sort multiple attributes
- Loading branch information
Showing
25 changed files
with
553 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,9 +163,13 @@ Format: `sort [ATTRIBUTE]` | |
* The order of character priority would be letters (A-Z), numbers (0-9), special characters (!@#$%^&*). | ||
* The capitalisation of the letters do not affect their priority such that `Aaron` will have same priority as `aaron`. | ||
* For attribute with exact same values, the tie-breaker is determined by their added order. | ||
* For sorting of multiple attributes, the weightage will be determined by the order in which it was entered. E.g `sort m/ p/ v/` will sort by contact by their module, among those with equal modules would then be sorted by their phone number and similarly for venue. | ||
* `[ATTRIBUTE]` is to be noted by their prefix. e.g `name` will be `n/`. | ||
* `s/` sorts contacts by person with the earliest meeting | ||
* `meet/` sorts contacts by person with the earliest meeting, followed by alphanumeric order of meeting description | ||
|
||
Examples: | ||
* `sort m/ p/` returns person by ascending module codes followed by ascending phone numbers `CS2000 80000000`, `CS2000 90000000`, `CS3000 80000000`followed by `CS3000 90000000` | ||
* `sort n/` returns person by ascending names `Alex`, `Bernice` followed by `Charlotte` | ||
* `sort p/` returns person by ascending phone numbers `87438807`, `91031282` followed by `92492021`<br> | ||
![result for 'sort p/'](images/sortByPhoneNumberResult.png) | ||
|
@@ -331,7 +335,7 @@ Action | Format, Examples | |
**Edit** | `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [m/MODULE] [f/FACULTY] [v/VENUE] [t/TAG]… [a/AVAILABILITY]…`<br> e.g.,`edit 2 n/James Lee e/[email protected]` | ||
**Filter** | `filter [m/MODULE] [f/FACULTY] [t/TAG]… [a/AVAILABILITY]…`<br> e.g., `filter m/CS2100 t/friends` | ||
**Find** | `find KEYWORD [MORE_KEYWORDS]`<br> e.g., `find James Jake` | ||
**Sort** | `sort [ATTRIBUTE]`<br> e.g., `sort p/` | ||
**Sort** | `sort [n/] [p/] [m/] [f/] [v/] [s/] [meet/]...`<br> e.g., `sort n/ p/ m/` | ||
**Add Meeting** | `meeting INDEX [d/DESCRIPTION] [s/DATETIME]`<br> e.g., `meeting 1 d/ Meet for finals preparation s/ 12/04/2024 18:00` | ||
**Set as Favourite** | `fav INDEX`<br> e.g., `fav 3` | ||
**Remove as Favourite** | `unfav INDEX`<br> e.g., `unfav 3` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...main/java/staffconnect/model/meeting/comparator/MeetingDateThenDescriptionComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/staffconnect/model/person/comparators/MeetingListComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package staffconnect.model.person.comparators; | ||
|
||
import static staffconnect.model.meeting.comparator.MeetingDateThenDescriptionComparator.MEETING_DATE_THEN_DESCRIPTION_COMPARATOR; | ||
|
||
import java.util.Comparator; | ||
|
||
import staffconnect.model.meeting.Meeting; | ||
import staffconnect.model.person.Person; | ||
|
||
|
||
/** | ||
* Represents a Comparator for a Person's Earliest Meeting followed by the ascending description in the staff book. | ||
*/ | ||
public class MeetingListComparator implements Comparator<Person> { | ||
|
||
public static final MeetingListComparator MEETING_LIST_COMPARATOR = new MeetingListComparator(); | ||
|
||
@Override | ||
public int compare(Person p1, Person p2) { | ||
Meeting earliestAlphanumericMeeting1 = p1.getMeetings().stream().min(MEETING_DATE_THEN_DESCRIPTION_COMPARATOR) | ||
.orElse(null); | ||
Meeting earliestAlphanumericMeeting2 = p2.getMeetings().stream().min(MEETING_DATE_THEN_DESCRIPTION_COMPARATOR) | ||
.orElse(null); | ||
|
||
if ((earliestAlphanumericMeeting1 == null) && (earliestAlphanumericMeeting2 == null)) { | ||
return 0; | ||
} else if (earliestAlphanumericMeeting1 == (null)) { | ||
return 1; | ||
} else if (earliestAlphanumericMeeting2 == (null)) { | ||
return -1; | ||
} | ||
|
||
return MEETING_DATE_THEN_DESCRIPTION_COMPARATOR.compare(earliestAlphanumericMeeting1, | ||
earliestAlphanumericMeeting2); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Earliest Meeting, Ascending alphanumeric Description"; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/staffconnect/model/person/comparators/MeetingListDateComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package staffconnect.model.person.comparators; | ||
|
||
import static staffconnect.model.meeting.comparator.MeetingDateTimeComparator.MEETING_DATE_COMPARATOR; | ||
|
||
import java.util.Comparator; | ||
|
||
import staffconnect.model.meeting.Meeting; | ||
import staffconnect.model.person.Person; | ||
|
||
|
||
|
||
/** | ||
* Represents a Comparator for a Person's Earliest Meeting in the staff book. | ||
*/ | ||
public class MeetingListDateComparator implements Comparator<Person> { | ||
|
||
public static final MeetingListDateComparator MEETING_LIST_DATE_COMPARATOR = new MeetingListDateComparator(); | ||
|
||
@Override | ||
public int compare(Person p1, Person p2) { | ||
Meeting earliestMeeting1 = p1.getMeetings().stream().min(MEETING_DATE_COMPARATOR).orElse(null); | ||
Meeting earliestMeeting2 = p2.getMeetings().stream().min(MEETING_DATE_COMPARATOR).orElse(null); | ||
|
||
if ((earliestMeeting1 == null) && (earliestMeeting2 == null)) { | ||
return 0; | ||
} else if (earliestMeeting1 == (null)) { | ||
return 1; | ||
} else if (earliestMeeting2 == (null)) { | ||
return -1; | ||
} | ||
|
||
return MEETING_DATE_COMPARATOR.compare(earliestMeeting1, earliestMeeting2); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Earliest Meeting"; | ||
} | ||
} |
Oops, something went wrong.