Skip to content

Commit

Permalink
Merge pull request #132 from Respirayson/branch-viewtasks-prefixes
Browse files Browse the repository at this point in the history
Fix too many prefix for viewtasks bug
  • Loading branch information
Respirayson authored Nov 1, 2023
2 parents 68043db + 94d4a3f commit 1dada23
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Task> predicate;

public ViewTasksCommand(Predicate<Task> predicate) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/seedu/address/logic/parser/ArgumentMultimap.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ public class ArgumentMultimap {
/** Prefixes mapped to their respective arguments**/
private final Map<Prefix, List<String>> 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Task> predicate = PREDICATE_SHOW_ALL_TASKS;

if (argMultimap.getValue(PREFIX_TASK_NAME).isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
}

}

0 comments on commit 1dada23

Please sign in to comment.