forked from nus-cs2103-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32ea83a
commit eae4ffe
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/main/java/seedu/address/logic/commands/RemarkCommand.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,60 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.model.Model; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; | ||
|
||
/** | ||
* Changes the remark of an existing person in the address book. | ||
*/ | ||
public class RemarkCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "remark"; | ||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Edits the remark of the person identified " | ||
+ "by the index number used in the last person listing. " | ||
+ "Existing remark will be overwritten by the input.\n" | ||
+ "Parameters: INDEX (must be a positive integer) " | ||
+ "r/ [REMARK]\n" | ||
+ "Example: " + COMMAND_WORD + " 1 " | ||
+ "r/ Likes to swim."; | ||
|
||
public static final String MESSAGE_ARGUMENTS = "Index: %1$d, Remark: %2$s"; | ||
|
||
private final Index index; | ||
private final String remark; | ||
|
||
/** | ||
* @param index of the person in the filtered person list to edit the remark | ||
* @param remark of the person to be updated to | ||
*/ | ||
public RemarkCommand(Index index, String remark) { | ||
requireAllNonNull(index, remark); | ||
|
||
this.index = index; | ||
this.remark = remark; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
throw new CommandException( | ||
String.format(MESSAGE_ARGUMENTS, index.getOneBased(), remark)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof RemarkCommand)) { | ||
return false; | ||
} | ||
|
||
RemarkCommand e = (RemarkCommand) other; | ||
return index.equals(e.index) | ||
&& remark.equals(e.remark); | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
src/main/java/seedu/address/logic/parser/RemarkCommandParser.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,30 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.exceptions.IllegalValueException; | ||
import seedu.address.logic.commands.RemarkCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; | ||
|
||
public class RemarkCommandParser implements Parser<RemarkCommand>{ | ||
public RemarkCommand parse(String args) throws ParseException { | ||
requireNonNull(args); | ||
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, | ||
PREFIX_REMARK); | ||
|
||
Index index; | ||
try { | ||
index = ParserUtil.parseIndex(argMultimap.getPreamble()); | ||
} catch (IllegalValueException ive) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
RemarkCommand.MESSAGE_USAGE), ive); | ||
} | ||
|
||
String remark = argMultimap.getValue(PREFIX_REMARK).orElse(""); | ||
|
||
return new RemarkCommand(index, remark); | ||
} | ||
} |