forked from nus-cs2103-AY2122S2/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.
Merge branch 'master' into sort-by-priority
- Loading branch information
Showing
15 changed files
with
514 additions
and
22 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
82 changes: 82 additions & 0 deletions
82
src/main/java/seedu/address/logic/commands/DeleteTagCommand.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,82 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* Adds a person to the address book. | ||
*/ | ||
public class DeleteTagCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "deleteTag"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Delete a tag " | ||
+ "(identified by the tag's index number) " | ||
+ "of the person identified " | ||
+ "by the index number used in the displayed person list. " | ||
+ "Only one tag can be deleted at a time. " | ||
+ "Parameters: PERSON_INDEX (must be a positive integer) " | ||
+ "TAG_INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + "3 " + "2"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Deleted tag in Person: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book"; | ||
|
||
private final Index index; | ||
private final int tagNumber; | ||
|
||
/** | ||
* Creates an AddTagCommand to add the specified {@code Tag} | ||
* | ||
* @param index of the person in the filtered person list to edit | ||
* @param tagNumber of the tag to be deleted | ||
*/ | ||
public DeleteTagCommand(Index index, int tagNumber) { | ||
requireNonNull(index); | ||
this.index = index; | ||
this.tagNumber = tagNumber; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Person> lastShownList = model.getFilteredPersonList(); | ||
|
||
if (index.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Person personToEdit = lastShownList.get(index.getZeroBased()); | ||
Person tagAddedPerson = deleteTagFromPerson(personToEdit, tagNumber); | ||
|
||
model.setPerson(personToEdit, tagAddedPerson); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, tagAddedPerson.getName())); | ||
} | ||
|
||
private Person deleteTagFromPerson(Person personToEdit, int tagNumber) { | ||
Person newPerson = Person.copyPerson(personToEdit); | ||
ArrayList<Tag> tagList = newPerson.getTags(); | ||
tagList.remove(tagNumber - 1); | ||
|
||
newPerson.setTags(tagList); | ||
return newPerson; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof DeleteTagCommand // instanceof handles nulls | ||
&& tagNumber == ((DeleteTagCommand) other).tagNumber); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
src/main/java/seedu/address/logic/commands/EditTagCommand.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,93 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* Adds a person to the address book. | ||
*/ | ||
public class EditTagCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "editTag"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edit a tag " | ||
+ "(identified by the tag's index number) " | ||
+ "of the person identified " | ||
+ "by the index number used in the displayed person list. " | ||
+ "Only one tag can edited at a time. " | ||
+ "Parameters: PERSON_INDEX (must be a positive integer) " | ||
+ "TAG_INDEX (must be a positive integer) " | ||
+ "TAG\n" | ||
+ "Example: " + COMMAND_WORD + "1 " + "2 " | ||
+ "owesMoney :p2"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Edited tag in Person: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book"; | ||
|
||
private final Index index; | ||
private final int tagNumber; | ||
private final Tag toAdd; | ||
|
||
/** | ||
* Creates an EditTagCommand to replace the tag in the index with the specified {@code Tag} | ||
* | ||
* @param index of the person in the filtered person list to edit | ||
* @param tagNumber of the person's tag list to edit | ||
* @param tag to be added to the person identified | ||
*/ | ||
public EditTagCommand(Index index, int tagNumber, Tag tag) { | ||
requireNonNull(index); | ||
requireNonNull(tag); | ||
this.index = index; | ||
this.tagNumber = tagNumber; | ||
toAdd = tag; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Person> lastShownList = model.getFilteredPersonList(); | ||
|
||
if (index.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Person personToEdit = lastShownList.get(index.getZeroBased()); | ||
Person tagAddedPerson = editTagOfPerson(personToEdit, tagNumber, toAdd); | ||
|
||
model.setPerson(personToEdit, tagAddedPerson); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, tagAddedPerson.getName())); | ||
} | ||
|
||
private Person editTagOfPerson(Person personToEdit, int tagNumber, Tag tag) { | ||
Person newPerson = Person.copyPerson(personToEdit); | ||
ArrayList<Tag> tagList = newPerson.getTags(); | ||
tagList.set(tagNumber - 1, tag); // add exception later | ||
|
||
newPerson.setTags(tagList); | ||
return newPerson; | ||
} | ||
|
||
public Tag getToAdd() { | ||
return toAdd; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof EditTagCommand // instanceof handles nulls | ||
&& tagNumber == ((EditTagCommand) other).tagNumber | ||
&& toAdd.equals(((EditTagCommand) other).toAdd)); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/seedu/address/logic/commands/RedoCommand.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,24 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
|
||
/** | ||
* Lists all persons in the address book to the user. | ||
*/ | ||
public class RedoCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "redo"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Command redone"; | ||
|
||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
model.redoCommand(); | ||
return new CommandResult(MESSAGE_SUCCESS); | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
src/main/java/seedu/address/logic/parser/DeleteTagCommandParser.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,39 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import javafx.util.Pair; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.DeleteTagCommand; | ||
import seedu.address.logic.commands.EditCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new AddCommand object | ||
*/ | ||
public class DeleteTagCommandParser implements Parser<DeleteTagCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the DeleteCommand | ||
* and returns an AddCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public DeleteTagCommand parse(String args) throws ParseException { | ||
ArgumentMultimap argMultimap = | ||
ArgumentTokenizer.tokenize(args); | ||
Pair<Index, String> userInputs; | ||
Pair<Integer, String> trimOutNumber; | ||
|
||
try { | ||
userInputs = ParserUtil.parseOutIndex(argMultimap.getPreamble()); | ||
trimOutNumber = ParserUtil.parseOutNumber(userInputs.getValue()); | ||
} catch (ParseException pe) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe); | ||
} | ||
|
||
Index index = userInputs.getKey(); | ||
Integer tagNumber = trimOutNumber.getKey(); | ||
return new DeleteTagCommand(index, tagNumber); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/seedu/address/logic/parser/EditTagCommandParser.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,41 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import javafx.util.Pair; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.EditCommand; | ||
import seedu.address.logic.commands.EditTagCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* Parses input arguments and creates a new AddCommand object | ||
*/ | ||
public class EditTagCommandParser implements Parser<EditTagCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the EditCommand | ||
* and returns an EditCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public EditTagCommand parse(String args) throws ParseException { | ||
ArgumentMultimap argMultimap = | ||
ArgumentTokenizer.tokenize(args); | ||
Pair<Index, String> userInputs; | ||
Pair<Integer, String> trimOutNumber; | ||
|
||
try { | ||
userInputs = ParserUtil.parseOutIndex(argMultimap.getPreamble()); | ||
trimOutNumber = ParserUtil.parseOutNumber(userInputs.getValue()); | ||
} catch (ParseException pe) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe); | ||
} | ||
|
||
Index index = userInputs.getKey(); | ||
Integer tagNumber = trimOutNumber.getKey(); | ||
Tag tag = ParserUtil.parseTag(trimOutNumber.getValue()); | ||
return new EditTagCommand(index, tagNumber, tag); | ||
} | ||
|
||
} |
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
Oops, something went wrong.