From f67b60657863408b193538b58d1de1c52e6eb1d1 Mon Sep 17 00:00:00 2001 From: GabrielWLM Date: Tue, 26 Oct 2021 04:12:02 +0800 Subject: [PATCH 1/3] add basic find group command --- .../seedu/address/commons/core/Messages.java | 3 +- .../logic/commands/FindGroupCommand.java | 51 +++++++++++++++++++ .../ClassCodeContainsKeywordsPredicate.java | 2 +- ...utorialGroupContainsKeywordsPredicate.java | 33 ++++++++++++ 4 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 src/main/java/seedu/address/logic/commands/FindGroupCommand.java create mode 100644 src/main/java/seedu/address/model/tutorialgroup/TutorialGroupContainsKeywordsPredicate.java diff --git a/src/main/java/seedu/address/commons/core/Messages.java b/src/main/java/seedu/address/commons/core/Messages.java index 94c5f7a9dca..7193f209bfa 100644 --- a/src/main/java/seedu/address/commons/core/Messages.java +++ b/src/main/java/seedu/address/commons/core/Messages.java @@ -11,6 +11,7 @@ public class Messages { public static final String MESSAGE_INVALID_CLASS_DISPLAYED_INDEX = "The class index provided is invalid"; public static final String MESSAGE_INVALID_GROUP_DISPLAYED_INDEX = "The group index provided is invalid"; public static final String MESSAGE_STUDENTS_LISTED_OVERVIEW = "%1$d students listed!"; - public static final String MESSAGE_TUTORIAL_CLASSES_LISTED_OVERVIEW = "%1$d classes listed!"; + public static final String MESSAGE_TUTORIAL_CLASSES_LISTED_OVERVIEW = "%1$d tutorial classes listed!"; + public static final String MESSAGE_TUTORIAL_GROUPS_LISTED_OVERVIEW = "%1$d tutorial groups listed!"; } diff --git a/src/main/java/seedu/address/logic/commands/FindGroupCommand.java b/src/main/java/seedu/address/logic/commands/FindGroupCommand.java new file mode 100644 index 00000000000..4a51ed924a3 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/FindGroupCommand.java @@ -0,0 +1,51 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; +import static seedu.address.logic.parser.CliSyntax.PREFIX_CLASSCODE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TYPE; + +import seedu.address.commons.core.Messages; +import seedu.address.model.Model; +import seedu.address.model.tutorialgroup.TutorialGroupContainsKeywordsPredicate; + +/** + * Finds and lists all tutorial groups in ClassMATE whose class code and tutorial group contains any of the argument + * keywords. + * Keyword matching is case-insensitive. + */ +public class FindGroupCommand extends Command { + + public static final String COMMAND_WORD = "findc"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all tutorial groups whose class code and" + + "tutorial group contain any of the specified keywords (case-insensitive) and displays them as a list" + + "with index numbers.\n" + + "Parameters: " + + PREFIX_CLASSCODE + "KEYWORD" + + "[" + PREFIX_TYPE + "KEYWORD\n" + + "Example: " + COMMAND_WORD + " " + + PREFIX_CLASSCODE + "G06 " + + PREFIX_TYPE + "OP1 "; + + private final TutorialGroupContainsKeywordsPredicate predicate; + + public FindGroupCommand(TutorialGroupContainsKeywordsPredicate predicate) { + this.predicate = predicate; + } + + @Override + public CommandResult execute(Model model) { + requireNonNull(model); + model.updateFilteredTutorialGroupList(predicate); + return new CommandResult( + String.format(Messages.MESSAGE_TUTORIAL_GROUPS_LISTED_OVERVIEW, + model.getFilteredTutorialGroupList().size())); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof FindGroupCommand // instanceof handles nulls + && predicate.equals(((FindGroupCommand) other).predicate)); // state check + } +} diff --git a/src/main/java/seedu/address/model/tutorialclass/ClassCodeContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/tutorialclass/ClassCodeContainsKeywordsPredicate.java index d9fa367ffb8..e0cbf40c15b 100644 --- a/src/main/java/seedu/address/model/tutorialclass/ClassCodeContainsKeywordsPredicate.java +++ b/src/main/java/seedu/address/model/tutorialclass/ClassCodeContainsKeywordsPredicate.java @@ -6,7 +6,7 @@ import seedu.address.commons.util.StringUtil; /** - * Tests that a {@code Student}'s {@code Name} matches any of the keywords given. + * Tests that a {@code TutorialClass}'s {@code ClassCode} matches any of the keywords given. */ public class ClassCodeContainsKeywordsPredicate implements Predicate { private final List keywords; diff --git a/src/main/java/seedu/address/model/tutorialgroup/TutorialGroupContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/tutorialgroup/TutorialGroupContainsKeywordsPredicate.java new file mode 100644 index 00000000000..8fa1e2a0797 --- /dev/null +++ b/src/main/java/seedu/address/model/tutorialgroup/TutorialGroupContainsKeywordsPredicate.java @@ -0,0 +1,33 @@ +package seedu.address.model.tutorialgroup; + +import java.util.List; +import java.util.function.Predicate; + +import seedu.address.commons.util.StringUtil; + +/** + * Tests that a {@code TutorialGroup}'s {@code GroupName} matches any of the keywords given. + */ +public class TutorialGroupContainsKeywordsPredicate implements Predicate { + private final List keywords; + + public TutorialGroupContainsKeywordsPredicate(List keywords) { + this.keywords = keywords; + } + + @Override + public boolean test(TutorialGroup tutorialGroup) { + return keywords.stream() + .anyMatch(keyword -> StringUtil.containsWordIgnoreCase( + tutorialGroup.getClassCode().toString(), keyword)); + //TODO Add GroupType as a keyword + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof TutorialGroupContainsKeywordsPredicate // instanceof handles nulls + && keywords.equals(((TutorialGroupContainsKeywordsPredicate) other).keywords)); // state check + } + +} From 1940280b089f73fd7ef6da1eb836dae1cd1f301e Mon Sep 17 00:00:00 2001 From: GabrielWLM Date: Fri, 29 Oct 2021 07:55:53 +0800 Subject: [PATCH 2/3] commit before merging --- .../seedu/address/commons/core/Messages.java | 5 +-- .../logic/commands/AddGroupCommand.java | 9 ++--- ...roupCommand.java => ViewGroupCommand.java} | 34 +++++++++++-------- .../seedu/address/logic/parser/CliSyntax.java | 2 +- .../logic/parser/FindClassCommandParser.java | 6 ++-- .../parser/FindStudentCommandParser.java | 6 ++-- .../logic/parser/ViewGroupCommandParser.java | 33 ++++++++++++++++++ .../model/student/GroupNamePredicate.java | 30 ++++++++++++++++ .../model/student/GroupTypePredicate.java | 32 +++++++++++++++++ .../seedu/address/model/student/Student.java | 5 ++- 10 files changed, 134 insertions(+), 28 deletions(-) rename src/main/java/seedu/address/logic/commands/{FindGroupCommand.java => ViewGroupCommand.java} (50%) create mode 100644 src/main/java/seedu/address/logic/parser/ViewGroupCommandParser.java create mode 100644 src/main/java/seedu/address/model/student/GroupNamePredicate.java create mode 100644 src/main/java/seedu/address/model/student/GroupTypePredicate.java diff --git a/src/main/java/seedu/address/commons/core/Messages.java b/src/main/java/seedu/address/commons/core/Messages.java index 7193f209bfa..62016154176 100644 --- a/src/main/java/seedu/address/commons/core/Messages.java +++ b/src/main/java/seedu/address/commons/core/Messages.java @@ -12,6 +12,7 @@ public class Messages { public static final String MESSAGE_INVALID_GROUP_DISPLAYED_INDEX = "The group index provided is invalid"; public static final String MESSAGE_STUDENTS_LISTED_OVERVIEW = "%1$d students listed!"; public static final String MESSAGE_TUTORIAL_CLASSES_LISTED_OVERVIEW = "%1$d tutorial classes listed!"; - public static final String MESSAGE_TUTORIAL_GROUPS_LISTED_OVERVIEW = "%1$d tutorial groups listed!"; - + public static final String MESSAGE_TUTORIAL_GROUP_LISTED_OVERVIEW = "%1$d students from tutorial group listed!"; + public static final String MESSAGE_CLASS_DOES_NOT_EXIST = "This class does not exist in Classmate"; + public static final String MESSAGE_GROUP_DOES_NOT_EXIST = "This group does not exist in Classmate"; } diff --git a/src/main/java/seedu/address/logic/commands/AddGroupCommand.java b/src/main/java/seedu/address/logic/commands/AddGroupCommand.java index 7776feab5b5..f0b344e24e3 100644 --- a/src/main/java/seedu/address/logic/commands/AddGroupCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddGroupCommand.java @@ -19,8 +19,8 @@ public class AddGroupCommand extends Command { public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a group to a class to Classmate. " + "Parameters: " - + PREFIX_GROUPNAME + "GROUPNAME " + PREFIX_CLASSCODE + "CLASSCODE " + + PREFIX_GROUPNAME + "GROUPNAME " + PREFIX_TYPE + "TYPE " + "Example: " + COMMAND_WORD + " " + PREFIX_GROUPNAME + "1 " @@ -29,7 +29,7 @@ public class AddGroupCommand extends Command { public static final String MESSAGE_SUCCESS = "New group added: %1$s"; public static final String MESSAGE_DUPLICATE_GROUP = "This group already exists in Classmate"; - public static final String MESSAGE_GROUP_NOT_EXIST = "The class does not exist in Classmate"; + public static final String MESSAGE_CLASS_DOES_NOT_EXIST = "The class does not exist in Classmate"; private final TutorialGroup toAdd; private final TutorialClass toAddTutorialClass; @@ -41,7 +41,8 @@ public AddGroupCommand(TutorialGroup tutorialGroup) { requireNonNull(tutorialGroup); toAdd = tutorialGroup; // new class with the same class code created to check whether it already exists in ClassMATE - toAddTutorialClass = new TutorialClass(tutorialGroup.getClassCode(), new Schedule("dummy"), new HashSet()); + toAddTutorialClass = new TutorialClass(tutorialGroup.getClassCode(), new Schedule("dummy"), + new HashSet()); } @Override @@ -50,7 +51,7 @@ public CommandResult execute(Model model) throws CommandException { // check if tutorial class already exists in ClassMATE if (!model.hasTutorialClass(toAddTutorialClass)) { - throw new CommandException(MESSAGE_GROUP_NOT_EXIST); + throw new CommandException(MESSAGE_CLASS_DOES_NOT_EXIST); } if (model.hasTutorialGroup(toAdd)) { diff --git a/src/main/java/seedu/address/logic/commands/FindGroupCommand.java b/src/main/java/seedu/address/logic/commands/ViewGroupCommand.java similarity index 50% rename from src/main/java/seedu/address/logic/commands/FindGroupCommand.java rename to src/main/java/seedu/address/logic/commands/ViewGroupCommand.java index 4a51ed924a3..8b0e9093b7e 100644 --- a/src/main/java/seedu/address/logic/commands/FindGroupCommand.java +++ b/src/main/java/seedu/address/logic/commands/ViewGroupCommand.java @@ -2,34 +2,37 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_CLASSCODE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_GROUPNAME; import static seedu.address.logic.parser.CliSyntax.PREFIX_TYPE; import seedu.address.commons.core.Messages; import seedu.address.model.Model; +import seedu.address.model.student.ClassMemberPredicate; import seedu.address.model.tutorialgroup.TutorialGroupContainsKeywordsPredicate; /** - * Finds and lists all tutorial groups in ClassMATE whose class code and tutorial group contains any of the argument - * keywords. + * Lists all students in a tutorial group in ClassMATE given a class code, tutorial group type and tutorial group name * Keyword matching is case-insensitive. */ -public class FindGroupCommand extends Command { +public class ViewGroupCommand extends Command { - public static final String COMMAND_WORD = "findc"; + public static final String COMMAND_WORD = "viewg"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all tutorial groups whose class code and" - + "tutorial group contain any of the specified keywords (case-insensitive) and displays them as a list" + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all students in a tutorial group given a class " + + "code, tutorial group type and tutorial group name (case-insensitive) and displays them as a list" + "with index numbers.\n" + "Parameters: " - + PREFIX_CLASSCODE + "KEYWORD" - + "[" + PREFIX_TYPE + "KEYWORD\n" + + PREFIX_CLASSCODE + "CLASSCODE " + + PREFIX_GROUPNAME + "GROUPNAME " + + PREFIX_TYPE + "TYPE " + "Example: " + COMMAND_WORD + " " + + PREFIX_GROUPNAME + "3 " + PREFIX_CLASSCODE + "G06 " - + PREFIX_TYPE + "OP1 "; + + PREFIX_TYPE + "OP2 "; private final TutorialGroupContainsKeywordsPredicate predicate; - public FindGroupCommand(TutorialGroupContainsKeywordsPredicate predicate) { + public ViewGroupCommand(TutorialGroupContainsKeywordsPredicate predicate) { this.predicate = predicate; } @@ -37,15 +40,18 @@ public FindGroupCommand(TutorialGroupContainsKeywordsPredicate predicate) { public CommandResult execute(Model model) { requireNonNull(model); model.updateFilteredTutorialGroupList(predicate); + + + model.updateFilteredStudentList(new ClassMemberPredicate(targetClassCode)); return new CommandResult( - String.format(Messages.MESSAGE_TUTORIAL_GROUPS_LISTED_OVERVIEW, - model.getFilteredTutorialGroupList().size())); + String.format(Messages.MESSAGE_TUTORIAL_GROUP_LISTED_OVERVIEW, + model.getFilteredStudentList().size())); } @Override public boolean equals(Object other) { return other == this // short circuit if same object - || (other instanceof FindGroupCommand // instanceof handles nulls - && predicate.equals(((FindGroupCommand) other).predicate)); // state check + || (other instanceof ViewGroupCommand // instanceof handles nulls + && predicate.equals(((ViewGroupCommand) other).predicate)); // state check } } diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 65d32ced65b..5005df0e10f 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -5,7 +5,7 @@ */ public class CliSyntax { - /* Student Prefix definitions */ + // Student Prefix definitions public static final Prefix PREFIX_NAME = new Prefix("n/"); public static final Prefix PREFIX_PHONE = new Prefix("p/"); public static final Prefix PREFIX_EMAIL = new Prefix("e/"); diff --git a/src/main/java/seedu/address/logic/parser/FindClassCommandParser.java b/src/main/java/seedu/address/logic/parser/FindClassCommandParser.java index 9a1e8daaedd..3fff11c09bf 100644 --- a/src/main/java/seedu/address/logic/parser/FindClassCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/FindClassCommandParser.java @@ -9,13 +9,13 @@ import seedu.address.model.tutorialclass.ClassCodeContainsKeywordsPredicate; /** - * Parses input arguments and creates a new FindCommand object + * Parses input arguments and creates a new FindClassCommand object */ public class FindClassCommandParser implements Parser { /** - * Parses the given {@code String} of arguments in the context of the FindCommand - * and returns a FindCommand object for execution. + * Parses the given {@code String} of arguments in the context of the FindClassCommand + * and returns a FindClassCommand object for execution. * @throws ParseException if the user input does not conform the expected format */ public FindClassCommand parse(String args) throws ParseException { diff --git a/src/main/java/seedu/address/logic/parser/FindStudentCommandParser.java b/src/main/java/seedu/address/logic/parser/FindStudentCommandParser.java index b0b2b595f31..8d64b519545 100644 --- a/src/main/java/seedu/address/logic/parser/FindStudentCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/FindStudentCommandParser.java @@ -9,13 +9,13 @@ import seedu.address.model.student.NameContainsKeywordsPredicate; /** - * Parses input arguments and creates a new FindCommand object + * Parses input arguments and creates a new FindStudentCommand object */ public class FindStudentCommandParser implements Parser { /** - * Parses the given {@code String} of arguments in the context of the FindCommand - * and returns a FindCommand object for execution. + * Parses the given {@code String} of arguments in the context of the FindStudentCommand + * and returns a FindStudentCommand object for execution. * @throws ParseException if the user input does not conform the expected format */ public FindStudentCommand parse(String args) throws ParseException { diff --git a/src/main/java/seedu/address/logic/parser/ViewGroupCommandParser.java b/src/main/java/seedu/address/logic/parser/ViewGroupCommandParser.java new file mode 100644 index 00000000000..cedf492c061 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/ViewGroupCommandParser.java @@ -0,0 +1,33 @@ +package seedu.address.logic.parser; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; + +import java.util.Arrays; + +import seedu.address.logic.commands.ViewGroupCommand; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.tutorialgroup.TutorialGroupContainsKeywordsPredicate; + +/** + * Parses input arguments and creates a new ViewGroupCommand object + */ +public class ViewGroupCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the ViewGroupCommand + * and returns a ViewGroupCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public ViewGroupCommand parse(String args) throws ParseException { + String trimmedArgs = args.trim(); + if (trimmedArgs.isEmpty()) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewGroupCommand.MESSAGE_USAGE)); + } + + String[] nameKeywords = trimmedArgs.split("\\s+"); + + return new ViewGroupCommand(new TutorialGroupContainsKeywordsPredicate(Arrays.asList(nameKeywords))); + } + +} diff --git a/src/main/java/seedu/address/model/student/GroupNamePredicate.java b/src/main/java/seedu/address/model/student/GroupNamePredicate.java new file mode 100644 index 00000000000..cdb72639d63 --- /dev/null +++ b/src/main/java/seedu/address/model/student/GroupNamePredicate.java @@ -0,0 +1,30 @@ +package seedu.address.model.student; + +import java.util.function.Predicate; + +/** + * Tests that a {@code Student}'s {@code GroupName} matches the given group name. + */ +public class GroupNamePredicate implements Predicate { + private final ClassCode classCode; + + public GroupNamePredicate(ClassCode classCode) { + this.classCode = classCode; + } + + public ClassCode getClassCode() { + return classCode; + } + + @Override + public boolean test(Student student) { + return student.getClassCode().equals(classCode); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same instance + || other instanceof GroupNamePredicate // instanceof handles null + && classCode.equals(((GroupNamePredicate) other).getClassCode()); // state check + } +} diff --git a/src/main/java/seedu/address/model/student/GroupTypePredicate.java b/src/main/java/seedu/address/model/student/GroupTypePredicate.java new file mode 100644 index 00000000000..1ed5466d7e0 --- /dev/null +++ b/src/main/java/seedu/address/model/student/GroupTypePredicate.java @@ -0,0 +1,32 @@ +package seedu.address.model.student; + +import java.util.function.Predicate; + +import seedu.address.model.tutorialgroup.GroupType; + +/** + * Tests that a {@code Student}'s {@code GroupType} matches the given group type. + */ +public class GroupTypePredicate implements Predicate { + private final GroupType groupType; + + public GroupTypePredicate(GroupType groupType) { + this.groupType = groupType; + } + + public GroupType getGroupType() { + return groupType; + } + + @Override + public boolean test(Student student) { + return student.getGroupType().equals(groupType); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same instance + || other instanceof GroupTypePredicate // instanceof handles null + && groupType.equals(((GroupTypePredicate) other).getGroupType()); // state check + } +} diff --git a/src/main/java/seedu/address/model/student/Student.java b/src/main/java/seedu/address/model/student/Student.java index 92411585f0a..a015e2727de 100644 --- a/src/main/java/seedu/address/model/student/Student.java +++ b/src/main/java/seedu/address/model/student/Student.java @@ -8,6 +8,8 @@ import java.util.Set; import seedu.address.model.tag.Tag; +import seedu.address.model.tutorialgroup.GroupType; +import seedu.address.model.tutorialgroup.TutorialGroup; /** * Represents a Student in the ClassMATE. @@ -23,8 +25,9 @@ public class Student { // Data fields private final Address address; private final ClassCode classCode; + // private final List marks; private final Set tags = new HashSet<>(); - //private final List marks = new ArrayList<>(); + private final Set tutorialGroups = new HashSet<>(); /** * Every field must be present and not null. From 9edc41957ccef30702eeee27c08d301a4a97cd41 Mon Sep 17 00:00:00 2001 From: GabrielWLM <77065071+GabrielWLM@users.noreply.github.com> Date: Fri, 29 Oct 2021 08:57:40 +0800 Subject: [PATCH 3/3] add find group command --- .../seedu/address/commons/core/Messages.java | 1 - .../logic/commands/AddGroupCommand.java | 4 +- .../logic/commands/ViewGroupCommand.java | 38 +++++++++++++------ .../address/logic/parser/ClassmateParser.java | 4 ++ .../logic/parser/ViewGroupCommandParser.java | 32 ++++++++++++---- .../java/seedu/address/model/Classmate.java | 11 ++++-- .../model/student/GroupMemberPredicate.java | 32 ++++++++++++++++ .../model/student/GroupNamePredicate.java | 30 --------------- .../model/student/GroupTypePredicate.java | 32 ---------------- 9 files changed, 95 insertions(+), 89 deletions(-) create mode 100644 src/main/java/seedu/address/model/student/GroupMemberPredicate.java delete mode 100644 src/main/java/seedu/address/model/student/GroupNamePredicate.java delete mode 100644 src/main/java/seedu/address/model/student/GroupTypePredicate.java diff --git a/src/main/java/seedu/address/commons/core/Messages.java b/src/main/java/seedu/address/commons/core/Messages.java index 62016154176..adb2cf16db3 100644 --- a/src/main/java/seedu/address/commons/core/Messages.java +++ b/src/main/java/seedu/address/commons/core/Messages.java @@ -9,7 +9,6 @@ public class Messages { public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s"; public static final String MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX = "The student index provided is invalid"; public static final String MESSAGE_INVALID_CLASS_DISPLAYED_INDEX = "The class index provided is invalid"; - public static final String MESSAGE_INVALID_GROUP_DISPLAYED_INDEX = "The group index provided is invalid"; public static final String MESSAGE_STUDENTS_LISTED_OVERVIEW = "%1$d students listed!"; public static final String MESSAGE_TUTORIAL_CLASSES_LISTED_OVERVIEW = "%1$d tutorial classes listed!"; public static final String MESSAGE_TUTORIAL_GROUP_LISTED_OVERVIEW = "%1$d students from tutorial group listed!"; diff --git a/src/main/java/seedu/address/logic/commands/AddGroupCommand.java b/src/main/java/seedu/address/logic/commands/AddGroupCommand.java index 9d1fac49cf2..a940d79a7b7 100644 --- a/src/main/java/seedu/address/logic/commands/AddGroupCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddGroupCommand.java @@ -1,6 +1,7 @@ package seedu.address.logic.commands; import static java.util.Objects.requireNonNull; +import static seedu.address.commons.core.Messages.MESSAGE_CLASS_DOES_NOT_EXIST; import static seedu.address.logic.parser.CliSyntax.PREFIX_CLASSCODE; import static seedu.address.logic.parser.CliSyntax.PREFIX_GROUPNUMBER; import static seedu.address.logic.parser.CliSyntax.PREFIX_TYPE; @@ -16,8 +17,8 @@ public class AddGroupCommand extends Command { public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a group to a class to Classmate. " + "Parameters: " + PREFIX_CLASSCODE + "CLASSCODE " - + PREFIX_GROUPNAME + "GROUPNAME " + PREFIX_TYPE + "TYPE " + + PREFIX_GROUPNUMBER + "GROUPNUMBER " + "Example: " + COMMAND_WORD + " " + PREFIX_GROUPNUMBER + "1 " + PREFIX_CLASSCODE + "G06 " @@ -25,7 +26,6 @@ public class AddGroupCommand extends Command { public static final String MESSAGE_SUCCESS = "New group added: %1$s"; public static final String MESSAGE_DUPLICATE_GROUP = "This group already exists in Classmate"; - public static final String MESSAGE_CLASS_DOES_NOT_EXIST = "The class does not exist in Classmate"; private final TutorialGroup toAdd; private final TutorialClass toAddTutorialClass; diff --git a/src/main/java/seedu/address/logic/commands/ViewGroupCommand.java b/src/main/java/seedu/address/logic/commands/ViewGroupCommand.java index 8b0e9093b7e..feec367db12 100644 --- a/src/main/java/seedu/address/logic/commands/ViewGroupCommand.java +++ b/src/main/java/seedu/address/logic/commands/ViewGroupCommand.java @@ -2,13 +2,15 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_CLASSCODE; -import static seedu.address.logic.parser.CliSyntax.PREFIX_GROUPNAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_GROUPNUMBER; import static seedu.address.logic.parser.CliSyntax.PREFIX_TYPE; import seedu.address.commons.core.Messages; +import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; -import seedu.address.model.student.ClassMemberPredicate; -import seedu.address.model.tutorialgroup.TutorialGroupContainsKeywordsPredicate; +import seedu.address.model.student.GroupMemberPredicate; +import seedu.address.model.tutorialclass.TutorialClass; +import seedu.address.model.tutorialgroup.TutorialGroup; /** * Lists all students in a tutorial group in ClassMATE given a class code, tutorial group type and tutorial group name @@ -23,26 +25,38 @@ public class ViewGroupCommand extends Command { + "with index numbers.\n" + "Parameters: " + PREFIX_CLASSCODE + "CLASSCODE " - + PREFIX_GROUPNAME + "GROUPNAME " + PREFIX_TYPE + "TYPE " + + PREFIX_GROUPNUMBER + "GROUPNUMBER " + "Example: " + COMMAND_WORD + " " - + PREFIX_GROUPNAME + "3 " + + PREFIX_GROUPNUMBER + "3 " + PREFIX_CLASSCODE + "G06 " + PREFIX_TYPE + "OP2 "; - private final TutorialGroupContainsKeywordsPredicate predicate; + private final TutorialGroup toView; + private final TutorialClass toViewTutorialClass; - public ViewGroupCommand(TutorialGroupContainsKeywordsPredicate predicate) { - this.predicate = predicate; + /** + * Creates a ViewGroupCommand to show the students in the specified {@code TutorialGroup} + */ + public ViewGroupCommand(TutorialGroup tutorialGroup) { + requireNonNull(tutorialGroup); + toView = tutorialGroup; + // new class with the same class code created to check whether it exists in ClassMATE + toViewTutorialClass = TutorialClass.createTestTutorialClass(toView.getClassCode()); } @Override - public CommandResult execute(Model model) { + public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - model.updateFilteredTutorialGroupList(predicate); + // check if tutorial class exists in ClassMATE + if (!model.hasTutorialClass(toViewTutorialClass)) { + throw new CommandException(Messages.MESSAGE_CLASS_DOES_NOT_EXIST); + } - model.updateFilteredStudentList(new ClassMemberPredicate(targetClassCode)); + + + model.updateFilteredStudentList(new GroupMemberPredicate(toView)); return new CommandResult( String.format(Messages.MESSAGE_TUTORIAL_GROUP_LISTED_OVERVIEW, model.getFilteredStudentList().size())); @@ -52,6 +66,6 @@ public CommandResult execute(Model model) { public boolean equals(Object other) { return other == this // short circuit if same object || (other instanceof ViewGroupCommand // instanceof handles nulls - && predicate.equals(((ViewGroupCommand) other).predicate)); // state check + && toView.equals(((ViewGroupCommand) other).toView)); // state check } } diff --git a/src/main/java/seedu/address/logic/parser/ClassmateParser.java b/src/main/java/seedu/address/logic/parser/ClassmateParser.java index 879ff4ddbc4..303963d2616 100644 --- a/src/main/java/seedu/address/logic/parser/ClassmateParser.java +++ b/src/main/java/seedu/address/logic/parser/ClassmateParser.java @@ -27,6 +27,7 @@ import seedu.address.logic.commands.ListClassCommand; import seedu.address.logic.commands.ListStudentCommand; import seedu.address.logic.commands.ViewClassCommand; +import seedu.address.logic.commands.ViewGroupCommand; import seedu.address.logic.commands.ViewStudentCommand; import seedu.address.logic.parser.exceptions.ParseException; @@ -97,6 +98,9 @@ public Command parseCommand(String userInput) throws ParseException { case ViewClassCommand.COMMAND_WORD: return new ViewClassCommandParser().parse(arguments); + case ViewGroupCommand.COMMAND_WORD: + return new ViewGroupCommandParser().parse(arguments); + case ViewStudentCommand.COMMAND_WORD: return new ViewStudentCommandParser().parse(arguments); diff --git a/src/main/java/seedu/address/logic/parser/ViewGroupCommandParser.java b/src/main/java/seedu/address/logic/parser/ViewGroupCommandParser.java index cedf492c061..261e22f8f76 100644 --- a/src/main/java/seedu/address/logic/parser/ViewGroupCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/ViewGroupCommandParser.java @@ -1,12 +1,19 @@ package seedu.address.logic.parser; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_CLASSCODE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_GROUPNUMBER; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TYPE; -import java.util.Arrays; +import java.util.stream.Stream; +import seedu.address.logic.commands.AddGroupCommand; import seedu.address.logic.commands.ViewGroupCommand; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.tutorialgroup.TutorialGroupContainsKeywordsPredicate; +import seedu.address.model.student.ClassCode; +import seedu.address.model.tutorialgroup.GroupNumber; +import seedu.address.model.tutorialgroup.GroupType; +import seedu.address.model.tutorialgroup.TutorialGroup; /** * Parses input arguments and creates a new ViewGroupCommand object @@ -19,15 +26,24 @@ public class ViewGroupCommandParser implements Parser { * @throws ParseException if the user input does not conform the expected format */ public ViewGroupCommand parse(String args) throws ParseException { - String trimmedArgs = args.trim(); - if (trimmedArgs.isEmpty()) { - throw new ParseException( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewGroupCommand.MESSAGE_USAGE)); + ArgumentMultimap argMultimap = + ArgumentTokenizer.tokenize(args, PREFIX_CLASSCODE, PREFIX_TYPE, PREFIX_GROUPNUMBER); + + if (!arePrefixesPresent(argMultimap, PREFIX_CLASSCODE, PREFIX_TYPE, PREFIX_GROUPNUMBER) + || !argMultimap.getPreamble().isEmpty()) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddGroupCommand.MESSAGE_USAGE)); } - String[] nameKeywords = trimmedArgs.split("\\s+"); + GroupNumber groupNumber = ParserUtil.parseGroupName(argMultimap.getValue(PREFIX_GROUPNUMBER).get()); + ClassCode classCode = ParserUtil.parseClassCode(argMultimap.getValue(PREFIX_CLASSCODE).get()); + GroupType groupType = ParserUtil.parseGroupType(argMultimap.getValue(PREFIX_TYPE).get()); + + TutorialGroup tutorialGroup = new TutorialGroup(groupNumber, classCode, groupType); - return new ViewGroupCommand(new TutorialGroupContainsKeywordsPredicate(Arrays.asList(nameKeywords))); + return new ViewGroupCommand(tutorialGroup); } + private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { + return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); + } } diff --git a/src/main/java/seedu/address/model/Classmate.java b/src/main/java/seedu/address/model/Classmate.java index a21a3e19dc8..da007a101b3 100644 --- a/src/main/java/seedu/address/model/Classmate.java +++ b/src/main/java/seedu/address/model/Classmate.java @@ -11,6 +11,7 @@ import seedu.address.model.tutorialclass.TutorialClass; import seedu.address.model.tutorialclass.UniqueTutorialClassList; import seedu.address.model.tutorialgroup.TutorialGroup; +import seedu.address.model.tutorialgroup.UniqueTutorialGroupList; /** * Wraps all data at the address-book level @@ -22,6 +23,7 @@ public class Classmate implements ReadOnlyClassmate { private final UniqueStudentList students; private final UniqueTutorialClassList tutorialClasses; + private final UniqueTutorialGroupList tutorialGroups; /* * The 'unusual' code block below is a non-static initialization block, sometimes used to avoid duplication @@ -33,6 +35,7 @@ public class Classmate implements ReadOnlyClassmate { { students = new UniqueStudentList(); tutorialClasses = new UniqueTutorialClassList(); + tutorialGroups = new UniqueTutorialGroupList(); } public Classmate() {} @@ -155,7 +158,7 @@ public void removeTutorialClass(TutorialClass key) { * {@code key} must exist in the ClassMATE. */ public void removeTutorialGroup(TutorialGroup key) { - tutorialClasses.remove(key); + tutorialGroups.remove(key); } /** @@ -163,7 +166,7 @@ public void removeTutorialGroup(TutorialGroup key) { */ public boolean hasTutorialGroup(TutorialGroup tutorialGroup) { requireNonNull(tutorialGroup); - return tutorialClasses.contains(tutorialGroup); + return tutorialGroups.contains(tutorialGroup); } /** @@ -171,14 +174,14 @@ public boolean hasTutorialGroup(TutorialGroup tutorialGroup) { * The tutorial group must not already exist in the ClassMATE. */ public void addTutorialGroup(TutorialGroup tutorialGroup) { - tutorialClasses.add(tutorialGroup); + tutorialGroups.add(tutorialGroup); } /** * Sorts the tutorial groups in ClassMATE. */ public void sortTutorialGroups() { - tutorialClasses.sort(); + tutorialGroups.sort(); } diff --git a/src/main/java/seedu/address/model/student/GroupMemberPredicate.java b/src/main/java/seedu/address/model/student/GroupMemberPredicate.java new file mode 100644 index 00000000000..a802086cee2 --- /dev/null +++ b/src/main/java/seedu/address/model/student/GroupMemberPredicate.java @@ -0,0 +1,32 @@ +package seedu.address.model.student; + +import java.util.function.Predicate; + +import seedu.address.model.tutorialgroup.TutorialGroup; + +/** + * Tests that a {@code Student}'s {@code TutorialGroup} matches the given TutorialGroup. + */ +public class GroupMemberPredicate implements Predicate { + private final TutorialGroup tutorialGroup; + + public GroupMemberPredicate(TutorialGroup tutorialGroup) { + this.tutorialGroup = tutorialGroup; + } + + public TutorialGroup getTutorialGroup() { + return tutorialGroup; + } + + @Override + public boolean test(Student student) { + return student.getTutorialGroups().contains(tutorialGroup); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same instance + || other instanceof GroupMemberPredicate // instanceof handles null + && tutorialGroup.equals(((GroupMemberPredicate) other).getTutorialGroup()); // state check + } +} diff --git a/src/main/java/seedu/address/model/student/GroupNamePredicate.java b/src/main/java/seedu/address/model/student/GroupNamePredicate.java deleted file mode 100644 index cdb72639d63..00000000000 --- a/src/main/java/seedu/address/model/student/GroupNamePredicate.java +++ /dev/null @@ -1,30 +0,0 @@ -package seedu.address.model.student; - -import java.util.function.Predicate; - -/** - * Tests that a {@code Student}'s {@code GroupName} matches the given group name. - */ -public class GroupNamePredicate implements Predicate { - private final ClassCode classCode; - - public GroupNamePredicate(ClassCode classCode) { - this.classCode = classCode; - } - - public ClassCode getClassCode() { - return classCode; - } - - @Override - public boolean test(Student student) { - return student.getClassCode().equals(classCode); - } - - @Override - public boolean equals(Object other) { - return other == this // short circuit if same instance - || other instanceof GroupNamePredicate // instanceof handles null - && classCode.equals(((GroupNamePredicate) other).getClassCode()); // state check - } -} diff --git a/src/main/java/seedu/address/model/student/GroupTypePredicate.java b/src/main/java/seedu/address/model/student/GroupTypePredicate.java deleted file mode 100644 index 1ed5466d7e0..00000000000 --- a/src/main/java/seedu/address/model/student/GroupTypePredicate.java +++ /dev/null @@ -1,32 +0,0 @@ -package seedu.address.model.student; - -import java.util.function.Predicate; - -import seedu.address.model.tutorialgroup.GroupType; - -/** - * Tests that a {@code Student}'s {@code GroupType} matches the given group type. - */ -public class GroupTypePredicate implements Predicate { - private final GroupType groupType; - - public GroupTypePredicate(GroupType groupType) { - this.groupType = groupType; - } - - public GroupType getGroupType() { - return groupType; - } - - @Override - public boolean test(Student student) { - return student.getGroupType().equals(groupType); - } - - @Override - public boolean equals(Object other) { - return other == this // short circuit if same instance - || other instanceof GroupTypePredicate // instanceof handles null - && groupType.equals(((GroupTypePredicate) other).getGroupType()); // state check - } -}