Skip to content

Commit

Permalink
Add RemarkCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
SinhaVedant committed Oct 3, 2023
1 parent 32ea83a commit eae4ffe
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/main/java/seedu/address/logic/commands/RemarkCommand.java
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.RemarkCommand;
import seedu.address.logic.parser.exceptions.ParseException;

/**
Expand Down Expand Up @@ -68,6 +69,9 @@ public Command parseCommand(String userInput) throws ParseException {
case FindCommand.COMMAND_WORD:
return new FindCommandParser().parse(arguments);

case RemarkCommand.COMMAND_WORD:
return new RemarkCommandParser().parse(arguments);

case ListCommand.COMMAND_WORD:
return new ListCommand();

Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public class CliSyntax {
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_REMARK = new Prefix("r/");

}
30 changes: 30 additions & 0 deletions src/main/java/seedu/address/logic/parser/RemarkCommandParser.java
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);
}
}

0 comments on commit eae4ffe

Please sign in to comment.