forked from nus-cs2103-AY2021S1/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 nus-cs2103-AY2021S1#65 from Nijnxw/branch-v1.2-vie…
…wlsn Branch v1.2 viewlsn
- Loading branch information
Showing
38 changed files
with
686 additions
and
96 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
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
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
61 changes: 61 additions & 0 deletions
61
src/main/java/seedu/address/logic/commands/ViewLsnCommand.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,61 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRP; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_LSN; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.group.GrpContainsKeywordPredicate; | ||
import seedu.address.model.group.LsnContainsKeywordPredicate; | ||
|
||
/** | ||
* Finds and lists the attendance and class participation of all the students from | ||
* a specified group and lesson. Keyword matching is case insensitive. | ||
*/ | ||
public class ViewLsnCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "viewlsn"; | ||
public static final Object MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Finds the attendance and class participation of all students " | ||
+ "from the specified lesson of a specific group (case-insensitive) and " | ||
+ "displays them as a list with index numbers.\n" | ||
+ "Parameters: GROUP LESSON\n" | ||
+ "Example: " + COMMAND_WORD + " " + PREFIX_GRP + " G04 " + PREFIX_LSN + " 2-2"; | ||
|
||
private final GrpContainsKeywordPredicate grpPredicate; | ||
private final LsnContainsKeywordPredicate lsnPredicate; | ||
|
||
/** | ||
* Creates a ViewLsnCommand to view the specified {@code Lesson} | ||
*/ | ||
public ViewLsnCommand(GrpContainsKeywordPredicate grpPredicate, | ||
LsnContainsKeywordPredicate lsnPredicate) { | ||
this.grpPredicate = grpPredicate; | ||
this.lsnPredicate = lsnPredicate; | ||
} | ||
|
||
private String getMessage(Model model) { | ||
return model.getFilteredGroupList().isEmpty() | ||
? Messages.MESSAGE_LESSON_EMPTY | ||
: String.format(Messages.MESSAGE_LESSON_LISTED_OVERVIEW, | ||
model.getFilteredGroupList().get(0).getName(), | ||
model.getFilteredLessonList().get(0).getName()); | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
requireNonNull(model); | ||
model.updateFilteredLessonList(lsnPredicate); | ||
return new CommandResult(this.getMessage(model)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof ViewLsnCommand // instanceof handles nulls | ||
&& grpPredicate.equals(((ViewLsnCommand) other).grpPredicate)) // state check | ||
&& lsnPredicate.equals(((ViewLsnCommand) other).lsnPredicate); | ||
} | ||
|
||
} |
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
46 changes: 46 additions & 0 deletions
46
src/main/java/seedu/address/logic/parser/ViewLsnCommandParser.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,46 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRP; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_LSN; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import seedu.address.logic.commands.ViewLsnCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.group.GrpContainsKeywordPredicate; | ||
import seedu.address.model.group.LsnContainsKeywordPredicate; | ||
|
||
public class ViewLsnCommandParser implements Parser<ViewLsnCommand> { | ||
|
||
private final ParseException viewLsnCommandParserException = new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewLsnCommand.MESSAGE_USAGE)); | ||
|
||
@Override | ||
public ViewLsnCommand parse(String args) throws ParseException { | ||
|
||
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_GRP, PREFIX_LSN); | ||
|
||
if (!arePrefixesPresent(argMultimap, PREFIX_GRP, PREFIX_LSN) || !argMultimap.getPreamble().isEmpty()) { | ||
throw viewLsnCommandParserException; | ||
} | ||
|
||
String[] grpKeyword = argMultimap.getValue(PREFIX_GRP).get().split("\\s+"); | ||
String[] lsnKeyword = argMultimap.getValue(PREFIX_LSN).get().split("\\s+"); | ||
|
||
if (grpKeyword.length > 1 || lsnKeyword.length > 1) { | ||
throw viewLsnCommandParserException; | ||
} | ||
|
||
return new ViewLsnCommand(new GrpContainsKeywordPredicate(grpKeyword[0]), | ||
new LsnContainsKeywordPredicate(lsnKeyword[0])); | ||
} | ||
|
||
/** | ||
* Returns true if none of the prefixes contains empty {@code Optional} values in the given {@code | ||
* ArgumentMultimap}. | ||
*/ | ||
private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { | ||
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); | ||
} | ||
} |
Oops, something went wrong.