From b3587e1d53e7a875c71596d14feac9634913d4af Mon Sep 17 00:00:00 2001 From: Eugenetanwl3881 Date: Sun, 6 Nov 2022 18:22:23 +0800 Subject: [PATCH 1/5] Add more assertions --- .../foodrem/logic/commands/tagcommands/TagCommandUtil.java | 2 ++ .../logic/parser/tagcommandparser/RenameTagCommandParser.java | 1 + 2 files changed, 3 insertions(+) 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(); } From 36ac9746682f230be177331d9cd4529b39b4ced2 Mon Sep 17 00:00:00 2001 From: Eugenetanwl3881 Date: Sun, 6 Nov 2022 18:22:41 +0800 Subject: [PATCH 2/5] Remove duplicated code --- .../parser/tagcommandparser/TagCommandParser.java | 12 +----------- .../parser/tagcommandparser/UntagCommandParser.java | 3 +-- 2 files changed, 2 insertions(+), 13 deletions(-) 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())); } From a63bf0c36838d15afb5581e065b69c60d5c42531 Mon Sep 17 00:00:00 2001 From: Eugenetanwl3881 Date: Sun, 6 Nov 2022 18:22:59 +0800 Subject: [PATCH 3/5] Add assertions in Tag class --- src/main/java/seedu/foodrem/model/tag/Tag.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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(); From 0dd22f1d546895df3887c6d9058d52d9b54cf5ad Mon Sep 17 00:00:00 2001 From: Eugenetanwl3881 Date: Sun, 6 Nov 2022 18:23:15 +0800 Subject: [PATCH 4/5] Add some missing JavaDocs --- .../model/tag/TagNameContainsKeywordsPredicate.java | 9 +++++++++ .../model/tag/exceptions/DuplicateTagException.java | 3 +++ 2 files changed, 12 insertions(+) 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"); } From 93839299deeb7e88d1296ac0cc5a96ba9e756565 Mon Sep 17 00:00:00 2001 From: Eugenetanwl3881 Date: Sun, 6 Nov 2022 18:23:41 +0800 Subject: [PATCH 5/5] inheritDoc JavaDocs for certain public methods --- src/main/java/seedu/foodrem/model/tag/TagName.java | 9 +++++++++ 1 file changed, 9 insertions(+) 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();