-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from GabrielWLM/add-view-group-command
Add view group command
- Loading branch information
Showing
12 changed files
with
211 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/java/seedu/address/logic/commands/ViewGroupCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
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_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.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 | ||
* Keyword matching is case-insensitive. | ||
*/ | ||
public class ViewGroupCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "viewg"; | ||
|
||
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 + "CLASSCODE " | ||
+ PREFIX_TYPE + "TYPE " | ||
+ PREFIX_GROUPNUMBER + "GROUPNUMBER " | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_GROUPNUMBER + "3 " | ||
+ PREFIX_CLASSCODE + "G06 " | ||
+ PREFIX_TYPE + "OP2 "; | ||
|
||
private final TutorialGroup toView; | ||
private final TutorialClass toViewTutorialClass; | ||
|
||
/** | ||
* 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) throws CommandException { | ||
requireNonNull(model); | ||
|
||
// check if tutorial class exists in ClassMATE | ||
if (!model.hasTutorialClass(toViewTutorialClass)) { | ||
throw new CommandException(Messages.MESSAGE_CLASS_DOES_NOT_EXIST); | ||
} | ||
|
||
|
||
|
||
model.updateFilteredStudentList(new GroupMemberPredicate(toView)); | ||
return new CommandResult( | ||
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 ViewGroupCommand // instanceof handles nulls | ||
&& toView.equals(((ViewGroupCommand) other).toView)); // state check | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/seedu/address/logic/parser/ViewGroupCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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.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.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 | ||
*/ | ||
public class ViewGroupCommandParser implements Parser<ViewGroupCommand> { | ||
|
||
/** | ||
* 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 { | ||
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)); | ||
} | ||
|
||
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(tutorialGroup); | ||
} | ||
|
||
private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { | ||
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/seedu/address/model/student/GroupMemberPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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<Student> { | ||
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/seedu/address/model/tutorialgroup/TutorialGroupContainsKeywordsPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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<TutorialGroup> { | ||
private final List<String> keywords; | ||
|
||
public TutorialGroupContainsKeywordsPredicate(List<String> 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 | ||
} | ||
|
||
} |