diff --git a/src/main/java/seedu/address/logic/commands/ViewTasksCommand.java b/src/main/java/seedu/address/logic/commands/ViewTasksCommand.java index d125c759205..16afb751583 100644 --- a/src/main/java/seedu/address/logic/commands/ViewTasksCommand.java +++ b/src/main/java/seedu/address/logic/commands/ViewTasksCommand.java @@ -32,6 +32,8 @@ public class ViewTasksCommand extends Command { + "[" + PREFIX_TASK_PROGRESS + "pending] " + "[" + PREFIX_DATE + "22/10/2023] "; + public static final String MESSAGE_MANY_PREFIXES = "Too many prefixes given."; + private final Predicate predicate; public ViewTasksCommand(Predicate predicate) { diff --git a/src/main/java/seedu/address/logic/parser/ArgumentMultimap.java b/src/main/java/seedu/address/logic/parser/ArgumentMultimap.java index 21e26887a83..70802ca3c31 100644 --- a/src/main/java/seedu/address/logic/parser/ArgumentMultimap.java +++ b/src/main/java/seedu/address/logic/parser/ArgumentMultimap.java @@ -22,6 +22,16 @@ public class ArgumentMultimap { /** Prefixes mapped to their respective arguments**/ private final Map> argMultimap = new HashMap<>(); + /** + * Returns the count of unique prefixes in the argument multimap. + * + * @return The number of unique prefixes in the argument multimap. + */ + public int getCountOfPrefixes() { + return argMultimap.size(); + } + + /** * Associates the specified argument value with {@code prefix} key in this map. * If the map previously contained a mapping for the key, the new value is appended to the list of existing values. diff --git a/src/main/java/seedu/address/logic/parser/ViewTasksCommandParser.java b/src/main/java/seedu/address/logic/parser/ViewTasksCommandParser.java index ae95e13fe24..9afd2d64c4f 100644 --- a/src/main/java/seedu/address/logic/parser/ViewTasksCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/ViewTasksCommandParser.java @@ -1,5 +1,6 @@ package seedu.address.logic.parser; +import static seedu.address.logic.commands.ViewTasksCommand.MESSAGE_MANY_PREFIXES; import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TASK_DESCRIPTION; import static seedu.address.logic.parser.CliSyntax.PREFIX_TASK_NAME; @@ -38,6 +39,10 @@ public ViewTasksCommand parse(String args) throws ParseException { argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_TASK_NAME, PREFIX_TASK_DESCRIPTION, PREFIX_TASK_PRIORITY, PREFIX_TASK_PROGRESS, PREFIX_DATE); + if (argMultimap.getCountOfPrefixes() > 2) { + throw new ParseException(MESSAGE_MANY_PREFIXES); + } + Predicate predicate = PREDICATE_SHOW_ALL_TASKS; if (argMultimap.getValue(PREFIX_TASK_NAME).isPresent()) { diff --git a/src/test/java/seedu/address/logic/parser/ViewTasksCommandParserTest.java b/src/test/java/seedu/address/logic/parser/ViewTasksCommandParserTest.java index 9a8cb65cbf3..6a84d8ed414 100644 --- a/src/test/java/seedu/address/logic/parser/ViewTasksCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/ViewTasksCommandParserTest.java @@ -1,10 +1,14 @@ package seedu.address.logic.parser; +import static seedu.address.logic.commands.CommandTestUtil.TASK_DESCRIPTION_TASK2; +import static seedu.address.logic.commands.CommandTestUtil.TASK_PRIORITY_TASK1; +import static seedu.address.logic.commands.ViewTasksCommand.MESSAGE_MANY_PREFIXES; import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TASK_DESCRIPTION; import static seedu.address.logic.parser.CliSyntax.PREFIX_TASK_NAME; import static seedu.address.logic.parser.CliSyntax.PREFIX_TASK_PRIORITY; import static seedu.address.logic.parser.CliSyntax.PREFIX_TASK_PROGRESS; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_TASKS; @@ -84,4 +88,9 @@ public void parse_validDateArgs_returnsViewTasksCommand() { assertParseSuccess(parser, " " + PREFIX_DATE + "22/10/2023 \n \t", expectedCommand); } + @Test + public void parse_manyPrefixes_throwsParseException() { + assertParseFailure(parser, TASK_DESCRIPTION_TASK2 + TASK_PRIORITY_TASK1, MESSAGE_MANY_PREFIXES); + } + }