From 4d05805ecb2ce8d9d8de655ba14b84738cb90ba8 Mon Sep 17 00:00:00 2001 From: lamchenghou Date: Thu, 2 Nov 2023 21:47:23 +0800 Subject: [PATCH 1/6] Update model and logic for mapping sort --- .../seedu/address/logic/SeplendidLogic.java | 7 +++ .../address/logic/SeplendidLogicManager.java | 4 ++ .../seedu/address/model/SeplendidModel.java | 17 ++++++ .../address/model/SeplendidModelManager.java | 54 ++++++++++++------- 4 files changed, 63 insertions(+), 19 deletions(-) diff --git a/src/main/java/seedu/address/logic/SeplendidLogic.java b/src/main/java/seedu/address/logic/SeplendidLogic.java index b6afbe55805..0bad84e4e87 100644 --- a/src/main/java/seedu/address/logic/SeplendidLogic.java +++ b/src/main/java/seedu/address/logic/SeplendidLogic.java @@ -72,14 +72,19 @@ public interface SeplendidLogic { ObservableList getFilteredPartnerCourseCatalogue(); Path getPartnerCourseCatalogueFilePath(); + ObservableList getSortedPartnerCourseCatalogue(); //=========== UniversityCatalogue ============================================================================ ReadOnlyUniversityCatalogue getUniversityCatalogue(); + ObservableList getFilteredUniversityCatalogue(); + Path getUniversityeCatalogueFilePath(); + ObservableList getSortedUniversityCatalogue(); + //=========== NoteCatalogue ============================================================================ ObservableList getFilteredNoteCatalogue(); @@ -89,5 +94,7 @@ public interface SeplendidLogic { ObservableList getFilteredMappingCatalogue(); Path getMappingCatalogueFilePath(); + + ObservableList getSortedMappingCatalogue(); } diff --git a/src/main/java/seedu/address/logic/SeplendidLogicManager.java b/src/main/java/seedu/address/logic/SeplendidLogicManager.java index 9e35f3d812c..3d5cb1f6d90 100644 --- a/src/main/java/seedu/address/logic/SeplendidLogicManager.java +++ b/src/main/java/seedu/address/logic/SeplendidLogicManager.java @@ -175,4 +175,8 @@ public ObservableList getFilteredMappingCatalogue() { public Path getMappingCatalogueFilePath() { return model.getMappingCatalogueFilePath(); } + + public ObservableList getSortedMappingCatalogue() { + return model.getSortedMappingList(); + } } diff --git a/src/main/java/seedu/address/model/SeplendidModel.java b/src/main/java/seedu/address/model/SeplendidModel.java index c23226ce547..a0c99abf8b7 100644 --- a/src/main/java/seedu/address/model/SeplendidModel.java +++ b/src/main/java/seedu/address/model/SeplendidModel.java @@ -143,6 +143,7 @@ void searchLocalCourses(LocalCourseAttribute attribute, void searchPartnerCourses(PartnerCourseAttribute attribute, PartnerCourseContainsKeywordsPredicate predicate); + ReadOnlyPartnerCourseCatalogue getPartnerCourseCatalogue(); /** @@ -175,6 +176,7 @@ void searchPartnerCourses(PartnerCourseAttribute attribute, void deletePartnerCourse(PartnerCourse partnerCourse) throws CommandException; public ObservableList getSortedPartnerCourseList(); + public void updateSortedPartnerList(Comparator partnerCourseComparator); /** @@ -195,6 +197,7 @@ void searchPartnerCourses(PartnerCourseAttribute attribute, ObservableList getFilteredUniversityList(); boolean hasUniversity(University university); + boolean hasUniversity(UniversityName universityName); void getSearchUniversityIfExists(UniversityNameContainsKeywordsPredicate universityPredicate); @@ -203,6 +206,7 @@ void searchPartnerCourses(PartnerCourseAttribute attribute, void addUniversity(University university); void setUniversity(University target, University editedUniversity); + ObservableList getSortedUniversityList(); void updateSortedUniversityList(Comparator universityComparator); @@ -257,6 +261,7 @@ void searchPartnerCourses(PartnerCourseAttribute attribute, /** * Gets the notes with the specific tags + * * @param notePredicate */ void getSearchNoteIfExists(NoteTagContainsKeywordsPredicate notePredicate); @@ -339,6 +344,18 @@ void searchPartnerCourses(PartnerCourseAttribute attribute, */ void setMapping(Mapping mapping, Mapping editedMapping); + /** + * Returns the sorted mapping list. + */ + ObservableList getSortedMappingList(); + + /** + * Sorts the mapping list according to the given comparator. + * + * @param mappingComparator This is the given comparator. + */ + void updateSortedMappingList(Comparator mappingComparator); + //=========== FilteredMappingList Accessors ============================================================= /** diff --git a/src/main/java/seedu/address/model/SeplendidModelManager.java b/src/main/java/seedu/address/model/SeplendidModelManager.java index d1c998ef666..85e225452aa 100644 --- a/src/main/java/seedu/address/model/SeplendidModelManager.java +++ b/src/main/java/seedu/address/model/SeplendidModelManager.java @@ -57,6 +57,7 @@ public class SeplendidModelManager implements SeplendidModel { private final MappingCatalogue mappingCatalogue; private final FilteredList filteredMappingCatalogue; + private final SortedList sortedMappingCatalogue; /** @@ -73,17 +74,17 @@ public SeplendidModelManager(ReadOnlyUserPrefs userPrefs, noteCatalogue, mappingCatalogue); logger.fine(String.format("Initializing with user prefs: %s,\n" - + "local course catalogue: %s, \n" - + "partner course catalogue: %s,\n" - + "university catalogue: %s,\n" - + "mapping catalogue: %s,\n" - + "and note catalogue: %s", - userPrefs, - localCourseCatalogue, - partnerCourseCatalogue, - universityCatalogue, - mappingCatalogue, - noteCatalogue)); + + "local course catalogue: %s, \n" + + "partner course catalogue: %s,\n" + + "university catalogue: %s,\n" + + "mapping catalogue: %s,\n" + + "and note catalogue: %s", + userPrefs, + localCourseCatalogue, + partnerCourseCatalogue, + universityCatalogue, + mappingCatalogue, + noteCatalogue)); this.localCourseCatalogue = new LocalCourseCatalogue(localCourseCatalogue); this.userPrefs = new UserPrefs(userPrefs); @@ -99,6 +100,7 @@ public SeplendidModelManager(ReadOnlyUserPrefs userPrefs, filteredNoteCatalogue = new FilteredList<>(this.noteCatalogue.getNoteList()); this.mappingCatalogue = new MappingCatalogue(mappingCatalogue); filteredMappingCatalogue = new FilteredList<>(this.mappingCatalogue.getMappingList()); + sortedMappingCatalogue = new SortedList<>(this.mappingCatalogue.getMappingList()); } /** @@ -106,12 +108,12 @@ public SeplendidModelManager(ReadOnlyUserPrefs userPrefs, */ public SeplendidModelManager() { this( - new UserPrefs(), - new LocalCourseCatalogue(), - new PartnerCourseCatalogue(), - new UniversityCatalogue(), - new MappingCatalogue(), - new NoteCatalogue()); + new UserPrefs(), + new LocalCourseCatalogue(), + new PartnerCourseCatalogue(), + new UniversityCatalogue(), + new MappingCatalogue(), + new NoteCatalogue()); } //=========== UserPrefs ================================================================================== @@ -235,6 +237,7 @@ public void updateSortedLocalList(Comparator localCourseComparator) /** * Checks if the local course exists. + * * @param attribute * @param predicate */ @@ -262,8 +265,10 @@ public void updateFilteredLocalCourseList(Predicate predicate) { } //=========== PartnerCourseCatalogue ============================================================================ + /** * Checks if the local course exists. + * * @param attribute * @param predicate */ @@ -380,6 +385,7 @@ public boolean hasUniversity(University university) { /** * Check if there exist the same university in the catalogue. + * * @param universityName * @return */ @@ -388,12 +394,14 @@ public boolean hasUniversity(UniversityName universityName) { Optional maybeUniversity = getUniversityIfExists(universityName); return maybeUniversity.isPresent(); } + @Override public void getSearchUniversityIfExists(UniversityNameContainsKeywordsPredicate universityPredicate) { requireNonNull(universityPredicate); filteredUniversityCatalogue.setPredicate(universityPredicate); } + @Override public void addUniversity(University university) { universityCatalogue.addUniversity(university); @@ -419,8 +427,6 @@ public void updateSortedUniversityList(Comparator universityComparat } - - //=========== FilteredUniversityList Accessors ============================================================= @Override @@ -620,6 +626,16 @@ public void setMapping(Mapping mapping, Mapping editedMapping) { mappingCatalogue.setMapping(mapping, editedMapping); } + @Override + public ObservableList getSortedMappingList() { + return sortedMappingCatalogue; + } + + @Override + public void updateSortedMappingList(Comparator mappingComparator) { + sortedMappingCatalogue.setComparator(mappingComparator); + } + //=========== FilteredNMappingList Accessors ============================================================= From fecfafd504d8369650556df124d6bbbf02bffb81 Mon Sep 17 00:00:00 2001 From: lamchenghou Date: Thu, 2 Nov 2023 21:47:37 +0800 Subject: [PATCH 2/6] Fix typo --- .../MappingAttributeContainsKeywordPredicate.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/seedu/address/model/mapping/MappingAttributeContainsKeywordPredicate.java b/src/main/java/seedu/address/model/mapping/MappingAttributeContainsKeywordPredicate.java index 3ee98f669b4..4e19601da4a 100644 --- a/src/main/java/seedu/address/model/mapping/MappingAttributeContainsKeywordPredicate.java +++ b/src/main/java/seedu/address/model/mapping/MappingAttributeContainsKeywordPredicate.java @@ -25,7 +25,7 @@ public class MappingAttributeContainsKeywordPredicate implements Predicate> getPartnerCourseIfExists; - private boolean isgetLocalPartnerCourseInitialised = false; + private boolean isGetLocalPartnerCourseInitialised = false; /** * Constructor for MappingAttributeContainsKeywordPredicate. @@ -47,7 +47,7 @@ public void initialiseGetLocalPartnercourse(Function> getPartnerCourseIfExists) { this.getLocalCourseIfExists = getLocalCourseIfExists; this.getPartnerCourseIfExists = getPartnerCourseIfExists; - isgetLocalPartnerCourseInitialised = true; + isGetLocalPartnerCourseInitialised = true; } /** @@ -70,14 +70,14 @@ public boolean test(Mapping mapping) { case LOCALCODE: return isQueryContainedInLocalCode(keyword, mapping); case LOCALNAME: - if (!isgetLocalPartnerCourseInitialised) { + if (!isGetLocalPartnerCourseInitialised) { break; } return isQueryContainedInLocalName(keyword, mapping, getLocalCourseIfExists); case PARTNERCODE: return isQueryContainedInPartnerCode(keyword, mapping); case PARTNERNAME: - if (!isgetLocalPartnerCourseInitialised) { + if (!isGetLocalPartnerCourseInitialised) { break; } return isQueryContainedInPartnerName(keyword, mapping, getPartnerCourseIfExists); @@ -120,7 +120,7 @@ private boolean isQueryContainedInLocalName(String query, Function> getLocalCourseIfExists) { String localName = getLocalCourseIfExists.apply(mapping.getLocalCode()) - .map(pc -> pc.getLocalName().getValue()).orElse(""); + .map(lc -> lc.getLocalName().getValue()).orElse(""); return localName.toLowerCase().contains(query.toLowerCase()); } @@ -155,7 +155,9 @@ public boolean equals(Object other) { @Override public String toString() { - return new ToStringBuilder(this).add("keyword", keyword).toString(); + return new ToStringBuilder(this) + .add("attribute", attribute) + .add("keyword", keyword).toString(); } } From 4962c6ce2625df49b07c2cf78ac9e7fa88861eea Mon Sep 17 00:00:00 2001 From: lamchenghou Date: Thu, 2 Nov 2023 21:47:55 +0800 Subject: [PATCH 3/6] Add MappingComparatorByAttribute --- .../mapping/MappingComparatorByAttribute.java | 147 ++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 src/main/java/seedu/address/model/mapping/MappingComparatorByAttribute.java diff --git a/src/main/java/seedu/address/model/mapping/MappingComparatorByAttribute.java b/src/main/java/seedu/address/model/mapping/MappingComparatorByAttribute.java new file mode 100644 index 00000000000..f1f00b7822e --- /dev/null +++ b/src/main/java/seedu/address/model/mapping/MappingComparatorByAttribute.java @@ -0,0 +1,147 @@ +package seedu.address.model.mapping; + +import java.util.Comparator; +import java.util.Optional; +import java.util.function.BiFunction; +import java.util.function.Function; + +import seedu.address.commons.util.ToStringBuilder; +import seedu.address.model.localcourse.LocalCode; +import seedu.address.model.localcourse.LocalCourse; +import seedu.address.model.partnercourse.PartnerCode; +import seedu.address.model.partnercourse.PartnerCourse; +import seedu.address.model.university.UniversityName; + +/** + * Compares two instances of Mapping based on given attribute. + */ +public class MappingComparatorByAttribute implements Comparator { + + /* Crucial that this is initialised with a correct attribute */ + private final MappingAttributeEnum attribute; + + private Function> getLocalCourseIfExists; + private BiFunction> getPartnerCourseIfExists; + + private boolean isGetLocalPartnerCourseInitialised = false; + + public MappingComparatorByAttribute(MappingAttributeEnum attribute) { + this.attribute = attribute; + } + + /** + * Initialises the getLocalCourseIfExists and getPartnerCourseIfExists functions. + */ + public void initialiseGetLocalPartnercourse(Function> + getLocalCourseIfExists, + BiFunction> getPartnerCourseIfExists) { + this.getLocalCourseIfExists = getLocalCourseIfExists; + this.getPartnerCourseIfExists = getPartnerCourseIfExists; + isGetLocalPartnerCourseInitialised = true; + } + + /** + * Returns the mapping attribute. + */ + public MappingAttributeEnum getAttribute() { + return attribute; + } + + @Override + public int compare(Mapping m1, Mapping m2) { + switch (attribute) { + case LOCALCODE: + return compareBasedOnLocalCode(m1, m2); + case LOCALNAME: + if (!isGetLocalPartnerCourseInitialised) { + break; + } + return compareBasedOnLocalName(m1, m2); + case PARTNERCODE: + return compareBasedOPartnerCode(m1, m2); + case PARTNERNAME: + if (!isGetLocalPartnerCourseInitialised) { + break; + } + return compareBasedOnPartnerName(m1, m2); + case UNIVERSITY: + return compareBasedOnUniversityName(m1, m2); + case INFORMATION: + return compareBasedOnInformation(m1, m2); + default: + // This will not happen + return 0; + } + return 0; + } + + private int compareBasedOnLocalCode(Mapping m1, Mapping m2) { + int diff = m1.getLocalCode().getValue().compareToIgnoreCase( + m2.getLocalCode().getValue() + ); + return Integer.compare(diff, 0); + } + + private int compareBasedOPartnerCode(Mapping m1, Mapping m2) { + int diff = m1.getPartnerCode().getValue().compareToIgnoreCase( + m2.getPartnerCode().getValue() + ); + return Integer.compare(diff, 0); + } + + private int compareBasedOnUniversityName(Mapping m1, Mapping m2) { + int diff = m1.getUniversityName().getValue().compareToIgnoreCase( + m2.getUniversityName().getValue() + ); + return Integer.compare(diff, 0); + } + + private int compareBasedOnLocalName(Mapping m1, Mapping m2) { + String localNameOfM1 = getLocalCourseIfExists + .apply(m1.getLocalCode()).map(lc -> lc.getLocalName().getValue()).orElse(""); + String localNameOfM2 = getLocalCourseIfExists + .apply(m2.getLocalCode()).map(lc -> lc.getLocalName().getValue()).orElse(""); + int diff = localNameOfM1.compareToIgnoreCase(localNameOfM2); + return Integer.compare(diff, 0); + } + + private int compareBasedOnPartnerName(Mapping m1, Mapping m2) { + String partnerNameOfM1 = getPartnerCourseIfExists + .apply(m1.getPartnerCode(), m1.getUniversityName()) + .map(pc -> pc.getPartnerName().getValue()).orElse(""); + String partnerNameOfM2 = getPartnerCourseIfExists + .apply(m2.getPartnerCode(), m2.getUniversityName()) + .map(pc -> pc.getPartnerName().getValue()).orElse(""); + int diff = partnerNameOfM1.compareToIgnoreCase(partnerNameOfM2); + return Integer.compare(diff, 0); + } + + private int compareBasedOnInformation(Mapping m1, Mapping m2) { + int diff = m1.getMappingMiscInformation().getValue().compareToIgnoreCase( + m2.getMappingMiscInformation().getValue() + ); + return Integer.compare(diff, 0); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof MappingComparatorByAttribute)) { + return false; + } + + MappingComparatorByAttribute otherComparator = (MappingComparatorByAttribute) other; + return attribute.equals(otherComparator.attribute); + } + + @Override + public String toString() { + return new ToStringBuilder(this).add("attribute", attribute).toString(); + } +} From 42b849ef6c3054c16ed8dd79c0866b5a1ab094ca Mon Sep 17 00:00:00 2001 From: lamchenghou Date: Thu, 2 Nov 2023 21:48:14 +0800 Subject: [PATCH 4/6] Add parsing and command for mapping sort --- .../commands/mapping/MappingSortCommand.java | 85 +++++++++++++++++++ .../address/logic/parser/SeplendidParser.java | 4 + .../mapping/MappingSortCommandParser.java | 52 ++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 src/main/java/seedu/address/logic/commands/mapping/MappingSortCommand.java create mode 100644 src/main/java/seedu/address/logic/parser/mapping/MappingSortCommandParser.java diff --git a/src/main/java/seedu/address/logic/commands/mapping/MappingSortCommand.java b/src/main/java/seedu/address/logic/commands/mapping/MappingSortCommand.java new file mode 100644 index 00000000000..6f2df06dece --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/mapping/MappingSortCommand.java @@ -0,0 +1,85 @@ +package seedu.address.logic.commands.mapping; + +import static java.util.Objects.requireNonNull; + +import seedu.address.commons.util.ToStringBuilder; +import seedu.address.logic.commands.CommandResult; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.SeplendidModel; +import seedu.address.model.mapping.MappingComparatorByAttribute; +import seedu.address.seplendidui.UiUtil; + +/** + * Lists all mappings in the MappingCatalogue. + */ +public class MappingSortCommand extends MappingCommand { + + public static final String MAPPING_SORT_MESSAGE_USAGE = COMMAND_WORD + + " sort [localcode/localname/partnercode/partnername/university/information]: " + + "Sorts all mappings based on the specified attribute."; + public static final String ACTION_WORD = "sort"; + + public static final String MESSAGE_SUCCESS = "Sorted mappings by %1$s."; + + private final MappingComparatorByAttribute mappingComparator; + + /** + * Creates a MappingSortCommand to add the specified {@code mappingComparator} + * + * @param mappingComparator Search mappingComparator. + */ + public MappingSortCommand(MappingComparatorByAttribute mappingComparator) { + super(); + this.mappingComparator = mappingComparator; + } + + /** + * TBD: This stub is to be removed after morphing is complete. + * + * @param model {@code Model} which the command should operate on. + * @return Nothing. + * @throws CommandException Always. + */ + @Override + public CommandResult execute(Model model) throws CommandException { + throw new CommandException("TBD: this is a stub and should be removed after morph."); + } + + @Override + public CommandResult execute(SeplendidModel seplendidModel) throws CommandException { + requireNonNull(seplendidModel); + // Inject model functions into mappingComparator + mappingComparator.initialiseGetLocalPartnercourse(seplendidModel::getLocalCourseIfExists, + seplendidModel::getPartnerCourseIfExists); + seplendidModel.updateSortedMappingList(mappingComparator); + return new CommandResult( + String.format(MESSAGE_SUCCESS, mappingComparator.getAttribute().toString().toLowerCase()), + UiUtil.ListViewModel.MAPPING_SORT); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof MappingSortCommand)) { + return false; + } + + MappingSortCommand otherMappingSortCommand = (MappingSortCommand) other; + return mappingComparator.equals(otherMappingSortCommand.mappingComparator); + } + + + @Override + public String toString() { + return new ToStringBuilder(this) + .add("mappingComparator", mappingComparator) + .toString(); + } + + +} diff --git a/src/main/java/seedu/address/logic/parser/SeplendidParser.java b/src/main/java/seedu/address/logic/parser/SeplendidParser.java index bda53c632c4..3bef27aa2a7 100644 --- a/src/main/java/seedu/address/logic/parser/SeplendidParser.java +++ b/src/main/java/seedu/address/logic/parser/SeplendidParser.java @@ -21,6 +21,7 @@ import seedu.address.logic.commands.mapping.MappingDeleteCommand; import seedu.address.logic.commands.mapping.MappingListCommand; import seedu.address.logic.commands.mapping.MappingSearchCommand; +import seedu.address.logic.commands.mapping.MappingSortCommand; import seedu.address.logic.commands.note.NoteAddCommand; import seedu.address.logic.commands.note.NoteCommand; import seedu.address.logic.commands.note.NoteDeleteCommand; @@ -46,6 +47,7 @@ import seedu.address.logic.parser.mapping.MappingAddCommandParser; import seedu.address.logic.parser.mapping.MappingDeleteCommandParser; import seedu.address.logic.parser.mapping.MappingSearchCommandParser; +import seedu.address.logic.parser.mapping.MappingSortCommandParser; import seedu.address.logic.parser.note.NoteAddCommandParser; import seedu.address.logic.parser.note.NoteSearchCommandParser; import seedu.address.logic.parser.partnercourse.PartnerCourseAddCommandParser; @@ -217,6 +219,8 @@ private MappingCommand getMappingCommandWithArg(String userInput, String actionW return new MappingDeleteCommandParser().parse(arguments); case MappingSearchCommand.ACTION_WORD: return new MappingSearchCommandParser().parse(arguments); + case MappingSortCommand.ACTION_WORD: + return new MappingSortCommandParser().parse(arguments); default: logger.finer("This user input caused a ParseException: " + userInput); throw new ParseException(MESSAGE_UNKNOWN_COMMAND); diff --git a/src/main/java/seedu/address/logic/parser/mapping/MappingSortCommandParser.java b/src/main/java/seedu/address/logic/parser/mapping/MappingSortCommandParser.java new file mode 100644 index 00000000000..b47016105ef --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/mapping/MappingSortCommandParser.java @@ -0,0 +1,52 @@ +package seedu.address.logic.parser.mapping; + +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PARAMETER_MAPPINGATTRIBUTE; +import static seedu.address.logic.parser.ParserUtil.areValuesEnclosedAndNonEmpty; +import static seedu.address.logic.parser.ParserUtil.parseMappingAttribute; + +import seedu.address.logic.commands.mapping.MappingSortCommand; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.ParserUtil; +import seedu.address.logic.parser.SeplendidArgumentMap; +import seedu.address.logic.parser.SeplendidArgumentTokenizer; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.mapping.MappingAttributeEnum; +import seedu.address.model.mapping.MappingComparatorByAttribute; + +/** + * Parses input arguments and creates a new MappingSortCommandParser object. + */ +public class MappingSortCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the MappingSortCommandParser + * and returns a MappingSortCommandParser object for execution. + * + * @throws ParseException if the user input does not conform the expected format + */ + public MappingSortCommand parse(String args) throws ParseException { + if (!areValuesEnclosedAndNonEmpty(args)) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, + MappingSortCommand.MAPPING_SORT_MESSAGE_USAGE)); + } + + SeplendidArgumentMap parameterToArgMap = + SeplendidArgumentTokenizer.tokenize(args, PARAMETER_MAPPINGATTRIBUTE); + + + if (!ParserUtil.areArgumentsPresent(parameterToArgMap, PARAMETER_MAPPINGATTRIBUTE)) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, + MappingSortCommand.MAPPING_SORT_MESSAGE_USAGE)); + } + + // All arguments should be a non-empty {@code Optional} + MappingAttributeEnum attributeEnumValue = parseMappingAttribute(parameterToArgMap.getValue( + PARAMETER_MAPPINGATTRIBUTE).get().toLowerCase()); + + MappingComparatorByAttribute mappingComparator = new MappingComparatorByAttribute(attributeEnumValue); + + return new MappingSortCommand(mappingComparator); + } + +} From ded27201af8fb43b4083b4b3082b2056076823f7 Mon Sep 17 00:00:00 2001 From: lamchenghou Date: Thu, 2 Nov 2023 21:48:23 +0800 Subject: [PATCH 5/6] Update UI for mapping sort --- src/main/java/seedu/address/seplendidui/MainWindow.java | 4 ++++ src/main/java/seedu/address/seplendidui/UiUtil.java | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/seplendidui/MainWindow.java b/src/main/java/seedu/address/seplendidui/MainWindow.java index f19d58b69c2..fede1058bd1 100644 --- a/src/main/java/seedu/address/seplendidui/MainWindow.java +++ b/src/main/java/seedu/address/seplendidui/MainWindow.java @@ -66,6 +66,7 @@ public MainWindow(Stage primaryStage, SeplendidLogic seplendidLogic) { public Stage getPrimaryStage() { return primaryStage; } + /** * Fills up all the placeholders of this window. */ @@ -154,6 +155,9 @@ private CommandResult executeCommand(String commandText) throws CommandException case UNIVERSITY_SORT: itemListPanel.setDisplayList(seplendidLogic.getSortedUniversityCatalogue()); break; + case MAPPING_SORT: + itemListPanel.setDisplayList(seplendidLogic.getSortedMappingCatalogue()); + break; default: // do nothing } diff --git a/src/main/java/seedu/address/seplendidui/UiUtil.java b/src/main/java/seedu/address/seplendidui/UiUtil.java index 2d618ea971a..310b0b0da7c 100644 --- a/src/main/java/seedu/address/seplendidui/UiUtil.java +++ b/src/main/java/seedu/address/seplendidui/UiUtil.java @@ -16,7 +16,8 @@ public enum ListViewModel { MAPPING_LIST, LOCAL_COURSE_SORT, PARTNER_COURSE_SORT, - UNIVERSITY_SORT; + UNIVERSITY_SORT, + MAPPING_SORT; @Override From 6dd057fc24d28d5617775d7b453d0bcb1abefdaf Mon Sep 17 00:00:00 2001 From: lamchenghou Date: Thu, 2 Nov 2023 22:04:41 +0800 Subject: [PATCH 6/6] Fix style and update tests --- .../commands/LocalCourseAddCommandTest.java | 21 ++++++++++++----- .../LocalCourseDeleteCommandTest.java | 23 ++++++++++++++----- .../commands/PartnerCourseAddCommandTest.java | 21 +++++++++++++---- .../PartnerCourseDeleteCommandTest.java | 20 ++++++++++++---- 4 files changed, 63 insertions(+), 22 deletions(-) diff --git a/src/test/java/seedu/address/logic/commands/LocalCourseAddCommandTest.java b/src/test/java/seedu/address/logic/commands/LocalCourseAddCommandTest.java index 79632c7ac19..b31475c9e7c 100644 --- a/src/test/java/seedu/address/logic/commands/LocalCourseAddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/LocalCourseAddCommandTest.java @@ -63,8 +63,8 @@ public void execute_localCourseAcceptedByModel_addSuccessful() throws Exception CommandResult commandResult = new LocalCourseAddCommand(validLocalCourse).execute(modelStub); assertEquals( - String.format(LocalCourseAddCommand.MESSAGE_SUCCESS, Messages.format(validLocalCourse)), - commandResult.getFeedbackToUser()); + String.format(LocalCourseAddCommand.MESSAGE_SUCCESS, Messages.format(validLocalCourse)), + commandResult.getFeedbackToUser()); assertEquals(Arrays.asList(validLocalCourse), modelStub.localCoursesAdded); } @@ -75,9 +75,9 @@ public void execute_duplicateLocalCourse_throwsCommandException() { SeplendidModelStub modelStub = new SeplendidModelStubWithLocalCourse(validLocalCourse); assertThrows( - CommandException.class, - LocalCourseAddCommand.MESSAGE_DUPLICATE_LOCAL_COURSE, ( - ) -> localCourseAddCommand.execute(modelStub)); + CommandException.class, + LocalCourseAddCommand.MESSAGE_DUPLICATE_LOCAL_COURSE, ( + ) -> localCourseAddCommand.execute(modelStub)); } @Test @@ -342,7 +342,7 @@ public void updateSortedUniversityList(Comparator universityComparat @Override public void getSearchUniversityIfExists( - UniversityNameContainsKeywordsPredicate universityNameContainsKeywordsPredicate + UniversityNameContainsKeywordsPredicate universityNameContainsKeywordsPredicate ) { throw new AssertionError("This method should not be called."); } @@ -465,6 +465,15 @@ public void updateFilteredMappingList(Predicate predicate) { throw new AssertionError("This method should not be called."); } + @Override + public ObservableList getSortedMappingList() { + throw new AssertionError("This method should not be called."); + } + + @Override + public void updateSortedMappingList(Comparator mappingComparator) { + throw new AssertionError("This method should not be called."); + } } /** diff --git a/src/test/java/seedu/address/logic/commands/LocalCourseDeleteCommandTest.java b/src/test/java/seedu/address/logic/commands/LocalCourseDeleteCommandTest.java index 3f0a6710d98..fd472f02eac 100644 --- a/src/test/java/seedu/address/logic/commands/LocalCourseDeleteCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/LocalCourseDeleteCommandTest.java @@ -65,7 +65,7 @@ public void execute_localCourseAcceptedByModel_deleteSuccessful() throws Excepti CommandResult commandResult = new LocalCourseDeleteCommand(CS2030S.getLocalCode()).execute(modelStub); assertEquals(String.format(LocalCourseDeleteCommand.MESSAGE_SUCCESS, Messages.format(CS2030S)), - commandResult.getFeedbackToUser()); + commandResult.getFeedbackToUser()); assertEquals(Arrays.asList(CS2040S), modelStub.localCoursesAdded); } @@ -73,13 +73,13 @@ public void execute_localCourseAcceptedByModel_deleteSuccessful() throws Excepti public void execute_localCourseDoesNotExist_throwsCommandException() { LocalCourse validLocalCourse = new LocalCourseBuilder().build(); LocalCourseDeleteCommand localCourseDeleteCommand = new LocalCourseDeleteCommand(new LocalCode( - TYPICAL_LOCAL_COURSE_CODE)); + TYPICAL_LOCAL_COURSE_CODE)); SeplendidModelStub modelStub = new SeplendidModelStubWithLocalCourse(validLocalCourse); assertThrows( - CommandException.class, - LocalCourseDeleteCommand.MESSAGE_NONEXISTENT_LOCAL_COURSE, ( - ) -> localCourseDeleteCommand.execute(modelStub)); + CommandException.class, + LocalCourseDeleteCommand.MESSAGE_NONEXISTENT_LOCAL_COURSE, ( + ) -> localCourseDeleteCommand.execute(modelStub)); } @Test @@ -143,6 +143,7 @@ public void searchLocalCourses(LocalCourseAttribute attribute, LocalCourseContainsKeywordsPredicate predicate) { throw new AssertionError("This method should not be called."); } + @Override public Path getLocalCourseCatalogueFilePath() { throw new AssertionError("This method should not be called."); @@ -293,7 +294,7 @@ public ReadOnlyUniversityCatalogue getUniversityCatalogue() { @Override public void getSearchUniversityIfExists( - UniversityNameContainsKeywordsPredicate universityNameContainsKeywordsPredicate + UniversityNameContainsKeywordsPredicate universityNameContainsKeywordsPredicate ) { } @@ -465,6 +466,16 @@ public void updateFilteredMappingList(Predicate predicate) { throw new AssertionError("This method should not be called."); } + @Override + public ObservableList getSortedMappingList() { + throw new AssertionError("This method should not be called."); + } + + @Override + public void updateSortedMappingList(Comparator mappingComparator) { + throw new AssertionError("This method should not be called."); + } + } /** diff --git a/src/test/java/seedu/address/logic/commands/PartnerCourseAddCommandTest.java b/src/test/java/seedu/address/logic/commands/PartnerCourseAddCommandTest.java index da283be9153..dc28d28d9fb 100644 --- a/src/test/java/seedu/address/logic/commands/PartnerCourseAddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/PartnerCourseAddCommandTest.java @@ -62,7 +62,7 @@ public void execute_partnerCourseAcceptedByModel_addSuccessful() throws Exceptio CommandResult commandResult = new PartnerCourseAddCommand(validPartnerCourse).execute(modelStub); assertEquals(String.format(PartnerCourseAddCommand.MESSAGE_SUCCESS, Messages.format(validPartnerCourse)), - commandResult.getFeedbackToUser()); + commandResult.getFeedbackToUser()); assertEquals(Arrays.asList(validPartnerCourse), modelStub.partnerCoursesAdded); } @@ -73,9 +73,9 @@ public void execute_duplicatePartnerCourse_throwsCommandException() { SeplendidModelStub modelStub = new SeplendidModelStubWithPartnerCourse(validPartnerCourse); assertThrows( - CommandException.class, - PartnerCourseAddCommand.MESSAGE_DUPLICATE_PARTNER_COURSE, ( - ) -> partnerCourseAddCommand.execute(modelStub)); + CommandException.class, + PartnerCourseAddCommand.MESSAGE_DUPLICATE_PARTNER_COURSE, ( + ) -> partnerCourseAddCommand.execute(modelStub)); } @Test @@ -133,6 +133,7 @@ public void searchLocalCourses(LocalCourseAttribute attribute, LocalCourseContainsKeywordsPredicate predicate) { throw new AssertionError("This method should not be called."); } + @Override public Path getLocalCourseCatalogueFilePath() { throw new AssertionError("This method should not be called."); @@ -296,7 +297,7 @@ public void setNoteCatalogue(ReadOnlyNoteCatalogue noteCatalogue) { @Override public void getSearchUniversityIfExists( - UniversityNameContainsKeywordsPredicate universityNameContainsKeywordsPredicate + UniversityNameContainsKeywordsPredicate universityNameContainsKeywordsPredicate ) { throw new AssertionError("This method should not be called."); } @@ -453,6 +454,16 @@ public void updateFilteredMappingList(Predicate predicate) { throw new AssertionError("This method should not be called."); } + @Override + public ObservableList getSortedMappingList() { + throw new AssertionError("This method should not be called."); + } + + @Override + public void updateSortedMappingList(Comparator mappingComparator) { + throw new AssertionError("This method should not be called."); + } + } /** diff --git a/src/test/java/seedu/address/logic/commands/PartnerCourseDeleteCommandTest.java b/src/test/java/seedu/address/logic/commands/PartnerCourseDeleteCommandTest.java index 4789f5f7541..62d8ec07e7d 100644 --- a/src/test/java/seedu/address/logic/commands/PartnerCourseDeleteCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/PartnerCourseDeleteCommandTest.java @@ -67,7 +67,7 @@ public void execute_partnerCourseAcceptedByModel_deleteSuccessful() throws Excep COMP1000.getPartnerCode(), COMP1000.getPartnerUniversity().getUniversityName()).execute(modelStub); assertEquals(String.format(PartnerCourseDeleteCommand.MESSAGE_SUCCESS, Messages.format(COMP1000)), - commandResult.getFeedbackToUser()); + commandResult.getFeedbackToUser()); assertEquals(Arrays.asList(COMP2000), modelStub.partnerCoursesAdded); } @@ -80,9 +80,9 @@ public void execute_partnerCourseDoesNotExist_throwsCommandException() { SeplendidModelStub modelStub = new SeplendidModelStubWithPartnerCourse(validPartnerCourse); assertThrows( - CommandException.class, - PartnerCourseDeleteCommand.MESSAGE_NONEXISTENT_PARTNER_COURSE, ( - ) -> partnerCourseDeleteCommand.execute(modelStub)); + CommandException.class, + PartnerCourseDeleteCommand.MESSAGE_NONEXISTENT_PARTNER_COURSE, ( + ) -> partnerCourseDeleteCommand.execute(modelStub)); } @Test @@ -141,6 +141,7 @@ public void searchLocalCourses(LocalCourseAttribute attribute, LocalCourseContainsKeywordsPredicate predicate) { throw new AssertionError("This method should not be called."); } + @Override public Path getLocalCourseCatalogueFilePath() { throw new AssertionError("This method should not be called."); @@ -321,7 +322,7 @@ public void setUniversityCatalogueFilePath(Path universityCatalogueFilePath) { @Override public void getSearchUniversityIfExists( - UniversityNameContainsKeywordsPredicate universityNameContainsKeywordsPredicate + UniversityNameContainsKeywordsPredicate universityNameContainsKeywordsPredicate ) { throw new AssertionError("This method should not be called."); } @@ -463,6 +464,15 @@ public void updateFilteredMappingList(Predicate predicate) { throw new AssertionError("This method should not be called."); } + @Override + public ObservableList getSortedMappingList() { + throw new AssertionError("This method should not be called."); + } + + @Override + public void updateSortedMappingList(Comparator mappingComparator) { + throw new AssertionError("This method should not be called."); + } } /**