From 9fdd34e200e0c106f4082dde81356d3509f4db89 Mon Sep 17 00:00:00 2001 From: solomonng2001 Date: Mon, 25 Mar 2024 15:49:50 +0800 Subject: [PATCH] Add sorting for person attributes Unable to sort clients by their attributes. Addition of sort will allow convenient access when looking up clients. Let's * make person attributes comparable, by implementing the interface. * Add sorting command and parser. * Add person comparator to abstract to logic for handling comparators. * Add tests in model, commands and parser. * Update ui to refresh client list after every command execute. --- .../address/logic/commands/SortCommand.java | 50 ++++++- .../seedu/address/model/ModelManager.java | 5 +- .../java/seedu/address/ui/MainWindow.java | 35 ++++- .../logic/commands/SortCommandTest.java | 102 +++++++++++++- .../logic/parser/SortCommandParserTest.java | 130 +++++++++++++++++- .../model/person/PersonComparatorTest.java | 28 ---- 6 files changed, 313 insertions(+), 37 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/SortCommand.java b/src/main/java/seedu/address/logic/commands/SortCommand.java index 63d48794734..2b8fb0b0aac 100644 --- a/src/main/java/seedu/address/logic/commands/SortCommand.java +++ b/src/main/java/seedu/address/logic/commands/SortCommand.java @@ -3,6 +3,8 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_SORT_ORDER; +import seedu.address.commons.util.ToStringBuilder; +import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.person.PersonComparator; import seedu.address.model.person.SortCriteria; @@ -24,7 +26,7 @@ public class SortCommand extends Command { + "priority " + PREFIX_SORT_ORDER + "desc"; - public static final String MESSAGE_SUCCESS = "Client list sorted."; + private static final String MESSAGE_SUCCESS = "Client list sorted by %s in %s order."; private final SortCriteria sortCriteria; private final SortOrder sortOrder; @@ -40,9 +42,51 @@ public SortCommand(SortCriteria sortCriteria, SortOrder sortOrder) { } @Override - public CommandResult execute(Model model) { + public CommandResult execute(Model model) throws CommandException { requireNonNull(model); model.sortFilteredPersonList(PersonComparator.getComparator(sortCriteria, sortOrder)); - return new CommandResult(MESSAGE_SUCCESS); + return new CommandResult(getMessageSuccess(sortCriteria, sortOrder)); + } + + /** + * Returns a success message based on the sort criteria and sort order. + * + * @param sortCriteria the sort criteria + * @param sortOrder the sort order + * @return the success message + */ + public static String getMessageSuccess(SortCriteria sortCriteria, SortOrder sortOrder) + throws IllegalArgumentException { + if (sortCriteria == null || sortOrder == null) { + throw new IllegalArgumentException("SortCriteria and SortOrder cannot be null."); + } + if (sortCriteria == SortCriteria.INVALID || sortOrder == SortOrder.INVALID) { + return String.format(MESSAGE_SUCCESS, SortCriteria.NAME, SortOrder.ASC); + } + return String.format(MESSAGE_SUCCESS, sortCriteria, sortOrder); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof SortCommand)) { + return false; + } + + SortCommand otherSortCommand = (SortCommand) other; + return sortCriteria.equals(otherSortCommand.sortCriteria) + && sortOrder.equals(otherSortCommand.sortOrder); + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .add("sortCriteria", sortCriteria) + .add("sortOrder", sortOrder) + .toString(); } } diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 58492bf76ec..20e760959e6 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -25,7 +25,7 @@ public class ModelManager implements Model { private final AddressBook addressBook; private final UserPrefs userPrefs; - private final FilteredList filteredPersons; + private FilteredList filteredPersons; private final DisplayClient displayClient; /** @@ -167,7 +167,8 @@ public void updateFilteredPersonList(Predicate predicate) { @Override public void sortFilteredPersonList(Comparator comparator) { requireNonNull(comparator); - filteredPersons.sort(comparator); + ObservableList sortedList = this.addressBook.getPersonList().sorted(comparator); + filteredPersons = new FilteredList<>(sortedList); } @Override diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 498630ce565..df8e020f385 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -148,6 +148,29 @@ void fillInnerParts() { commandBoxPlaceholder.getChildren().add(commandBox.getRoot()); } + /** + * Clears the placeholders of client list panel. + */ + private void clearClientListPanel() { + clientListPanelPlaceholder.getChildren().clear(); + } + + /** + * Fills up the placeholders of client list panel. + */ + private void addClientListPanel() { + clientListPanel = new ClientListPanel(logic.getFilteredPersonList()); + clientListPanelPlaceholder.getChildren().add(clientListPanel.getRoot()); + } + + /** + * Refreshes the client list panel. + */ + private void refreshClientListPanel() { + clearClientListPanel(); + addClientListPanel(); + } + /** * Fills up placeholders of client view panel. */ @@ -178,6 +201,15 @@ private void refreshClientViewPanel() { } } + /** + * Refreshes the client view panel, client list panel and reminders panel. + */ + private void refreshAllPanels() { + refreshClientViewPanel(); + refreshClientListPanel(); + // refreshRemindersPanel(); + } + // /** // * Fills up placeholders of reminders panel. // */ @@ -257,8 +289,7 @@ private CommandResult executeCommand(String commandText) throws CommandException logger.info("Result: " + commandResult.getFeedbackToUser()); resultDisplay.setFeedbackToUser(commandResult.getFeedbackToUser()); - refreshClientViewPanel(); - // refreshRemindersPanel(); + refreshAllPanels(); if (commandResult.isShowHelp()) { handleHelp(); diff --git a/src/test/java/seedu/address/logic/commands/SortCommandTest.java b/src/test/java/seedu/address/logic/commands/SortCommandTest.java index 3c0d373cd6a..ea208b42a9a 100644 --- a/src/test/java/seedu/address/logic/commands/SortCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/SortCommandTest.java @@ -1,2 +1,102 @@ -package seedu.address.logic.commands;public class SortCommandTest { +package seedu.address.logic.commands; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.testutil.Assert.assertThrows; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; + +import org.junit.jupiter.api.Test; + +import seedu.address.model.AddressBook; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; +import seedu.address.model.person.PersonComparator; +import seedu.address.model.person.SortCriteria; +import seedu.address.model.person.SortOrder; + +public class SortCommandTest { + + private final ModelManager model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + private final String invalidSortPriorityAsc = SortCommand.getMessageSuccess(SortCriteria.PRIORITY, SortOrder.ASC); + + @Test + public void constructor_nullArguments_throwsNullPointerException() { + // null sort criteria + assertThrows(NullPointerException.class, () -> new SortCommand(null, SortOrder.ASC)); + // null sort order + assertThrows(NullPointerException.class, () -> new SortCommand(SortCriteria.PRIORITY, null)); + // both null + assertThrows(NullPointerException.class, () -> new SortCommand(null, null)); + } + + @Test + public void execute_sortNoPersonsModel_sortSuccesstul() { + ModelManager expectedEmptyModel = new ModelManager(new AddressBook(new AddressBook()), new UserPrefs()); + expectedEmptyModel.sortFilteredPersonList(PersonComparator.getComparator(SortCriteria.PRIORITY, SortOrder.ASC)); + CommandTestUtil.assertCommandSuccess(new SortCommand(SortCriteria.PRIORITY, SortOrder.ASC), + new ModelManager(new AddressBook(new AddressBook()), new UserPrefs()), + invalidSortPriorityAsc, expectedEmptyModel); + } + + @Test + public void execute_sortPersonsModel_sortSuccessful() { + ModelManager expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); + expectedModel.sortFilteredPersonList(PersonComparator.getComparator(SortCriteria.PRIORITY, SortOrder.ASC)); + CommandTestUtil.assertCommandSuccess(new SortCommand(SortCriteria.PRIORITY, SortOrder.ASC), model, + invalidSortPriorityAsc, expectedModel); + } + + @Test + public void execute_invalidSortCriteria_sortSuccessful() { + ModelManager expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); + SortCommand sortCommand = new SortCommand(SortCriteria.INVALID, SortOrder.ASC); + expectedModel.sortFilteredPersonList(PersonComparator.getComparator(SortCriteria.INVALID, SortOrder.ASC)); + String expectedMessage = SortCommand.getMessageSuccess(SortCriteria.INVALID, SortOrder.ASC); + CommandTestUtil.assertCommandSuccess(sortCommand, model, expectedMessage, expectedModel); + } + + @Test + public void execute_invalidSortOrder_sortSuccessful() { + ModelManager expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); + SortCommand sortCommand = new SortCommand(SortCriteria.PRIORITY, SortOrder.INVALID); + expectedModel.sortFilteredPersonList(PersonComparator.getComparator(SortCriteria.PRIORITY, SortOrder.INVALID)); + String expectedMessage = SortCommand.getMessageSuccess(SortCriteria.PRIORITY, SortOrder.INVALID); + CommandTestUtil.assertCommandSuccess(sortCommand, model, expectedMessage, expectedModel); + } + + @Test + public void equals() { + SortCommand sortPriorityAscCommand = new SortCommand(SortCriteria.PRIORITY, SortOrder.ASC); + SortCommand sortPriorityDescCommand = new SortCommand(SortCriteria.PRIORITY, SortOrder.DESC); + SortCommand sortNameAscCommand = new SortCommand(SortCriteria.NAME, SortOrder.ASC); + + // same object -> returns true + assertTrue(sortPriorityAscCommand.equals(sortPriorityAscCommand)); + + // same values -> returns true + SortCommand sortPriorityAscCommandCopy = new SortCommand(SortCriteria.PRIORITY, SortOrder.ASC); + assertTrue(sortPriorityAscCommand.equals(sortPriorityAscCommandCopy)); + + // different types -> returns false + assertFalse(sortPriorityAscCommand.equals(1)); + + // null -> returns false + assertFalse(sortPriorityAscCommand.equals(null)); + + // different sort criteria -> returns false + assertFalse(sortPriorityAscCommand.equals(sortNameAscCommand)); + + // different sort order -> returns false + assertFalse(sortPriorityAscCommand.equals(sortPriorityDescCommand)); + } + + @Test + public void toStringMethod() { + SortCommand sortPriorityAscCommand = new SortCommand(SortCriteria.PRIORITY, SortOrder.ASC); + String expected = SortCommand.class.getCanonicalName() + + "{sortCriteria=" + SortCriteria.PRIORITY + + ", sortOrder=" + SortOrder.ASC + "}"; + assertEquals(expected, sortPriorityAscCommand.toString()); + } } diff --git a/src/test/java/seedu/address/logic/parser/SortCommandParserTest.java b/src/test/java/seedu/address/logic/parser/SortCommandParserTest.java index 77441435961..fec70de75ad 100644 --- a/src/test/java/seedu/address/logic/parser/SortCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/SortCommandParserTest.java @@ -1,10 +1,138 @@ package seedu.address.logic.parser; +import static seedu.address.logic.commands.CommandTestUtil.PREAMBLE_WHITESPACE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_SORT_ORDER; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; + import org.junit.jupiter.api.Test; +import seedu.address.logic.Messages; +import seedu.address.logic.commands.SortCommand; +import seedu.address.model.person.SortCriteria; +import seedu.address.model.person.SortOrder; + public class SortCommandParserTest { + public static final String VALID_SORT_NAME_ASC = SortCriteria.NAME + " " + PREFIX_SORT_ORDER + SortOrder.ASC; + public static final String VALID_SORT_NAME_DESC = SortCriteria.NAME + " " + PREFIX_SORT_ORDER + SortOrder.DESC; + public static final String VALID_SORT_PHONE_ASC = SortCriteria.PHONE + " " + PREFIX_SORT_ORDER + SortOrder.ASC; + public static final String VALID_SORT_PHONE_DESC = SortCriteria.PHONE + " " + PREFIX_SORT_ORDER + SortOrder.DESC; + public static final String VALID_SORT_EMAIL_ASC = SortCriteria.EMAIL + " " + PREFIX_SORT_ORDER + SortOrder.ASC; + public static final String VALID_SORT_EMAIL_DESC = SortCriteria.EMAIL + " " + PREFIX_SORT_ORDER + SortOrder.DESC; + public static final String VALID_SORT_ADDRESS_ASC = SortCriteria.ADDRESS + " " + PREFIX_SORT_ORDER + SortOrder.ASC; + public static final String VALID_SORT_ADDRESS_DESC = SortCriteria.ADDRESS + " " + PREFIX_SORT_ORDER + + SortOrder.DESC; + public static final String VALID_SORT_PRIORITY_ASC = SortCriteria.PRIORITY + " " + PREFIX_SORT_ORDER + + SortOrder.ASC; + public static final String VALID_SORT_PRIORITY_DESC = SortCriteria.PRIORITY + " " + PREFIX_SORT_ORDER + + SortOrder.DESC; + public static final String VALID_SORT_BIRTHDAY_ASC = SortCriteria.BIRTHDAY + " " + PREFIX_SORT_ORDER + + SortOrder.ASC; + public static final String VALID_SORT_BIRTHDAY_DESC = SortCriteria.BIRTHDAY + " " + PREFIX_SORT_ORDER + + SortOrder.DESC; + public static final String VALID_SORT_LASTMET_ASC = SortCriteria.LASTMET + " " + PREFIX_SORT_ORDER + SortOrder.ASC; + public static final String VALID_SORT_LASTMET_DESC = SortCriteria.LASTMET + " " + PREFIX_SORT_ORDER + + SortOrder.DESC; + public static final String VALID_SORT_SCHEDULE_ASC = SortCriteria.SCHEDULE + " " + PREFIX_SORT_ORDER + + SortOrder.ASC; + public static final String VALID_SORT_SCHEDULE_DESC = SortCriteria.SCHEDULE + " " + PREFIX_SORT_ORDER + + SortOrder.DESC; + + private final SortCommandParser parser = new SortCommandParser(); + @Test public void parse_allFieldsPresent_success() { - + // whitespace only preamble + assertParseSuccess(parser, PREAMBLE_WHITESPACE + VALID_SORT_NAME_ASC, + new SortCommand(SortCriteria.NAME, SortOrder.ASC)); + assertParseSuccess(parser, PREAMBLE_WHITESPACE + VALID_SORT_NAME_DESC, + new SortCommand(SortCriteria.NAME, SortOrder.DESC)); + assertParseSuccess(parser, PREAMBLE_WHITESPACE + VALID_SORT_PHONE_ASC, + new SortCommand(SortCriteria.PHONE, SortOrder.ASC)); + assertParseSuccess(parser, PREAMBLE_WHITESPACE + VALID_SORT_PHONE_DESC, + new SortCommand(SortCriteria.PHONE, SortOrder.DESC)); + assertParseSuccess(parser, PREAMBLE_WHITESPACE + VALID_SORT_EMAIL_ASC, + new SortCommand(SortCriteria.EMAIL, SortOrder.ASC)); + assertParseSuccess(parser, PREAMBLE_WHITESPACE + VALID_SORT_EMAIL_DESC, + new SortCommand(SortCriteria.EMAIL, SortOrder.DESC)); + assertParseSuccess(parser, PREAMBLE_WHITESPACE + VALID_SORT_ADDRESS_ASC, + new SortCommand(SortCriteria.ADDRESS, SortOrder.ASC)); + assertParseSuccess(parser, PREAMBLE_WHITESPACE + VALID_SORT_ADDRESS_DESC, + new SortCommand(SortCriteria.ADDRESS, SortOrder.DESC)); + assertParseSuccess(parser, PREAMBLE_WHITESPACE + VALID_SORT_PRIORITY_ASC, + new SortCommand(SortCriteria.PRIORITY, SortOrder.ASC)); + assertParseSuccess(parser, PREAMBLE_WHITESPACE + VALID_SORT_PRIORITY_DESC, + new SortCommand(SortCriteria.PRIORITY, SortOrder.DESC)); + assertParseSuccess(parser, PREAMBLE_WHITESPACE + VALID_SORT_BIRTHDAY_ASC, + new SortCommand(SortCriteria.BIRTHDAY, SortOrder.ASC)); + assertParseSuccess(parser, PREAMBLE_WHITESPACE + VALID_SORT_BIRTHDAY_DESC, + new SortCommand(SortCriteria.BIRTHDAY, SortOrder.DESC)); + assertParseSuccess(parser, PREAMBLE_WHITESPACE + VALID_SORT_LASTMET_ASC, + new SortCommand(SortCriteria.LASTMET, SortOrder.ASC)); + assertParseSuccess(parser, PREAMBLE_WHITESPACE + VALID_SORT_LASTMET_DESC, + new SortCommand(SortCriteria.LASTMET, SortOrder.DESC)); + assertParseSuccess(parser, PREAMBLE_WHITESPACE + VALID_SORT_SCHEDULE_ASC, + new SortCommand(SortCriteria.SCHEDULE, SortOrder.ASC)); + assertParseSuccess(parser, PREAMBLE_WHITESPACE + VALID_SORT_SCHEDULE_DESC, + new SortCommand(SortCriteria.SCHEDULE, SortOrder.DESC)); + + // without whitespace preamble + assertParseSuccess(parser, VALID_SORT_NAME_ASC, new SortCommand(SortCriteria.NAME, SortOrder.ASC)); + assertParseSuccess(parser, VALID_SORT_NAME_DESC, new SortCommand(SortCriteria.NAME, SortOrder.DESC)); + assertParseSuccess(parser, VALID_SORT_PHONE_ASC, new SortCommand(SortCriteria.PHONE, SortOrder.ASC)); + assertParseSuccess(parser, VALID_SORT_PHONE_DESC, new SortCommand(SortCriteria.PHONE, SortOrder.DESC)); + assertParseSuccess(parser, VALID_SORT_EMAIL_ASC, new SortCommand(SortCriteria.EMAIL, SortOrder.ASC)); + assertParseSuccess(parser, VALID_SORT_EMAIL_DESC, new SortCommand(SortCriteria.EMAIL, SortOrder.DESC)); + assertParseSuccess(parser, VALID_SORT_ADDRESS_ASC, new SortCommand(SortCriteria.ADDRESS, SortOrder.ASC)); + assertParseSuccess(parser, VALID_SORT_ADDRESS_DESC, new SortCommand(SortCriteria.ADDRESS, SortOrder.DESC)); + assertParseSuccess(parser, VALID_SORT_PRIORITY_ASC, new SortCommand(SortCriteria.PRIORITY, SortOrder.ASC)); + assertParseSuccess(parser, VALID_SORT_PRIORITY_DESC, new SortCommand(SortCriteria.PRIORITY, SortOrder.DESC)); + assertParseSuccess(parser, VALID_SORT_BIRTHDAY_ASC, new SortCommand(SortCriteria.BIRTHDAY, SortOrder.ASC)); + assertParseSuccess(parser, VALID_SORT_BIRTHDAY_DESC, new SortCommand(SortCriteria.BIRTHDAY, SortOrder.DESC)); + assertParseSuccess(parser, VALID_SORT_LASTMET_ASC, new SortCommand(SortCriteria.LASTMET, SortOrder.ASC)); + assertParseSuccess(parser, VALID_SORT_LASTMET_DESC, new SortCommand(SortCriteria.LASTMET, SortOrder.DESC)); + assertParseSuccess(parser, VALID_SORT_SCHEDULE_ASC, new SortCommand(SortCriteria.SCHEDULE, SortOrder.ASC)); + assertParseSuccess(parser, VALID_SORT_SCHEDULE_DESC, new SortCommand(SortCriteria.SCHEDULE, SortOrder.DESC)); + } + + @Test + public void parse_repeatedParameter_failure() { + // multiple sort orders + assertParseFailure(parser, VALID_SORT_NAME_ASC + " " + PREFIX_SORT_ORDER + SortOrder.DESC, + Messages.getErrorMessageForDuplicatePrefixes(PREFIX_SORT_ORDER)); + } + + @Test + public void parse_compulsoryFieldMissing_failure() { + String expectedMessage = String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, SortCommand.MESSAGE_USAGE); + + // missing sort criteria + assertParseFailure(parser, " " + PREFIX_SORT_ORDER + SortOrder.ASC, expectedMessage); + + // missing sort order + assertParseFailure(parser, SortCriteria.NAME.toString(), expectedMessage); + assertParseFailure(parser, SortCriteria.NAME.toString() + " " + SortOrder.DESC, expectedMessage); + + // missing both sort criteria and sort order + assertParseFailure(parser, "", expectedMessage); + } + + @Test +public void parse_invalidValue_failure() { + // invalid sort criteria + assertParseFailure(parser, "invalid" + " " + PREFIX_SORT_ORDER + SortOrder.ASC, + SortCriteria.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, "x" + " " + PREFIX_SORT_ORDER + SortOrder.DESC, + SortCriteria.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, " name " + VALID_SORT_NAME_ASC, + SortCriteria.MESSAGE_CONSTRAINTS); + + // invalid sort order + assertParseFailure(parser, SortCriteria.NAME + " " + PREFIX_SORT_ORDER + "invalid", + SortOrder.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, SortCriteria.NAME + " " + PREFIX_SORT_ORDER + "x", + SortOrder.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, SortCriteria.NAME + " " + PREFIX_SORT_ORDER, + SortOrder.MESSAGE_CONSTRAINTS); } } diff --git a/src/test/java/seedu/address/model/person/PersonComparatorTest.java b/src/test/java/seedu/address/model/person/PersonComparatorTest.java index 46d61a93fd0..8a5cdd54cac 100644 --- a/src/test/java/seedu/address/model/person/PersonComparatorTest.java +++ b/src/test/java/seedu/address/model/person/PersonComparatorTest.java @@ -92,34 +92,6 @@ public void getComparator() { assertTrue(birthdayDescComparator.compare(birthday1, birthday2) > 0); assertEquals(0, birthdayDescComparator.compare(birthday1, birthday1Copy)); -// // sort by last met -// Person lastMet1 = new PersonBuilder().withLastMet("2021-01-01").build(); -// Person lastMet1Copy = new PersonBuilder().withLastMet("2021-01-01").build(); -// Person lastMet2 = new PersonBuilder().withLastMet("2021-01-02").build(); -// // ascending -// Comparator lastMetAscComparator = PersonComparator.getComparator(SortCriteria.LASTMET, SortOrder.ASC); -// assertTrue(lastMetAscComparator.compare(lastMet1, lastMet2) < 0); -// assertEquals(0, lastMetAscComparator.compare(lastMet1, lastMet1Copy)); -// // descending -// Comparator lastMetDescComparator = PersonComparator.getComparator(SortCriteria.LASTMET, -// SortOrder.DESC); -// assertTrue(lastMetDescComparator.compare(lastMet1, lastMet2) > 0); -// assertEquals(0, lastMetDescComparator.compare(lastMet1, lastMet1Copy)); -// -// // sort by schedule -// Person schedule1 = new PersonBuilder().withSchedule("2021-01-01").build(); -// Person schedule1Copy = new PersonBuilder().withSchedule("2021-01-01").build(); -// Person schedule2 = new PersonBuilder().withSchedule("2021-01-02").build(); -// // ascending -// Comparator scheduleAscComparator = PersonComparator.getComparator(SortCriteria.SCHEDULE, SortOrder.ASC); -// assertTrue(scheduleAscComparator.compare(schedule1, schedule2) < 0); -// assertEquals(0, scheduleAscComparator.compare(schedule1, schedule1Copy)); -// // descending -// Comparator scheduleDescComparator = PersonComparator.getComparator(SortCriteria.SCHEDULE, -// SortOrder.DESC); -// assertTrue(scheduleDescComparator.compare(schedule1, schedule2) > 0); -// assertEquals(0, scheduleDescComparator.compare(schedule1, schedule1Copy)); - // sort by invalid or default criteria Comparator invalidAscComparator = PersonComparator.getComparator(SortCriteria.INVALID, SortOrder.ASC); // ascending