forked from AY2425S1-CS2103T-T11-2/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 branch 'master' into branch-updateDeveloperGuide
- Loading branch information
Showing
32 changed files
with
832 additions
and
45 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
99 changes: 99 additions & 0 deletions
99
src/main/java/seedu/address/logic/commands/MarkCommand.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,99 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_NAME; | ||
import static seedu.address.logic.Messages.MESSAGE_MARK_ALREADY_SUCCESS; | ||
import static seedu.address.logic.Messages.MESSAGE_MARK_SUCCESS; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_WEEK; | ||
|
||
import java.util.HashSet; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Name; | ||
import seedu.address.model.person.Person; | ||
|
||
/** | ||
* Marks a specific student as present for that particular week. | ||
*/ | ||
public class MarkCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "mark"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Marks the name as present for that particular " | ||
+ "week. The max week number is 13.\n " | ||
+ "Parameters: " + PREFIX_NAME + "NAME " + PREFIX_WEEK + "WEEK NUMBER " | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_NAME + "John Doe " | ||
+ PREFIX_WEEK + "1"; | ||
|
||
public final int week; | ||
private final Name name; | ||
|
||
/** | ||
* Constuctor for MarkCommand. | ||
* | ||
* @param name the name of the student to be marked | ||
* @param week the week number in which the student is being marked as present | ||
*/ | ||
public MarkCommand(Name name, int week) { | ||
this.name = name; | ||
this.week = week; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
Optional<Person> optionalPersonToMark = model.getPerson(name); | ||
if (!optionalPersonToMark.isPresent()) { | ||
throw new CommandException(String.format(MESSAGE_INVALID_PERSON_DISPLAYED_NAME, name)); | ||
} | ||
|
||
Person personToMark = optionalPersonToMark.get(); | ||
Set<Integer> updatedWeeksPresent = new HashSet<>(personToMark.getWeeksPresent()); | ||
|
||
if (!updatedWeeksPresent.add(week)) { | ||
return new CommandResult(String.format(MESSAGE_MARK_ALREADY_SUCCESS, name, week)); | ||
} | ||
|
||
Person updatedPerson = new Person( | ||
personToMark.getName(), | ||
personToMark.getPhone(), | ||
personToMark.getAddress(), | ||
personToMark.getEmail(), | ||
personToMark.getTelegram(), | ||
personToMark.getGithub(), | ||
personToMark.getAssignment(), | ||
updatedWeeksPresent, // Updated weeks present | ||
personToMark.getTags()); | ||
|
||
model.setPerson(personToMark, updatedPerson); | ||
|
||
return new CommandResult(String.format(MESSAGE_MARK_SUCCESS, name, week)); | ||
|
||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof MarkCommand)) { | ||
return false; | ||
} | ||
|
||
MarkCommand otherMarkCommand = (MarkCommand) other; | ||
return name.equals(otherMarkCommand.name) && week == otherMarkCommand.week; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("MarkCommand{name=%s, week=%d}", name, week); | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
src/main/java/seedu/address/logic/commands/UnmarkCommand.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,99 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_NAME; | ||
import static seedu.address.logic.Messages.MESSAGE_UNMARK_ALREADY_SUCCESS; | ||
import static seedu.address.logic.Messages.MESSAGE_UNMARK_SUCCESS; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_WEEK; | ||
|
||
import java.util.HashSet; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Name; | ||
import seedu.address.model.person.Person; | ||
|
||
/** | ||
* Unmarks a specific student as present for that particular week. | ||
* Marks the student as absent. | ||
*/ | ||
public class UnmarkCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "unmark"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Unmarks the name as present for that particular " | ||
+ "week.\n " | ||
+ "Parameters: " + PREFIX_NAME + "NAME" + PREFIX_WEEK + "WEEK NUMBER" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_NAME + "John Doe " | ||
+ PREFIX_WEEK + "1"; | ||
|
||
public final int week; | ||
private final Name name; | ||
|
||
/** | ||
* Constuctor for UnmarkCommand. | ||
* | ||
* @param name the name of the student to be unmarked | ||
* @param week the week number | ||
*/ | ||
public UnmarkCommand(Name name, int week) { | ||
this.name = name; | ||
this.week = week; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
Optional<Person> optionalPersonToUnmark = model.getPerson(name); | ||
if (!optionalPersonToUnmark.isPresent()) { | ||
throw new CommandException(String.format(MESSAGE_INVALID_PERSON_DISPLAYED_NAME, name)); | ||
} | ||
|
||
Person personToUnmark = optionalPersonToUnmark.get(); | ||
Set<Integer> updatedWeeksPresent = new HashSet<>(personToUnmark.getWeeksPresent()); | ||
|
||
if (!updatedWeeksPresent.remove(week)) { | ||
return new CommandResult(String.format(MESSAGE_UNMARK_ALREADY_SUCCESS, name, week)); | ||
} | ||
|
||
Person updatedPerson = new Person( | ||
personToUnmark.getName(), | ||
personToUnmark.getPhone(), | ||
personToUnmark.getAddress(), | ||
personToUnmark.getEmail(), | ||
personToUnmark.getTelegram(), | ||
personToUnmark.getGithub(), | ||
personToUnmark.getAssignment(), | ||
updatedWeeksPresent, // Updated weeks present | ||
personToUnmark.getTags()); | ||
|
||
model.setPerson(personToUnmark, updatedPerson); | ||
|
||
return new CommandResult(String.format(MESSAGE_UNMARK_SUCCESS, name, week)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof UnmarkCommand)) { | ||
return false; | ||
} | ||
|
||
UnmarkCommand otherUnmarkCommand = (UnmarkCommand) other; | ||
return name.equals(otherUnmarkCommand.name) && week == otherUnmarkCommand.week; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("UnmarkCommand{name=%s, week=%d}", name, week); | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
src/main/java/seedu/address/logic/parser/MarkCommandParser.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,45 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_WEEK; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import seedu.address.logic.commands.MarkCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.person.Name; | ||
|
||
/** | ||
* Parses input arguments and creates a new MarkCommand object | ||
*/ | ||
public class MarkCommandParser implements Parser<MarkCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the seedu.address.logic.commands.MarkCommand | ||
* and returns a seedu.address.logic.commands.MarkCommand object for execution. | ||
* | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public MarkCommand parse(String args) throws ParseException { | ||
ArgumentMultimap argumentMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_WEEK); | ||
|
||
if (!arePrefixesPresent(argumentMultimap, PREFIX_NAME, PREFIX_WEEK) | ||
|| !argumentMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, MarkCommand.MESSAGE_USAGE) | ||
); | ||
} | ||
|
||
argumentMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_WEEK); | ||
|
||
Name name = ParserUtil.parseName(argumentMultimap.getValue(PREFIX_NAME).get()); | ||
int week = ParserUtil.parseWeek(argumentMultimap.getValue(PREFIX_WEEK).get()); | ||
|
||
return new MarkCommand(name, week); | ||
} | ||
|
||
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
45 changes: 45 additions & 0 deletions
45
src/main/java/seedu/address/logic/parser/UnmarkCommandParser.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,45 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_WEEK; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import seedu.address.logic.commands.UnmarkCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.person.Name; | ||
|
||
/** | ||
* Parses input arguments and creates a new UnmarkCommand object | ||
*/ | ||
public class UnmarkCommandParser implements Parser<UnmarkCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the seedu.address.logic.commands.UnmarkCommand | ||
* and returns a seedu.address.logic.commands.UnmarkCommand object for execution. | ||
* | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public UnmarkCommand parse(String args) throws ParseException { | ||
ArgumentMultimap argumentMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_WEEK); | ||
|
||
if (!arePrefixesPresent(argumentMultimap, PREFIX_NAME, PREFIX_WEEK) | ||
|| !argumentMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, UnmarkCommand.MESSAGE_USAGE) | ||
); | ||
} | ||
|
||
argumentMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_WEEK); | ||
|
||
Name name = ParserUtil.parseName(argumentMultimap.getValue(PREFIX_NAME).get()); | ||
int week = ParserUtil.parseWeek(argumentMultimap.getValue(PREFIX_WEEK).get()); | ||
|
||
return new UnmarkCommand(name, week); | ||
} | ||
|
||
private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { | ||
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); | ||
} | ||
} |
Oops, something went wrong.