diff --git a/src/main/java/seedu/foodrem/logic/commands/tagcommands/TagCommandUtil.java b/src/main/java/seedu/foodrem/logic/commands/tagcommands/TagCommandUtil.java index e61a0f323b6..7458b1ed5a7 100644 --- a/src/main/java/seedu/foodrem/logic/commands/tagcommands/TagCommandUtil.java +++ b/src/main/java/seedu/foodrem/logic/commands/tagcommands/TagCommandUtil.java @@ -25,6 +25,8 @@ private TagCommandUtil() {} */ public static Item validateAndGetItem(Model model, Tag tag, Index index) throws CommandException { requireNonNull(model); + requireNonNull(tag); + requireNonNull(index); if (!model.hasTag(tag)) { throw new CommandException("This tag does not exist"); diff --git a/src/main/java/seedu/foodrem/logic/parser/tagcommandparser/RenameTagCommandParser.java b/src/main/java/seedu/foodrem/logic/parser/tagcommandparser/RenameTagCommandParser.java index 1a0aa5283ef..fd2343d8452 100644 --- a/src/main/java/seedu/foodrem/logic/parser/tagcommandparser/RenameTagCommandParser.java +++ b/src/main/java/seedu/foodrem/logic/parser/tagcommandparser/RenameTagCommandParser.java @@ -52,6 +52,7 @@ public RenameTagCommand parse(String args) throws ParseException { } private boolean hasExtraPrefixesInName(String name) { + assert name != null; Matcher matcher = CliSyntax.PREFIX_REGEX.matcher(name); return matcher.find(); } diff --git a/src/main/java/seedu/foodrem/logic/parser/tagcommandparser/TagCommandParser.java b/src/main/java/seedu/foodrem/logic/parser/tagcommandparser/TagCommandParser.java index f8cbb62d147..d1741dcec6b 100644 --- a/src/main/java/seedu/foodrem/logic/parser/tagcommandparser/TagCommandParser.java +++ b/src/main/java/seedu/foodrem/logic/parser/tagcommandparser/TagCommandParser.java @@ -2,8 +2,6 @@ import static java.util.Objects.requireNonNull; -import java.util.stream.Stream; - import seedu.foodrem.commons.core.Messages; import seedu.foodrem.commons.core.index.Index; import seedu.foodrem.commons.util.StringUtil; @@ -13,7 +11,6 @@ import seedu.foodrem.logic.parser.CliSyntax; import seedu.foodrem.logic.parser.Parser; import seedu.foodrem.logic.parser.ParserUtil; -import seedu.foodrem.logic.parser.Prefix; import seedu.foodrem.logic.parser.exceptions.ParseException; /** @@ -32,7 +29,7 @@ public TagCommand parse(String args) throws ParseException { Index index = StringUtil.validateAndGetIndexFromString(argMultimap.getPreamble().trim(), TagCommand.getUsage()); - if (!arePrefixesPresent(argMultimap, CliSyntax.PREFIX_NAME) + if (!ParserUtil.arePrefixesPresent(argMultimap, CliSyntax.PREFIX_NAME) || argMultimap.getPreamble().isEmpty()) { throw new ParseException(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, TagCommand.getUsage())); } @@ -42,11 +39,4 @@ public TagCommand parse(String args) throws ParseException { return new TagCommand(name, index); } - /** - * Returns {@code 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()); - } } diff --git a/src/main/java/seedu/foodrem/logic/parser/tagcommandparser/UntagCommandParser.java b/src/main/java/seedu/foodrem/logic/parser/tagcommandparser/UntagCommandParser.java index c4f030c2cc5..a67d3f1bf46 100644 --- a/src/main/java/seedu/foodrem/logic/parser/tagcommandparser/UntagCommandParser.java +++ b/src/main/java/seedu/foodrem/logic/parser/tagcommandparser/UntagCommandParser.java @@ -1,7 +1,6 @@ package seedu.foodrem.logic.parser.tagcommandparser; import static java.util.Objects.requireNonNull; -import static seedu.foodrem.logic.parser.ParserUtil.arePrefixesPresent; import seedu.foodrem.commons.core.Messages; import seedu.foodrem.commons.core.index.Index; @@ -29,7 +28,7 @@ public UntagCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, CliSyntax.PREFIX_NAME); Index index = StringUtil.validateAndGetIndexFromString(argMultimap.getPreamble().trim(), UntagCommand.getUsage()); - if (!arePrefixesPresent(argMultimap, CliSyntax.PREFIX_NAME) + if (!ParserUtil.arePrefixesPresent(argMultimap, CliSyntax.PREFIX_NAME) || argMultimap.getPreamble().isEmpty()) { throw new ParseException(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, UntagCommand.getUsage())); } diff --git a/src/main/java/seedu/foodrem/model/tag/Tag.java b/src/main/java/seedu/foodrem/model/tag/Tag.java index c58672c722f..d8316848811 100644 --- a/src/main/java/seedu/foodrem/model/tag/Tag.java +++ b/src/main/java/seedu/foodrem/model/tag/Tag.java @@ -21,16 +21,22 @@ public Tag(String tagName) { } public String getName() { + assert tagName != null; return this.tagName.toString(); } + /** + * @inheritDoc + */ @Override public boolean equals(Object other) { return other == this || (other instanceof Tag && tagName.equals(((Tag) other).tagName)); } - + /** + * @inheritDoc + */ @Override public int hashCode() { return tagName.hashCode(); diff --git a/src/main/java/seedu/foodrem/model/tag/TagName.java b/src/main/java/seedu/foodrem/model/tag/TagName.java index 225cf84abb6..cb902db693e 100644 --- a/src/main/java/seedu/foodrem/model/tag/TagName.java +++ b/src/main/java/seedu/foodrem/model/tag/TagName.java @@ -37,11 +37,17 @@ public TagName(String name) { fullName = name; } + /** + * @inheritDoc + */ @Override public String toString() { return fullName; } + /** + * @inheritDoc + */ @Override public boolean equals(Object other) { return other == this @@ -49,6 +55,9 @@ public boolean equals(Object other) { && fullName.equals(((TagName) other).fullName)); } + /** + * @inheritDoc + */ @Override public int hashCode() { return fullName.hashCode(); diff --git a/src/main/java/seedu/foodrem/model/tag/TagNameContainsKeywordsPredicate.java b/src/main/java/seedu/foodrem/model/tag/TagNameContainsKeywordsPredicate.java index fdca44606e5..0c7100750e6 100644 --- a/src/main/java/seedu/foodrem/model/tag/TagNameContainsKeywordsPredicate.java +++ b/src/main/java/seedu/foodrem/model/tag/TagNameContainsKeywordsPredicate.java @@ -15,12 +15,21 @@ public TagNameContainsKeywordsPredicate(List keywords) { this.keywords = keywords; } + /** + * Tests whether the keyword is contained in the {@code tag} + * + * @param tag to be tested + * @return boolean stating whether keyword in tag name + */ @Override public boolean test(Tag tag) { return keywords.stream() .anyMatch(keyword -> StringUtil.containsWordIgnoreCase(tag.getName(), keyword)); } + /** + * @inheritDoc + */ @Override public boolean equals(Object other) { return other == this diff --git a/src/main/java/seedu/foodrem/model/tag/exceptions/DuplicateTagException.java b/src/main/java/seedu/foodrem/model/tag/exceptions/DuplicateTagException.java index b8e6f9ae2f6..4ea45fd8d4c 100644 --- a/src/main/java/seedu/foodrem/model/tag/exceptions/DuplicateTagException.java +++ b/src/main/java/seedu/foodrem/model/tag/exceptions/DuplicateTagException.java @@ -5,6 +5,9 @@ * name). */ public class DuplicateTagException extends RuntimeException { + /** + * Creates a new DuplicateTagException + */ public DuplicateTagException() { super("Operation would result in duplicate tags"); }