forked from nus-cs2103-AY2425S1/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 pull request #72 from HanB1n/branch-tagging
Update Feature Tagging
- Loading branch information
Showing
40 changed files
with
1,332 additions
and
43 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
71 changes: 71 additions & 0 deletions
71
src/main/java/seedu/address/logic/commands/CreateTagCommand.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,71 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* Adds a tag to the address book. | ||
*/ | ||
public class CreateTagCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "create-tag"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Creates a tag in the address book. " | ||
+ "Parameters: " | ||
+ PREFIX_TAG + "TAG\n" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_TAG + "florist"; | ||
|
||
public static final String MESSAGE_SUCCESS = "New tag added: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_TAG = "This tag already exists in the address book"; | ||
|
||
private final Tag toAdd; | ||
|
||
/** | ||
* Creates an CreateTagCommand to add the specified {@code Tag} | ||
*/ | ||
public CreateTagCommand(Tag tag) { | ||
requireNonNull(tag); | ||
toAdd = tag; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
if (model.hasTag(toAdd)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_TAG); | ||
} | ||
|
||
model.addTag(toAdd); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd))); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof CreateTagCommand)) { | ||
return false; | ||
} | ||
|
||
CreateTagCommand otherCreateTagCommand = (CreateTagCommand) other; | ||
return toAdd.equals(otherCreateTagCommand.toAdd); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("toAdd", toAdd) | ||
.toString(); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
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,75 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* Deletes a person identified using it's displayed index from the address book. | ||
*/ | ||
public class DeleteTagCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "delete-tag"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Deletes the tag identified by the tag name.\n" | ||
+ "Parameters: TAG_NAME (must exists in the AddressBook)\n" | ||
+ "Example: " + COMMAND_WORD + " florist"; | ||
|
||
public static final String MESSAGE_DELETE_TAG_SUCCESS = "Deleted Tag: %1$s"; | ||
public static final String MESSAGE_DELETE_TAG_FAILURE_STILL_TAGGED = "The Tag: %1$s is still used"; | ||
public static final String MESSAGE_DELETE_TAG_FAILURE_NOT_FOUND = "The Tag: %1$s does not exist"; | ||
|
||
private final Tag targetTag; | ||
|
||
public DeleteTagCommand(Tag targetTag) { | ||
this.targetTag = targetTag; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Tag> allTags = model.getFilteredTagList(); | ||
|
||
for (Tag tag : allTags) { | ||
if (tag.getTagName().equals(targetTag.getTagName())) { | ||
if (tag.canBeDeleted()) { | ||
model.deleteTag(tag); | ||
return new CommandResult(String.format(MESSAGE_DELETE_TAG_SUCCESS, Messages.format(targetTag))); | ||
} else { | ||
throw new CommandException( | ||
String.format(MESSAGE_DELETE_TAG_FAILURE_STILL_TAGGED, Messages.format(targetTag))); | ||
} | ||
} | ||
} | ||
throw new CommandException(String.format(MESSAGE_DELETE_TAG_FAILURE_NOT_FOUND, Messages.format(targetTag))); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof DeleteTagCommand)) { | ||
return false; | ||
} | ||
|
||
DeleteTagCommand otherDeleteTagCommand = (DeleteTagCommand) other; | ||
return targetTag.equals(otherDeleteTagCommand.targetTag); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("targetTag", targetTag) | ||
.toString(); | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
src/main/java/seedu/address/logic/parser/CreateTagCommandParser.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,44 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import seedu.address.logic.commands.CreateTagCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* Parses input arguments and creates a new AddCommand object | ||
*/ | ||
public class CreateTagCommandParser implements Parser<CreateTagCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the AddCommand | ||
* and returns an AddCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public CreateTagCommand parse(String args) throws ParseException { | ||
ArgumentMultimap argMultimap = | ||
ArgumentTokenizer.tokenize(args, PREFIX_TAG); | ||
|
||
if (!arePrefixesPresent(argMultimap, PREFIX_TAG) | ||
|| !argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, CreateTagCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_TAG); | ||
Tag tag = ParserUtil.parseTag(argMultimap.getValue(PREFIX_TAG).get()); | ||
return new CreateTagCommand(tag); | ||
} | ||
|
||
/** | ||
* 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()); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
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,43 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import seedu.address.logic.commands.DeleteTagCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* Parses input arguments and creates a new DeleteTagCommand object | ||
*/ | ||
public class DeleteTagCommandParser implements Parser<DeleteTagCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the DeleteCommand | ||
* and returns a DeleteCommand 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, PREFIX_TAG); | ||
|
||
if (!arePrefixesPresent(argMultimap, PREFIX_TAG) | ||
|| !argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteTagCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_TAG); | ||
Tag tag = ParserUtil.parseTag(argMultimap.getValue(PREFIX_TAG).get()); | ||
return new DeleteTagCommand(tag); | ||
} | ||
|
||
/** | ||
* 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()); | ||
} | ||
} |
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.