forked from AY2324S2-CS2103T-T09-4/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from AY2324S2-CS2103T-T09-4/master
Update
- Loading branch information
Showing
16 changed files
with
465 additions
and
48 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
src/main/java/seedu/address/logic/commands/ListStudentsOfClassCommand.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,72 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_MODULECODE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TUTORIALCLASS; | ||
|
||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.module.ModuleCode; | ||
import seedu.address.model.module.TutorialClass; | ||
|
||
/** | ||
* A command to list all students of a particular tutorial class. | ||
*/ | ||
public class ListStudentsOfClassCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "/class_list_students"; | ||
public static final String MESSAGE_STUDENT_LIST_EMPTY = "No students found in the specified tutorial class"; | ||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": List students of the tutorial class. \n" | ||
+ "Parameters: " | ||
+ PREFIX_MODULECODE + "MODULE CODE " | ||
+ PREFIX_TUTORIALCLASS + "TUTORIAL CLASS " | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_MODULECODE + "CS2103T " | ||
+ PREFIX_TUTORIALCLASS + "T09 "; | ||
|
||
private final ModuleCode module; | ||
private final TutorialClass tutorialClass; | ||
|
||
/** | ||
* Creates a ListStudentsCommand to list students of the specified tutorial class. | ||
* | ||
* @param module The module code. | ||
* @param tutorialClass The tutorial class. | ||
*/ | ||
public ListStudentsOfClassCommand(ModuleCode module, TutorialClass tutorialClass) { | ||
requireNonNull(module); | ||
this.module = module; | ||
this.tutorialClass = tutorialClass; | ||
} | ||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
ModuleCode existingModule = model.findModuleFromList(module); | ||
if (existingModule == null || !existingModule.hasTutorialClass(tutorialClass)) { | ||
return new CommandResult(String.format("Module %s or tutorial class %s not found", | ||
module, tutorialClass, MESSAGE_STUDENT_LIST_EMPTY)); | ||
} | ||
TutorialClass existingTutorialClass = model.findTutorialClassFromList(tutorialClass, module); | ||
if (existingTutorialClass.getStudents().isEmpty()) { | ||
return new CommandResult(MESSAGE_STUDENT_LIST_EMPTY); | ||
} | ||
|
||
StringBuilder result = new StringBuilder(); | ||
result.append("Module: ").append(module).append(", Tutorial Class: ") | ||
.append(tutorialClass).append("\nStudents: "); | ||
existingTutorialClass.getStudents().forEach(student -> result.append(student.getName()).append(", ")); | ||
return new CommandResult(result.toString().trim()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
if (!(other instanceof ListStudentsOfClassCommand)) { | ||
return false; | ||
} | ||
ListStudentsOfClassCommand command = (ListStudentsOfClassCommand) other; | ||
return module.equals(command.module) && tutorialClass.equals(command.tutorialClass); | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
src/main/java/seedu/address/logic/parser/ListStudentsOfClassCommandParser.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,53 @@ | ||
package seedu.address.logic.parser; | ||
|
||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_MODULECODE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TUTORIALCLASS; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import seedu.address.logic.commands.ListStudentsOfClassCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.module.ModuleCode; | ||
import seedu.address.model.module.TutorialClass; | ||
|
||
|
||
/** | ||
* Parses input arguments and creates a new ListStudentsCommand object. | ||
*/ | ||
public class ListStudentsOfClassCommandParser implements Parser<ListStudentsOfClassCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the ListStudentsCommand | ||
* and returns a ListStudentsCommand object for execution. | ||
* | ||
* @param args String containing the arguments. | ||
* @return ListStudentsCommand object representing the command. | ||
* @throws ParseException if the user input does not conform to the expected format. | ||
*/ | ||
public ListStudentsOfClassCommand parse(String args) throws ParseException { | ||
ArgumentMultimap argMultimap = | ||
ArgumentTokenizer.tokenize(args, PREFIX_MODULECODE, PREFIX_TUTORIALCLASS); | ||
|
||
if (!arePrefixesPresent(argMultimap, PREFIX_MODULECODE, PREFIX_TUTORIALCLASS) | ||
|| !argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
ListStudentsOfClassCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_MODULECODE, PREFIX_TUTORIALCLASS); | ||
ModuleCode module = ParserUtil.parseModuleCode(argMultimap.getValue(PREFIX_MODULECODE).get()); | ||
TutorialClass tutorialClass = ParserUtil.parseTutorialClass(argMultimap.getValue(PREFIX_TUTORIALCLASS).get()); | ||
|
||
return new ListStudentsOfClassCommand(module, tutorialClass); | ||
} | ||
|
||
/** | ||
* Returns true if all the prefixes contain non-empty values in the given {@code ArgumentMultimap}. | ||
*/ | ||
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.