forked from nus-cs2103-AY2122S1/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.
- Loading branch information
Showing
9 changed files
with
265 additions
and
3 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
50 changes: 50 additions & 0 deletions
50
src/main/java/seedu/address/logic/commands/task/ListTaskCommand.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,50 @@ | ||
package seedu.address.logic.commands.task; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.TaskCommand; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.task.filters.TaskFilters.TaskFilter; | ||
|
||
/** | ||
* Completes an existing task in the task list. | ||
*/ | ||
public class ListTaskCommand extends TaskCommand { | ||
public static final String COMMAND_WORD = "list"; | ||
public static final String FULL_COMMAND_WORD = TaskCommand.COMMAND_WORD + " " + COMMAND_WORD; | ||
public static final String MESSAGE_SUCCESS = "Task list updated"; | ||
public static final String MESSAGE_USAGE = FULL_COMMAND_WORD | ||
+ ": Lists tasks matching the given search conditions.\n" | ||
+ "Parameters: t/TAG (tasks containing the tag TAG) " | ||
+ "Example: " + FULL_COMMAND_WORD + " 1"; | ||
|
||
private final List<TaskFilter> taskFilters; | ||
|
||
public ListTaskCommand(List<TaskFilter> taskFilters) { | ||
this.taskFilters = taskFilters; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
model.setTaskFilters(taskFilters); | ||
return new CommandResult(MESSAGE_SUCCESS); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
return this == o | ||
|| (o instanceof ListTaskCommand | ||
&& taskFilters.equals(((ListTaskCommand) o).taskFilters)); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return taskFilters.hashCode(); | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
src/main/java/seedu/address/logic/parser/task/ListTaskCommandParser.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.task; | ||
|
||
import static seedu.address.logic.parser.CliSyntax.PREFIX_DONE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_UNDONE; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import seedu.address.logic.commands.task.ListTaskCommand; | ||
import seedu.address.logic.parser.ArgumentMultimap; | ||
import seedu.address.logic.parser.ArgumentTokenizer; | ||
import seedu.address.logic.parser.Parser; | ||
import seedu.address.logic.parser.ParserUtil; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.tag.Tag; | ||
import seedu.address.model.task.filters.TaskFilters; | ||
import seedu.address.model.task.filters.TaskFilters.TaskFilter; | ||
|
||
public class ListTaskCommandParser implements Parser<ListTaskCommand> { | ||
/** | ||
* Parses the given {@code String} of arguments in the context of the EditTaskCommand | ||
* and returns an EditTaskCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public ListTaskCommand parse(String args) throws ParseException { | ||
ArgumentMultimap argMultimap = | ||
ArgumentTokenizer.tokenize(args, PREFIX_DONE, PREFIX_UNDONE, PREFIX_TAG); | ||
|
||
Set<Tag> tags = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); | ||
List<TaskFilter> taskFilters = tags.stream().map(TaskFilters.FILTER_TAG).collect(Collectors.toList()); | ||
|
||
if (argMultimap.getValue(PREFIX_DONE).isPresent()) { | ||
taskFilters.add(TaskFilters.FILTER_DONE); | ||
} | ||
|
||
if (argMultimap.getValue(PREFIX_UNDONE).isPresent()) { | ||
taskFilters.add(TaskFilters.FILTER_DONE.invert()); | ||
} | ||
|
||
return new ListTaskCommand(taskFilters); | ||
} | ||
} |
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
75 changes: 75 additions & 0 deletions
75
src/test/java/seedu/address/logic/commands/task/ListTaskCommandTest.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.task; | ||
|
||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
import static seedu.address.logic.commands.task.ListTaskCommand.MESSAGE_SUCCESS; | ||
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; | ||
import static seedu.address.testutil.TypicalTasks.getTypicalTaskList; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.logic.commands.Command; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.UserPrefs; | ||
import seedu.address.model.tag.Tag; | ||
import seedu.address.model.task.filters.TaskFilters; | ||
import seedu.address.model.task.filters.TaskFilters.TaskFilter; | ||
|
||
public class ListTaskCommandTest { | ||
private final Model model = new ModelManager(getTypicalAddressBook(), getTypicalTaskList(), new UserPrefs()); | ||
|
||
@Test | ||
void execute_noFilter_showsEntireList() { | ||
Command command = new ListTaskCommand(new ArrayList<>()); | ||
Model expectedModel = ModelManager.from(model); | ||
expectedModel.setTaskFilters(new ArrayList<>()); | ||
|
||
assertCommandSuccess(command, model, MESSAGE_SUCCESS, expectedModel); | ||
} | ||
|
||
@Test | ||
void execute_tagsFilter_showsTasksWithTag() { | ||
Tag tag = new Tag("important"); | ||
List<TaskFilter> taskFilters = List.of(TaskFilters.FILTER_TAG.apply(tag)); | ||
Command command = new ListTaskCommand(taskFilters); | ||
Model expectedModel = ModelManager.from(model); | ||
expectedModel.setTaskFilters(taskFilters); | ||
|
||
assertCommandSuccess(command, model, MESSAGE_SUCCESS, expectedModel); | ||
} | ||
|
||
@Test | ||
void execute_multipleFilters_showsCorrectTasks() { | ||
Tag tag = new Tag("important"); | ||
List<TaskFilter> taskFilters = List.of( | ||
TaskFilters.FILTER_TAG.apply(tag), | ||
TaskFilters.FILTER_DONE | ||
); | ||
Command command = new ListTaskCommand(taskFilters); | ||
Model expectedModel = ModelManager.from(model); | ||
expectedModel.setTaskFilters(taskFilters); | ||
|
||
assertCommandSuccess(command, model, MESSAGE_SUCCESS, expectedModel); | ||
} | ||
|
||
@Test | ||
void execute_filterThenClear_showsAllTasks() { | ||
Tag tag = new Tag("important"); | ||
List<TaskFilter> taskFilters = List.of( | ||
TaskFilters.FILTER_TAG.apply(tag), | ||
TaskFilters.FILTER_DONE | ||
); | ||
Command command = new ListTaskCommand(taskFilters); | ||
Model expectedModel = ModelManager.from(model); | ||
|
||
expectedModel.setTaskFilters(taskFilters); | ||
assertCommandSuccess(command, model, MESSAGE_SUCCESS, expectedModel); | ||
|
||
Command clearCommand = new ListTaskCommand(List.of()); | ||
expectedModel.setTaskFilters(List.of()); | ||
assertCommandSuccess(clearCommand, model, MESSAGE_SUCCESS, expectedModel); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/test/java/seedu/address/logic/parser/task/ListTaskCommandParserTest.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.task; | ||
|
||
import static seedu.address.logic.parser.CliSyntax.PREFIX_DONE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_UNDONE; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.logic.commands.task.ListTaskCommand; | ||
import seedu.address.model.tag.Tag; | ||
import seedu.address.model.task.filters.TaskFilters; | ||
import seedu.address.model.task.filters.TaskFilters.TaskFilter; | ||
|
||
public class ListTaskCommandParserTest { | ||
private final ListTaskCommandParser parser = new ListTaskCommandParser(); | ||
@Test | ||
void parse_emptyArguments_noTaskFilters() { | ||
assertParseSuccess(parser, "", new ListTaskCommand(new ArrayList<>())); | ||
} | ||
|
||
@Test | ||
void parse_showDone_showDoneTasks() { | ||
assertParseSuccess(parser, " " + PREFIX_DONE, new ListTaskCommand(List.of(TaskFilters.FILTER_DONE))); | ||
} | ||
|
||
@Test | ||
void parse_showUndone_showUndoneTasks() { | ||
assertParseSuccess(parser, " " + PREFIX_UNDONE, new ListTaskCommand(List.of(TaskFilters.FILTER_DONE.invert()))); | ||
} | ||
|
||
@Test | ||
void parse_showTag_showTaggedTasks() { | ||
String tagName = "important"; | ||
Tag tag = new Tag(tagName); | ||
List<TaskFilter> taskFilters = List.of(TaskFilters.FILTER_TAG.apply(tag)); | ||
assertParseSuccess(parser, " " + PREFIX_TAG + tagName, | ||
new ListTaskCommand(taskFilters)); | ||
} | ||
} |
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