forked from nus-cs2103-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
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 nus-cs2103-AY2324S1#111 from jx124/add-sort-meetin…
…g-time-feature Add sort meeting time feature
- Loading branch information
Showing
18 changed files
with
222 additions
and
17 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/main/java/seedu/address/logic/commands/SortMeetingTimeCommand.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,26 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.function.Predicate; | ||
|
||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Person; | ||
|
||
/** | ||
* Lists persons in the address book sorted by their meeting times. | ||
*/ | ||
public class SortMeetingTimeCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "sortmeeting"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Sorted all meeting times chronologically"; | ||
|
||
public static final Predicate<Person> PREDICATE_HAS_MEETING_TIME = person -> person.getMeetingTime().isPresent(); | ||
@Override | ||
public CommandResult execute(Model model) { | ||
requireNonNull(model); | ||
model.sortFilteredPersonList(); | ||
return new CommandResult(MESSAGE_SUCCESS); | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
src/main/java/seedu/address/model/person/PersonMeetingTimeComparator.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,26 @@ | ||
package seedu.address.model.person; | ||
|
||
import java.util.Comparator; | ||
import java.util.NoSuchElementException; | ||
|
||
/** | ||
* Implements the comparator to sort Persons based on their meeting times. | ||
*/ | ||
public class PersonMeetingTimeComparator implements Comparator<Person> { | ||
|
||
/** | ||
* Compares the meeting times of two Person objects. | ||
* Both Person objects should have a valid meeting time that is not null. | ||
* | ||
* @param person1 the first Person object to be compared. | ||
* @param person2 the second Person object to be compared. | ||
* @return The relative order of the Person objects. | ||
*/ | ||
@Override | ||
public int compare(Person person1, Person person2) throws NoSuchElementException { | ||
MeetingTime meetingTime1 = person1.getMeetingTime().orElseThrow(); | ||
MeetingTime meetingTime2 = person2.getMeetingTime().orElseThrow(); | ||
|
||
return meetingTime1.value.compareTo(meetingTime2.value); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -25,28 +25,28 @@ public class SampleDataUtil { | |
public static Person[] getSamplePersons() { | ||
return new Person[] { | ||
new Client(new Name("Alex Yeoh"), new Phone("87438807"), new Email("[email protected]"), | ||
new Address("Blk 30 Geylang Street 29, #06-40"), Optional.of(new MeetingTime("10/10/2023 14:30")), | ||
new Address("Blk 30 Geylang Street 29, #06-40"), Optional.of(new MeetingTime("12/10/2023 14:30")), | ||
getTagSet("friends")), | ||
new Client(new Name("Bernice Yu"), new Phone("99272758"), new Email("[email protected]"), | ||
new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), | ||
Optional.of(new MeetingTime("10/10/2023 14:30")), | ||
Optional.empty(), | ||
getTagSet("colleagues", "friends")), | ||
new Client(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("[email protected]"), | ||
new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), | ||
Optional.of(new MeetingTime("10/10/2023 14:30")), | ||
Optional.of(new MeetingTime("11/10/2023 13:30")), | ||
getTagSet("neighbours")), | ||
new Lead(new Name("David Li"), new Phone("91031282"), new Email("[email protected]"), | ||
new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), | ||
new KeyMilestone("01/12/2023"), Optional.of(new MeetingTime("10/10/2023 14:30")), | ||
new KeyMilestone("01/12/2023"), Optional.of(new MeetingTime("11/10/2023 10:30")), | ||
getTagSet("family")), | ||
new Lead(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("[email protected]"), | ||
new Address("Blk 47 Tampines Street 20, #17-35"), | ||
new KeyMilestone("01/12/2023"), | ||
Optional.of(new MeetingTime("10/10/2023 14:30")), | ||
Optional.empty(), | ||
getTagSet("classmates")), | ||
new Lead(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("[email protected]"), | ||
new Address("Blk 45 Aljunied Street 85, #11-31"), | ||
new KeyMilestone("01/12/2023"), Optional.of(new MeetingTime("10/10/2023 14:30")), | ||
new KeyMilestone("01/12/2023"), Optional.of(new MeetingTime("12/10/2023 16:30")), | ||
getTagSet("colleagues")) | ||
}; | ||
} | ||
|
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
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
31 changes: 31 additions & 0 deletions
31
src/test/java/seedu/address/logic/commands/SortMeetingTimeCommandTest.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,31 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
import static seedu.address.logic.commands.SortMeetingTimeCommand.MESSAGE_SUCCESS; | ||
import static seedu.address.testutil.TypicalPersons.ALICE; | ||
import static seedu.address.testutil.TypicalPersons.BENSON; | ||
import static seedu.address.testutil.TypicalPersons.CARL; | ||
import static seedu.address.testutil.TypicalPersons.ELLE; | ||
import static seedu.address.testutil.TypicalPersons.GEORGE; | ||
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.UserPrefs; | ||
|
||
public class SortMeetingTimeCommandTest { | ||
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
|
||
@Test | ||
public void execute_sortPersonList_correctOrder() { | ||
expectedModel.sortFilteredPersonList(); | ||
assertCommandSuccess(new SortMeetingTimeCommand(), model, MESSAGE_SUCCESS, expectedModel); | ||
assertEquals(Arrays.asList(ALICE, ELLE, CARL, GEORGE, BENSON), model.getFilteredPersonList()); | ||
} | ||
} |
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
Oops, something went wrong.