From 9d1550edb6545956156cb0667b1e9fa31132eb23 Mon Sep 17 00:00:00 2001 From: alvintfl Date: Thu, 13 Oct 2022 21:29:03 +0800 Subject: [PATCH 01/11] Fix edit task command not allowing deadlines to be edited Deadlines cannot be edited in edit task command. Let's fix edit task command to allow tasks to be edited. --- .../address/logic/parser/task/EditTaskCommandParser.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/logic/parser/task/EditTaskCommandParser.java b/src/main/java/seedu/address/logic/parser/task/EditTaskCommandParser.java index d74a8cf096c..23602d91f47 100644 --- a/src/main/java/seedu/address/logic/parser/task/EditTaskCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/task/EditTaskCommandParser.java @@ -3,6 +3,7 @@ import static java.util.Objects.requireNonNull; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TASK_DEADLINE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TASK_DESCRIPTION; import java.util.Collection; @@ -33,7 +34,7 @@ public class EditTaskCommandParser implements Parser { public EditTaskCommand parse(String args) throws ParseException { requireNonNull(args); ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_TASK_DESCRIPTION); + ArgumentTokenizer.tokenize(args, PREFIX_TASK_DESCRIPTION, PREFIX_TASK_DEADLINE); Index index; @@ -49,6 +50,10 @@ public EditTaskCommand parse(String args) throws ParseException { editTaskDescriptor.setDescription( ParserUtil.parseDescription(argMultimap.getValue(PREFIX_TASK_DESCRIPTION).get())); } + if (argMultimap.getValue(PREFIX_TASK_DEADLINE).isPresent()) { + editTaskDescriptor.setDeadline( + ParserUtil.parseDeadline(argMultimap.getValue(PREFIX_TASK_DEADLINE).get())); + } parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editTaskDescriptor::setTags); if (!editTaskDescriptor.isAnyFieldEdited()) { From a6d694161c95dec663f352ff2c902dd63010175e Mon Sep 17 00:00:00 2001 From: junwei-tan Date: Thu, 13 Oct 2022 21:43:29 +0800 Subject: [PATCH 02/11] Add filter command for task and people Users are unable to query based on tags. Allowing quering using tags provides more flexibility in searching. Let's, * add filter command for contacts (filterC) * add filter command for tasks (filterT) --- .../contact/FilterContactCommand.java | 44 ++++++++++++++++++ .../commands/contact/FindContactCommand.java | 4 +- .../commands/task/FilterTaskCommand.java | 46 +++++++++++++++++++ .../logic/parser/AddressBookParser.java | 10 ++++ .../contact/FilterContactCommandParser.java | 37 +++++++++++++++ .../contact/FindContactCommandParser.java | 8 ++-- .../parser/task/FilterTaskCommandParser.java | 37 +++++++++++++++ .../parser/task/FindTaskCommandParser.java | 5 +- .../PersonContainsKeywordsPredicate.java | 45 ++++++++++++------ .../java/seedu/address/model/task/Task.java | 6 ++- .../task/TaskContainsKeywordsPredicate.java | 24 +++++++++- .../FilterContactCommandParserTest.java | 4 ++ .../parser/FilterTaskCommandParserTest.java | 4 ++ .../parser/FindTaskCommandParserTest.java | 4 ++ 14 files changed, 253 insertions(+), 25 deletions(-) create mode 100644 src/main/java/seedu/address/logic/commands/contact/FilterContactCommand.java create mode 100644 src/main/java/seedu/address/logic/commands/task/FilterTaskCommand.java create mode 100644 src/main/java/seedu/address/logic/parser/contact/FilterContactCommandParser.java create mode 100644 src/main/java/seedu/address/logic/parser/task/FilterTaskCommandParser.java create mode 100644 src/test/java/seedu/address/logic/parser/FilterContactCommandParserTest.java create mode 100644 src/test/java/seedu/address/logic/parser/FilterTaskCommandParserTest.java create mode 100644 src/test/java/seedu/address/logic/parser/FindTaskCommandParserTest.java diff --git a/src/main/java/seedu/address/logic/commands/contact/FilterContactCommand.java b/src/main/java/seedu/address/logic/commands/contact/FilterContactCommand.java new file mode 100644 index 00000000000..accd46f5bfb --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/contact/FilterContactCommand.java @@ -0,0 +1,44 @@ +package seedu.address.logic.commands.contact; + +import static java.util.Objects.requireNonNull; + +import seedu.address.commons.core.Messages; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; +import seedu.address.model.Model; +import seedu.address.model.person.PersonContainsKeywordsPredicate; + +/** + * Finds and lists all persons whose tags contain any of the argument keywords. + * Keyword matching is case-insensitive. + */ +public class FilterContactCommand extends Command { + + public static final String COMMAND_WORD = "filterC"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all persons whose tag(s) contain any of " + + "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n" + + "Parameters: KEYWORD [MORE_KEYWORDS]...\n" + + "Example: " + COMMAND_WORD + " grocery shopping friends"; + + private final PersonContainsKeywordsPredicate predicate; + + public FilterContactCommand(PersonContainsKeywordsPredicate predicate) { + this.predicate = predicate; + } + + @Override + public CommandResult execute(Model model) { + requireNonNull(model); + model.updateFilteredPersonList(predicate); + return new CommandResult( + String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size())); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof FilterContactCommand // instanceof handles nulls + && predicate.equals(((FilterContactCommand) other).predicate)); // state check + } +} diff --git a/src/main/java/seedu/address/logic/commands/contact/FindContactCommand.java b/src/main/java/seedu/address/logic/commands/contact/FindContactCommand.java index e8910c80940..b2ba5db6f80 100644 --- a/src/main/java/seedu/address/logic/commands/contact/FindContactCommand.java +++ b/src/main/java/seedu/address/logic/commands/contact/FindContactCommand.java @@ -9,8 +9,8 @@ import seedu.address.model.person.PersonContainsKeywordsPredicate; /** - * Finds and lists all persons in address book whose name contains any of the argument keywords. - * Keyword matching is case insensitive. + * Finds and lists all persons in address book whose fields contain any of the argument keywords. + * Keyword matching is case-insensitive. */ public class FindContactCommand extends Command { diff --git a/src/main/java/seedu/address/logic/commands/task/FilterTaskCommand.java b/src/main/java/seedu/address/logic/commands/task/FilterTaskCommand.java new file mode 100644 index 00000000000..7bcf361dbb4 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/task/FilterTaskCommand.java @@ -0,0 +1,46 @@ +package seedu.address.logic.commands.task; + +import static java.util.Objects.requireNonNull; + +import seedu.address.commons.core.Messages; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; +import seedu.address.model.Model; +import seedu.address.model.task.TaskContainsKeywordsPredicate; + +/** + * Finds and lists all tasks whose tags contain any of the argument keywords. + * Keyword matching is case-insensitive. + */ +public class FilterTaskCommand extends Command { + + public static final String COMMAND_WORD = "filterT"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Finds all tasks whose description/deadline contain any of " + + "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n" + + "Parameters: KEYWORD [MORE_KEYWORDS]...\n" + + "Example: " + COMMAND_WORD + " grocery shopping friends"; + + private final TaskContainsKeywordsPredicate predicate; + + public FilterTaskCommand(TaskContainsKeywordsPredicate predicate) { + this.predicate = predicate; + } + + @Override + public CommandResult execute(Model model) { + requireNonNull(model); + model.updateFilteredTaskList(predicate); + return new CommandResult( + String.format(Messages.MESSAGE_TASKS_LISTED_OVERVIEW, + model.getFilteredTaskList().size())); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof FilterTaskCommand // instanceof handles nulls + && predicate.equals(((FilterTaskCommand) other).predicate)); // state check + } +} diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index edc5ace7a2c..1868e65287a 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -13,12 +13,14 @@ import seedu.address.logic.commands.contact.AddContactCommand; import seedu.address.logic.commands.contact.DeleteContactCommand; import seedu.address.logic.commands.contact.EditContactCommand; +import seedu.address.logic.commands.contact.FilterContactCommand; import seedu.address.logic.commands.contact.FindContactCommand; import seedu.address.logic.commands.contact.ListContactCommand; import seedu.address.logic.commands.tag.AddTagCommand; import seedu.address.logic.commands.tag.DeleteTagCommand; import seedu.address.logic.commands.task.AddTaskCommand; import seedu.address.logic.commands.task.EditTaskCommand; +import seedu.address.logic.commands.task.FilterTaskCommand; import seedu.address.logic.commands.task.FindTaskCommand; import seedu.address.logic.commands.task.ListTaskCommand; import seedu.address.logic.commands.task.MarkTaskCommand; @@ -26,12 +28,14 @@ import seedu.address.logic.parser.contact.AddContactCommandParser; import seedu.address.logic.parser.contact.DeleteContactCommandParser; import seedu.address.logic.parser.contact.EditContactCommandParser; +import seedu.address.logic.parser.contact.FilterContactCommandParser; import seedu.address.logic.parser.contact.FindContactCommandParser; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.logic.parser.tag.AddTagCommandParser; import seedu.address.logic.parser.tag.DeleteTagCommandParser; import seedu.address.logic.parser.task.AddTaskCommandParser; import seedu.address.logic.parser.task.EditTaskCommandParser; +import seedu.address.logic.parser.task.FilterTaskCommandParser; import seedu.address.logic.parser.task.FindTaskCommandParser; import seedu.address.logic.parser.task.MarkTaskCommandParser; import seedu.address.logic.parser.task.UnmarkTaskCommandParser; @@ -78,6 +82,9 @@ public Command parseCommand(String userInput) throws ParseException { case FindContactCommand.COMMAND_WORD: return new FindContactCommandParser().parse(arguments); + case FilterContactCommand.COMMAND_WORD: + return new FilterContactCommandParser().parse(arguments); + case ListContactCommand.COMMAND_WORD: return new ListContactCommand(); @@ -102,6 +109,9 @@ public Command parseCommand(String userInput) throws ParseException { case FindTaskCommand.COMMAND_WORD: return new FindTaskCommandParser().parse(arguments); + case FilterTaskCommand.COMMAND_WORD: + return new FilterTaskCommandParser().parse(arguments); + case MarkTaskCommand.COMMAND_WORD: return new MarkTaskCommandParser().parse(arguments); diff --git a/src/main/java/seedu/address/logic/parser/contact/FilterContactCommandParser.java b/src/main/java/seedu/address/logic/parser/contact/FilterContactCommandParser.java new file mode 100644 index 00000000000..e4a8b9d8e60 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/contact/FilterContactCommandParser.java @@ -0,0 +1,37 @@ +package seedu.address.logic.parser.contact; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; + +import java.util.List; + +import seedu.address.logic.commands.contact.FilterContactCommand; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.ParserUtil; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.person.PersonContainsKeywordsPredicate; + +/** + * Parses input arguments and creates a new FilterContactCommandParser object + */ +public class FilterContactCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the FilterContactCommand + * and returns a FilterContactCommand object for execution. + * + * @param args Raw arguments from user. + * @return FilterContactCommand object. + * @throws ParseException If the user input does not conform the expected format + */ + public FilterContactCommand parse(String args) throws ParseException { + String trimmedArgs = args.trim(); + List tags = List.of(trimmedArgs.split(" ")); + + if (tags.isEmpty()) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, FilterContactCommand.MESSAGE_USAGE)); + } + + return new FilterContactCommand(new PersonContainsKeywordsPredicate(ParserUtil.parseTags(tags))); + } +} diff --git a/src/main/java/seedu/address/logic/parser/contact/FindContactCommandParser.java b/src/main/java/seedu/address/logic/parser/contact/FindContactCommandParser.java index 5b6c886cb62..e23dc69930c 100644 --- a/src/main/java/seedu/address/logic/parser/contact/FindContactCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/contact/FindContactCommandParser.java @@ -31,7 +31,10 @@ public class FindContactCommandParser implements Parser { /** * Parses the given {@code String} of arguments in the context of the FindContactCommand * and returns a FindContactCommand object for execution. - * @throws ParseException if the user input does not conform the expected format + * + * @param args Raw arguments from user. + * @return FindContactCommand object. + * @throws ParseException If the user input does not conform the expected format */ public FindContactCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = @@ -42,8 +45,7 @@ public FindContactCommand parse(String args) throws ParseException { PREFIX_PHONE, PREFIX_EMAIL) || !argMultimap.getPreamble().isEmpty()) { throw new ParseException( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, - FindContactCommand.MESSAGE_USAGE)); + String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindContactCommand.MESSAGE_USAGE)); } List names = getNames(argMultimap); diff --git a/src/main/java/seedu/address/logic/parser/task/FilterTaskCommandParser.java b/src/main/java/seedu/address/logic/parser/task/FilterTaskCommandParser.java new file mode 100644 index 00000000000..dce7ce8c849 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/task/FilterTaskCommandParser.java @@ -0,0 +1,37 @@ +package seedu.address.logic.parser.task; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; + +import java.util.List; + +import seedu.address.logic.commands.task.FilterTaskCommand; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.ParserUtil; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.task.TaskContainsKeywordsPredicate; + +/** + * Parses input arguments and creates a new FilterTaskCommandParser object + */ +public class FilterTaskCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the FilterTaskCommand + * and returns a FilterTaskCommand object for execution. + * + * @param args Raw arguments from user. + * @return FilterTaskCommand object. + * @throws ParseException If the user input does not conform the expected format + */ + public FilterTaskCommand parse(String args) throws ParseException { + String trimmedArgs = args.trim(); + List tags = List.of(trimmedArgs.split(" ")); + + if (tags.isEmpty()) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, FilterTaskCommand.MESSAGE_USAGE)); + } + + return new FilterTaskCommand(new TaskContainsKeywordsPredicate(ParserUtil.parseTags(tags))); + } +} diff --git a/src/main/java/seedu/address/logic/parser/task/FindTaskCommandParser.java b/src/main/java/seedu/address/logic/parser/task/FindTaskCommandParser.java index 88ed1029e69..efdd59513a5 100644 --- a/src/main/java/seedu/address/logic/parser/task/FindTaskCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/task/FindTaskCommandParser.java @@ -27,7 +27,10 @@ public class FindTaskCommandParser implements Parser { /** * Parses the given {@code String} of arguments in the context of the FindTaskCommandParser * and returns a FindTaskCommand object for execution. - * @throws ParseException if the user input does not conform the expected format + * + * @param args Raw arguments from user input. + * @return FindTaskCommand object. + * @throws ParseException If the user input does not conform the expected format */ public FindTaskCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = diff --git a/src/main/java/seedu/address/model/person/PersonContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/person/PersonContainsKeywordsPredicate.java index c3034a44540..283f35ef571 100644 --- a/src/main/java/seedu/address/model/person/PersonContainsKeywordsPredicate.java +++ b/src/main/java/seedu/address/model/person/PersonContainsKeywordsPredicate.java @@ -1,9 +1,14 @@ package seedu.address.model.person; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.function.Predicate; import seedu.address.commons.util.StringUtil; +import seedu.address.model.tag.Tag; /** * Tests that a {@code Person}'s {@code Name} and/or {@code Phone} and/or {@code Email} and/or {@code Address} @@ -14,6 +19,7 @@ public class PersonContainsKeywordsPredicate implements Predicate { private final List phoneKeywords; private final List emailKeywords; private final List
addressKeywords; + private final Set tags; /** * Constructs an {@code PersonContainsKeywordsPredicate}. @@ -29,8 +35,24 @@ public PersonContainsKeywordsPredicate(List nameKeywords, this.phoneKeywords = phoneKeywords; this.emailKeywords = emailKeywords; this.addressKeywords = addressKeywords; + this.tags = new HashSet<>(); + + } + + /** + * Constructs an {@code PersonContainsKeywordsPredicate}. + * + * @param tags A set containing search terms for {@code Tag}. + */ + public PersonContainsKeywordsPredicate(Set tags) { + this.nameKeywords = new ArrayList<>(); + this.phoneKeywords = new ArrayList<>(); + this.emailKeywords = new ArrayList<>(); + this.addressKeywords = new ArrayList<>(); + this.tags = tags; } + // TODO: Implement for tags @Override public boolean test(Person person) { return (nameKeywords.isEmpty() || nameKeywords.stream().anyMatch(keyword -> @@ -40,24 +62,17 @@ public boolean test(Person person) { && (emailKeywords.isEmpty() || emailKeywords.stream().anyMatch(keyword -> StringUtil.containsWordIgnoreCase(person.getEmail().value, keyword.toString()))) && (addressKeywords.isEmpty() || addressKeywords.stream().anyMatch(keyword -> - StringUtil.containsWordIgnoreCase(person.getAddress().value, keyword.toString()))); + StringUtil.containsWordIgnoreCase(person.getAddress().value, keyword.toString()))) + && (tags.isEmpty() || !Collections.disjoint(tags, person.getTags())); } @Override public boolean equals(Object other) { - if (other == this) { - return true; - } - - if (!(other instanceof PersonContainsKeywordsPredicate)) { - return false; - } - - PersonContainsKeywordsPredicate castedOther = (PersonContainsKeywordsPredicate) other; - - return nameKeywords.equals(castedOther.nameKeywords) - && phoneKeywords.equals(castedOther.phoneKeywords) - && emailKeywords.equals(castedOther.emailKeywords) - && addressKeywords.equals(castedOther.addressKeywords); + return other == this // short circuit if same object + || (other instanceof PersonContainsKeywordsPredicate // instanceof handles nulls + && nameKeywords.equals(((PersonContainsKeywordsPredicate) other).nameKeywords)) // state check + && emailKeywords.equals(((PersonContainsKeywordsPredicate) other).emailKeywords) + && addressKeywords.equals(((PersonContainsKeywordsPredicate) other).addressKeywords) + && tags.equals(((PersonContainsKeywordsPredicate) other).tags); } } diff --git a/src/main/java/seedu/address/model/task/Task.java b/src/main/java/seedu/address/model/task/Task.java index 8ecf273c88e..a6e555c4e31 100644 --- a/src/main/java/seedu/address/model/task/Task.java +++ b/src/main/java/seedu/address/model/task/Task.java @@ -92,12 +92,14 @@ public void unmarkTask() { * * @param descriptionKeywords Possibly empty list containing keywords for {@code Description}. * @param deadlineKeywords Possibly empty list containing keywords for {@code Deadline}. + * @param tags Possibly empty set containing search terms for {@code Tag}. * @return boolean indicating if task contains supplied keywords. */ public boolean containsKeywordsCaseInsensitive(List descriptionKeywords, - List deadlineKeywords) { + List deadlineKeywords, Set tags) { return (descriptionKeywords.isEmpty() || descriptionKeywords.stream().anyMatch(description::equalsIgnoreCase)) - && (deadlineKeywords.isEmpty() || deadlineKeywords.contains(deadline)); + && (deadlineKeywords.isEmpty() || deadlineKeywords.contains(deadline)) + && (tags.isEmpty() || !Collections.disjoint(tags, this.tags)); } /** diff --git a/src/main/java/seedu/address/model/task/TaskContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/task/TaskContainsKeywordsPredicate.java index 7247a06fcb9..b90a6bda31c 100644 --- a/src/main/java/seedu/address/model/task/TaskContainsKeywordsPredicate.java +++ b/src/main/java/seedu/address/model/task/TaskContainsKeywordsPredicate.java @@ -1,8 +1,13 @@ package seedu.address.model.task; +import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.function.Predicate; +import seedu.address.model.tag.Tag; + /** * Tests that a {@code task}'s {@code Description} and/or {@code Deadline} * matches any of the keywords given. @@ -10,6 +15,7 @@ public class TaskContainsKeywordsPredicate implements Predicate { private final List descriptionKeywords; private final List deadlineKeywords; + private final Set tags; /** * Constructs an {@code TaskContainsKeywordsPredicate}. @@ -21,6 +27,18 @@ public TaskContainsKeywordsPredicate(List descriptionKeywords, List deadlineKeywords) { this.descriptionKeywords = descriptionKeywords; this.deadlineKeywords = deadlineKeywords; + tags = new HashSet<>(); + } + + /** + * Constructs an {@code TaskContainsKeywordsPredicate}. + * + * @param tags A set containing search terms for {@code Tag}. + */ + public TaskContainsKeywordsPredicate(Set tags) { + this.descriptionKeywords = new ArrayList<>(); + this.deadlineKeywords = new ArrayList<>(); + this.tags = tags; } /** @@ -30,9 +48,10 @@ public TaskContainsKeywordsPredicate(List descriptionKeywords, * @param task Task that will be checked for matching keywords. * @return boolean indicating if task contains supplied keywords. */ + // TODO Implement for tags @Override public boolean test(Task task) { - return task.containsKeywordsCaseInsensitive(descriptionKeywords, deadlineKeywords); + return task.containsKeywordsCaseInsensitive(descriptionKeywords, deadlineKeywords, tags); } @Override @@ -48,6 +67,7 @@ public boolean equals(Object other) { TaskContainsKeywordsPredicate castedOther = (TaskContainsKeywordsPredicate) other; return descriptionKeywords.equals(castedOther.descriptionKeywords) - && deadlineKeywords.equals(castedOther.deadlineKeywords); + && deadlineKeywords.equals(castedOther.deadlineKeywords) + && tags.equals(castedOther.tags); } } diff --git a/src/test/java/seedu/address/logic/parser/FilterContactCommandParserTest.java b/src/test/java/seedu/address/logic/parser/FilterContactCommandParserTest.java new file mode 100644 index 00000000000..7ff9b12acbb --- /dev/null +++ b/src/test/java/seedu/address/logic/parser/FilterContactCommandParserTest.java @@ -0,0 +1,4 @@ +package seedu.address.logic.parser; + +public class FilterContactCommandParserTest { +} diff --git a/src/test/java/seedu/address/logic/parser/FilterTaskCommandParserTest.java b/src/test/java/seedu/address/logic/parser/FilterTaskCommandParserTest.java new file mode 100644 index 00000000000..e6cc973e971 --- /dev/null +++ b/src/test/java/seedu/address/logic/parser/FilterTaskCommandParserTest.java @@ -0,0 +1,4 @@ +package seedu.address.logic.parser; + +public class FilterTaskCommandParserTest { +} diff --git a/src/test/java/seedu/address/logic/parser/FindTaskCommandParserTest.java b/src/test/java/seedu/address/logic/parser/FindTaskCommandParserTest.java new file mode 100644 index 00000000000..23aaf8a0f7f --- /dev/null +++ b/src/test/java/seedu/address/logic/parser/FindTaskCommandParserTest.java @@ -0,0 +1,4 @@ +package seedu.address.logic.parser; + +public class FindTaskCommandParserTest { +} From 4e168409cab4e3af74bb5c021a120b9cd083abc7 Mon Sep 17 00:00:00 2001 From: alvintfl Date: Thu, 13 Oct 2022 22:03:54 +0800 Subject: [PATCH 03/11] Change edit task command to copy isDone value as well Edit task command always sets isDone to false as editTaskDescriptor was not copying taskToEdit's isDone. Let's change edit task command to copy taskToEdit's isDone instead. --- .../seedu/address/logic/commands/task/EditTaskCommand.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/logic/commands/task/EditTaskCommand.java b/src/main/java/seedu/address/logic/commands/task/EditTaskCommand.java index 0d9f41b384b..705e8019bd4 100644 --- a/src/main/java/seedu/address/logic/commands/task/EditTaskCommand.java +++ b/src/main/java/seedu/address/logic/commands/task/EditTaskCommand.java @@ -84,7 +84,10 @@ private static Task createEditedTask(Task taskToEdit, EditTaskDescriptor editTas Description updatedDescription = editTaskDescriptor.getDescription().orElse(taskToEdit.getDescription()); Deadline updatedDeadline = editTaskDescriptor.getDeadline().orElse(taskToEdit.getDeadline()); - Boolean updatedIsDone = editTaskDescriptor.getIsDone().orElse(taskToEdit.getStatus()); + /* Optional not needed as we edit isDone through markT/unmarkT instead + * and editTaskDescriptor's isDone is never set to taskToEdit's isDone. + */ + Boolean updatedIsDone = taskToEdit.getStatus(); Set updatedTags = editTaskDescriptor.getTags().orElse(taskToEdit.getTags()); return new Task(updatedDescription, updatedDeadline, updatedIsDone, updatedTags); From d080070748a475e6db422cc7765d6c7a36507ef4 Mon Sep 17 00:00:00 2001 From: feliciagan Date: Thu, 13 Oct 2022 23:30:29 +0800 Subject: [PATCH 04/11] Add storage of tasks Task list is not stored. The user needs the data to be stored to use the address book regularly. Let's store the task list. --- .../java/seedu/address/model/AddressBook.java | 12 ++- .../seedu/address/model/task/Deadline.java | 4 +- .../seedu/address/model/task/Description.java | 2 +- .../address/storage/JsonAdaptedTask.java | 94 +++++++++++++++++++ .../storage/JsonSerializableAddressBook.java | 17 +++- .../duplicatePersonAddressBook.json | 3 +- .../invalidPersonAddressBook.json | 3 +- .../typicalPersonsAddressBook.json | 3 +- 8 files changed, 130 insertions(+), 8 deletions(-) create mode 100644 src/main/java/seedu/address/storage/JsonAdaptedTask.java diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index b69f0cfaf22..1b1ad2d155b 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -56,6 +56,14 @@ public void setPersons(List persons) { this.persons.setPersons(persons); } + /** + * Replaces the contents of the task list with {@code tasks}. + * {@code tasks} must not contain duplicate tasks. + */ + public void setTasks(List tasks) { + this.tasks.setTasks(tasks); + } + /** * Resets the existing data of this {@code AddressBook} with {@code newData}. */ @@ -63,6 +71,7 @@ public void resetData(ReadOnlyAddressBook newData) { requireNonNull(newData); setPersons(newData.getPersonList()); + setTasks(newData.getTaskList()); } //// person-level operations @@ -106,7 +115,8 @@ public void removePerson(Person key) { @Override public String toString() { - return persons.asUnmodifiableObservableList().size() + " persons"; + return persons.asUnmodifiableObservableList().size() + " persons, " + + tasks.asUnmodifiableObservableList().size() + " tasks"; // TODO: refine later } diff --git a/src/main/java/seedu/address/model/task/Deadline.java b/src/main/java/seedu/address/model/task/Deadline.java index f92dc942b60..6bce96b8573 100644 --- a/src/main/java/seedu/address/model/task/Deadline.java +++ b/src/main/java/seedu/address/model/task/Deadline.java @@ -19,7 +19,8 @@ public class Deadline { */ private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("dd-MM-yyyy"); - private final LocalDate date; + public final String value; + public final LocalDate date; /** * Constructs an {@code Deadline}. @@ -30,6 +31,7 @@ public Deadline(String deadline) { requireNonNull(deadline); //TODO Fix isValidDeadline //checkArgument(isValidDeadline(deadline), MESSAGE_CONSTRAINTS); + this.value = deadline; date = LocalDate.parse(deadline, DATE_TIME_FORMATTER); } diff --git a/src/main/java/seedu/address/model/task/Description.java b/src/main/java/seedu/address/model/task/Description.java index 612b43e76b0..65834c861f2 100644 --- a/src/main/java/seedu/address/model/task/Description.java +++ b/src/main/java/seedu/address/model/task/Description.java @@ -16,7 +16,7 @@ public class Description { */ public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; - private final String taskDescription; + public final String taskDescription; /** * Constructs an {@code Description}. diff --git a/src/main/java/seedu/address/storage/JsonAdaptedTask.java b/src/main/java/seedu/address/storage/JsonAdaptedTask.java new file mode 100644 index 00000000000..366a176ea56 --- /dev/null +++ b/src/main/java/seedu/address/storage/JsonAdaptedTask.java @@ -0,0 +1,94 @@ +package seedu.address.storage; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.tag.Tag; +import seedu.address.model.task.Deadline; +import seedu.address.model.task.Description; +import seedu.address.model.task.Task; + +/** + * Jackson-friendly version of {@link Task}. + */ +public class JsonAdaptedTask { + public static final String MISSING_FIELD_MESSAGE_FORMAT = "Task's %s field is missing!"; + + private final String description; + private final String deadline; + private final Boolean isDone; + private final List tagged = new ArrayList<>(); + + /** + * Constructs a {@code JsonAdaptedTask} with the given task details. + */ + @JsonCreator + public JsonAdaptedTask(@JsonProperty("description") String description, @JsonProperty("deadline") String deadline, + @JsonProperty("isDone") Boolean isDone, + @JsonProperty("tagged") List tagged) { + this.description = description; + this.deadline = deadline; + this.isDone = isDone; + if (tagged != null) { + this.tagged.addAll(tagged); + } + } + + /** + * Converts a given {@code Task} into this class for Jackson use. + */ + public JsonAdaptedTask(Task source) { + description = source.getDescription().taskDescription; + deadline = source.getDeadline().value; + isDone = source.getStatus(); + tagged.addAll(source.getTags().stream() + .map(JsonAdaptedTag::new) + .collect(Collectors.toList())); + } + + /** + * Converts this Jackson-friendly adapted task object into the model's {@code Task} object. + * + * @throws IllegalValueException if there were any data constraints violated in the adapted task. + */ + public Task toModelType() throws IllegalValueException { + final List taskTags = new ArrayList<>(); + for (JsonAdaptedTag tag : tagged) { + taskTags.add(tag.toModelType()); + } + + if (description == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, + Description.class.getSimpleName())); + } + if (!Description.isValidDescription(description)) { + throw new IllegalValueException(Description.MESSAGE_CONSTRAINTS); + } + final Description modelDescription = new Description(description); + + if (deadline == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, + Deadline.class.getSimpleName())); + } + if (!Deadline.isValidDeadline(deadline)) { + throw new IllegalValueException(Deadline.MESSAGE_CONSTRAINTS); + } + final Deadline modelDeadline = new Deadline(deadline); + + if (isDone == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, + Boolean.class.getSimpleName())); + } + final Boolean modelIsDone = isDone; + + final Set modelTags = new HashSet<>(taskTags); + return new Task(modelDescription, modelDeadline, modelIsDone, modelTags); + } +} diff --git a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java index 5efd834091d..e1bfff2ea9e 100644 --- a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java +++ b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java @@ -12,6 +12,7 @@ import seedu.address.model.AddressBook; import seedu.address.model.ReadOnlyAddressBook; import seedu.address.model.person.Person; +import seedu.address.model.task.Task; /** * An Immutable AddressBook that is serializable to JSON format. @@ -20,15 +21,19 @@ class JsonSerializableAddressBook { public static final String MESSAGE_DUPLICATE_PERSON = "Persons list contains duplicate person(s)."; + public static final String MESSAGE_DUPLICATE_TASK = "Tasks list contains duplicate task(s)."; private final List persons = new ArrayList<>(); + private final List tasks = new ArrayList<>(); /** - * Constructs a {@code JsonSerializableAddressBook} with the given persons. + * Constructs a {@code JsonSerializableAddressBook} with the given persons and tasks. */ @JsonCreator - public JsonSerializableAddressBook(@JsonProperty("persons") List persons) { + public JsonSerializableAddressBook(@JsonProperty("persons") List persons, + @JsonProperty("tasks") List tasks) { this.persons.addAll(persons); + this.tasks.addAll(tasks); } /** @@ -38,6 +43,7 @@ public JsonSerializableAddressBook(@JsonProperty("persons") List Date: Fri, 14 Oct 2022 00:31:03 +0800 Subject: [PATCH 05/11] Add exception handling and fix bugs in add and delete tag --- .../logic/commands/tag/AddTagCommand.java | 32 +++++++----- .../logic/commands/tag/DeleteTagCommand.java | 52 +++++++++++-------- .../logic/parser/tag/AddTagCommandParser.java | 13 +++-- .../parser/tag/DeleteTagCommandParser.java | 10 ++-- 4 files changed, 62 insertions(+), 45 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/tag/AddTagCommand.java b/src/main/java/seedu/address/logic/commands/tag/AddTagCommand.java index df73a2b5013..881e5f9ec49 100644 --- a/src/main/java/seedu/address/logic/commands/tag/AddTagCommand.java +++ b/src/main/java/seedu/address/logic/commands/tag/AddTagCommand.java @@ -46,25 +46,28 @@ public class AddTagCommand extends Command { public static final String MESSAGE_ADD_TAG_SUCCESS = "Added tag: %1$s"; public static final String MESSAGE_TAG_NOT_ADDED = "At least 1 tag to add must be provided."; public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book."; + public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the address book."; public static final String MESSAGE_MISSING_INDEX = "At least 1 contact or task index must be provided."; - private final Index index; + private final Index contactIndex; + private final Index taskIndex; private final EditPersonDescriptor editPersonDescriptor; private final EditTaskDescriptor editTaskDescriptor; private final boolean addTagToContact; private final boolean addTagToTask; /** - * @param index of the person in the filtered person list to edit + * @param contactIndex of the person in the filtered person list to edit * @param editPersonDescriptor details to edit the person with */ - public AddTagCommand(Index index, EditPersonDescriptor editPersonDescriptor, EditTaskDescriptor editTaskDescriptor, + public AddTagCommand(Index contactIndex, Index taskIndex, EditPersonDescriptor editPersonDescriptor, EditTaskDescriptor editTaskDescriptor, boolean addTagToContact, boolean addTagToTask) { - requireNonNull(index); + requireNonNull(contactIndex); requireNonNull(editPersonDescriptor); requireNonNull(editTaskDescriptor); - this.index = index; + this.contactIndex = contactIndex; + this.taskIndex = taskIndex; this.editPersonDescriptor = new EditPersonDescriptor(editPersonDescriptor); this.addTagToContact = addTagToContact; this.addTagToTask = addTagToTask; @@ -78,11 +81,11 @@ public CommandResult execute(Model model) throws CommandException { if (addTagToContact) { List lastShownPersonList = model.getFilteredPersonList(); - if (index.getZeroBased() >= lastShownPersonList.size()) { + if (contactIndex.getZeroBased() >= lastShownPersonList.size()) { throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } - Person personToEdit = lastShownPersonList.get(index.getZeroBased()); + Person personToEdit = lastShownPersonList.get(contactIndex.getZeroBased()); Person editedPerson = createEditedPerson(personToEdit, editPersonDescriptor); if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) { @@ -97,15 +100,15 @@ public CommandResult execute(Model model) throws CommandException { if (addTagToTask) { List lastShownTaskList = model.getFilteredTaskList(); - if (index.getZeroBased() >= lastShownTaskList.size()) { - throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + if (taskIndex.getZeroBased() >= lastShownTaskList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); } - Task taskToEdit = lastShownTaskList.get(index.getZeroBased()); + Task taskToEdit = lastShownTaskList.get(taskIndex.getZeroBased()); Task editedTask = createEditedTask(taskToEdit, editTaskDescriptor); if (!taskToEdit.isSameTask(editedTask) && model.hasTask(editedTask)) { - throw new CommandException(MESSAGE_DUPLICATE_PERSON); + throw new CommandException(MESSAGE_DUPLICATE_TASK); } model.setTask(taskToEdit, editedTask); @@ -146,8 +149,7 @@ private static Task createEditedTask(Task taskToEdit, EditTaskDescriptor editTas assert taskToEdit != null; Description updatedDescription = editTaskDescriptor.getDescription().orElse(taskToEdit.getDescription()); - // TODO: Implement - Deadline updatedDeadline = new Deadline(""); + Deadline updatedDeadline = editTaskDescriptor.getDeadline().orElse(taskToEdit.getDeadline()); Boolean updatedIsDone = editTaskDescriptor.getIsDone().orElse(taskToEdit.getStatus()); Set newTags = editTaskDescriptor.getTags().orElse(new HashSet<>()); Set updatedTags = new HashSet<>(); @@ -173,7 +175,9 @@ public boolean equals(Object other) { // state check AddTagCommand e = (AddTagCommand) other; - return index.equals(e.index) + return contactIndex.equals(e.contactIndex) + && taskIndex.equals(e.taskIndex) + && editTaskDescriptor.equals(e.editTaskDescriptor) && editPersonDescriptor.equals(e.editPersonDescriptor); } } diff --git a/src/main/java/seedu/address/logic/commands/tag/DeleteTagCommand.java b/src/main/java/seedu/address/logic/commands/tag/DeleteTagCommand.java index ca6e33c9d71..8e51e217216 100644 --- a/src/main/java/seedu/address/logic/commands/tag/DeleteTagCommand.java +++ b/src/main/java/seedu/address/logic/commands/tag/DeleteTagCommand.java @@ -43,29 +43,36 @@ public class DeleteTagCommand extends Command { + "Example: " + COMMAND_WORD + " 1 " + PREFIX_TAG + "CS2103T"; - public static final String MESSAGE_ADD_TAG_SUCCESS = "Deleted tag: %1$s"; - public static final String MESSAGE_TAG_NOT_ADDED = "At least 1 tag to add must be provided."; - public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book."; + public static final String MESSAGE_DELETE_TAG_SUCCESS = "Deleted tag: %1$s"; + public static final String MESSAGE_TAG_NOT_DELETED = "At least 1 tag to delete must be provided."; + public static final String MESSAGE_TAGS_DO_NOT_EXIST = "The tag(s) you want to remove are not found on the selected contact/task."; public static final String MESSAGE_MISSING_INDEX = "At least 1 contact or task index must be provided."; - private final Index index; + private final Index contactIndex; + private final Index taskIndex; private final EditPersonDescriptor editPersonDescriptor; private final EditTaskDescriptor editTaskDescriptor; private final boolean deleteTagFromContact; private final boolean deleteTagFromTask; /** - * @param index of the person in the filtered person list to edit + * @param contactIndex of the person in the filtered person list to edit + * @param taskIndex of the task in the filtered task list to edit * @param editPersonDescriptor details to edit the person with + * @param editTaskDescriptor details to edit the task with + * @param deleteTagFromContact true if contactIndex was provided + * @param deleteTagFromTask true if taskIndex was provided */ - public DeleteTagCommand(Index index, EditPersonDescriptor editPersonDescriptor, + public DeleteTagCommand(Index contactIndex, Index taskIndex, EditPersonDescriptor editPersonDescriptor, EditTaskDescriptor editTaskDescriptor, boolean deleteTagFromContact, boolean deleteTagFromTask) { - requireNonNull(index); + requireNonNull(contactIndex); + requireNonNull(taskIndex); requireNonNull(editPersonDescriptor); requireNonNull(editTaskDescriptor); - this.index = index; + this.contactIndex = contactIndex; + this.taskIndex = taskIndex; this.editPersonDescriptor = new EditPersonDescriptor(editPersonDescriptor); this.deleteTagFromContact = deleteTagFromContact; this.deleteTagFromTask = deleteTagFromTask; @@ -79,39 +86,39 @@ public CommandResult execute(Model model) throws CommandException { if (deleteTagFromContact) { List lastShownList = model.getFilteredPersonList(); - if (index.getZeroBased() >= lastShownList.size()) { + if (contactIndex.getZeroBased() >= lastShownList.size()) { throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } - Person personToEdit = lastShownList.get(index.getZeroBased()); + Person personToEdit = lastShownList.get(contactIndex.getZeroBased()); Person editedPerson = createEditedPerson(personToEdit, editPersonDescriptor); - if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) { - throw new CommandException(MESSAGE_DUPLICATE_PERSON); + if (personToEdit.getTags().equals(editedPerson.getTags())) { + throw new CommandException(MESSAGE_TAGS_DO_NOT_EXIST); } model.setPerson(personToEdit, editedPerson); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); - return new CommandResult(String.format(MESSAGE_ADD_TAG_SUCCESS, + return new CommandResult(String.format(MESSAGE_DELETE_TAG_SUCCESS, editPersonDescriptor.getTags().orElse(new HashSet<>()))); } if (deleteTagFromTask) { List lastShownTaskList = model.getFilteredTaskList(); - if (index.getZeroBased() >= lastShownTaskList.size()) { - throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + if (taskIndex.getZeroBased() >= lastShownTaskList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); } - Task taskToEdit = lastShownTaskList.get(index.getZeroBased()); + Task taskToEdit = lastShownTaskList.get(taskIndex.getZeroBased()); Task editedTask = createEditedTask(taskToEdit, editTaskDescriptor); - if (!taskToEdit.isSameTask(editedTask) && model.hasTask(editedTask)) { - throw new CommandException(MESSAGE_DUPLICATE_PERSON); + if (taskToEdit.getTags().equals(editedTask.getTags())) { + throw new CommandException(MESSAGE_TAGS_DO_NOT_EXIST); } model.setTask(taskToEdit, editedTask); model.updateFilteredTaskList(PREDICATE_SHOW_ALL_TASKS); - return new CommandResult(String.format(MESSAGE_ADD_TAG_SUCCESS, + return new CommandResult(String.format(MESSAGE_DELETE_TAG_SUCCESS, editTaskDescriptor.getTags().orElse(new HashSet<>()))); } throw new CommandException(MESSAGE_MISSING_INDEX); @@ -147,8 +154,7 @@ private static Task createEditedTask(Task taskToEdit, EditTaskDescriptor editTas assert taskToEdit != null; Description updatedDescription = editTaskDescriptor.getDescription().orElse(taskToEdit.getDescription()); - // TODO: Implement - Deadline updatedDeadline = new Deadline(""); + Deadline updatedDeadline = editTaskDescriptor.getDeadline().orElse(taskToEdit.getDeadline()); Boolean updatedIsDone = editTaskDescriptor.getIsDone().orElse(taskToEdit.getStatus()); Set newTags = editTaskDescriptor.getTags().orElse(new HashSet<>()); Set updatedTags = new HashSet<>(); @@ -174,7 +180,9 @@ public boolean equals(Object other) { // state check DeleteTagCommand e = (DeleteTagCommand) other; - return index.equals(e.index) + return contactIndex.equals(e.contactIndex) + && taskIndex.equals(e.taskIndex) + && editTaskDescriptor.equals(e.editTaskDescriptor) && editPersonDescriptor.equals(e.editPersonDescriptor); } } diff --git a/src/main/java/seedu/address/logic/parser/tag/AddTagCommandParser.java b/src/main/java/seedu/address/logic/parser/tag/AddTagCommandParser.java index fefc559feef..52d7ece115e 100644 --- a/src/main/java/seedu/address/logic/parser/tag/AddTagCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/tag/AddTagCommandParser.java @@ -37,15 +37,17 @@ public AddTagCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_CONTACT, PREFIX_TASK, PREFIX_TAG); - Index index; + Index contactIndex; + Index taskIndex; boolean addTagToContact = argMultimap.getValue(PREFIX_CONTACT).isPresent(); boolean addTagToTask = argMultimap.getValue(PREFIX_TASK).isPresent(); try { - index = ParserUtil.parseIndex(argMultimap.getPreamble()); + contactIndex = ParserUtil.parseIndex(argMultimap.getValue(PREFIX_CONTACT).orElse("1")); + taskIndex = ParserUtil.parseIndex(argMultimap.getValue(PREFIX_TASK).orElse("1")); } catch (ParseException pe) { - throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddTagCommand.MESSAGE_USAGE), pe); + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddTagCommand.MESSAGE_USAGE)); } EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor(); @@ -54,11 +56,12 @@ public AddTagCommand parse(String args) throws ParseException { EditTaskDescriptor editTaskDescriptor = new EditTaskDescriptor(); parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editTaskDescriptor::setTags); - if (!editPersonDescriptor.isAnyFieldEdited()) { + if (!editPersonDescriptor.isAnyFieldEdited() && !editTaskDescriptor.isAnyFieldEdited()) { throw new ParseException(AddTagCommand.MESSAGE_TAG_NOT_ADDED); } - return new AddTagCommand(index, editPersonDescriptor, editTaskDescriptor, addTagToContact, addTagToTask); + return new AddTagCommand(contactIndex, taskIndex, editPersonDescriptor, editTaskDescriptor, + addTagToContact, addTagToTask); } /** diff --git a/src/main/java/seedu/address/logic/parser/tag/DeleteTagCommandParser.java b/src/main/java/seedu/address/logic/parser/tag/DeleteTagCommandParser.java index c3a3d44e968..19822c52078 100644 --- a/src/main/java/seedu/address/logic/parser/tag/DeleteTagCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/tag/DeleteTagCommandParser.java @@ -38,13 +38,15 @@ public DeleteTagCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_CONTACT, PREFIX_TASK, PREFIX_TAG); - Index index; + Index contactIndex; + Index taskIndex; boolean deleteTagFromContact = argMultimap.getValue(PREFIX_CONTACT).isPresent(); boolean deleteTagFromTask = argMultimap.getValue(PREFIX_TASK).isPresent(); try { - index = ParserUtil.parseIndex(argMultimap.getPreamble()); + contactIndex = ParserUtil.parseIndex(argMultimap.getValue(PREFIX_CONTACT).orElse("1")); + taskIndex = ParserUtil.parseIndex(argMultimap.getValue(PREFIX_TASK).orElse("1")); } catch (ParseException pe) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddTagCommand.MESSAGE_USAGE), pe); } @@ -56,10 +58,10 @@ public DeleteTagCommand parse(String args) throws ParseException { parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editTaskDescriptor::setTags); if (!editPersonDescriptor.isAnyFieldEdited()) { - throw new ParseException(AddTagCommand.MESSAGE_TAG_NOT_ADDED); + throw new ParseException(DeleteTagCommand.MESSAGE_TAG_NOT_DELETED); } - return new DeleteTagCommand(index, editPersonDescriptor, editTaskDescriptor, + return new DeleteTagCommand(contactIndex, taskIndex, editPersonDescriptor, editTaskDescriptor, deleteTagFromContact, deleteTagFromTask); } From 18c7115e95ead9aeafe7a52a7f4a1a16d2d9b587 Mon Sep 17 00:00:00 2001 From: ryanguai Date: Fri, 14 Oct 2022 00:43:45 +0800 Subject: [PATCH 06/11] Fix minor checkstyle problems --- .../java/seedu/address/logic/commands/tag/AddTagCommand.java | 4 ++-- .../seedu/address/logic/commands/tag/DeleteTagCommand.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/tag/AddTagCommand.java b/src/main/java/seedu/address/logic/commands/tag/AddTagCommand.java index 881e5f9ec49..06c68dfecbe 100644 --- a/src/main/java/seedu/address/logic/commands/tag/AddTagCommand.java +++ b/src/main/java/seedu/address/logic/commands/tag/AddTagCommand.java @@ -60,8 +60,8 @@ public class AddTagCommand extends Command { * @param contactIndex of the person in the filtered person list to edit * @param editPersonDescriptor details to edit the person with */ - public AddTagCommand(Index contactIndex, Index taskIndex, EditPersonDescriptor editPersonDescriptor, EditTaskDescriptor editTaskDescriptor, - boolean addTagToContact, boolean addTagToTask) { + public AddTagCommand(Index contactIndex, Index taskIndex, EditPersonDescriptor editPersonDescriptor, + EditTaskDescriptor editTaskDescriptor, boolean addTagToContact, boolean addTagToTask) { requireNonNull(contactIndex); requireNonNull(editPersonDescriptor); requireNonNull(editTaskDescriptor); diff --git a/src/main/java/seedu/address/logic/commands/tag/DeleteTagCommand.java b/src/main/java/seedu/address/logic/commands/tag/DeleteTagCommand.java index 8e51e217216..dd3a7284d89 100644 --- a/src/main/java/seedu/address/logic/commands/tag/DeleteTagCommand.java +++ b/src/main/java/seedu/address/logic/commands/tag/DeleteTagCommand.java @@ -45,7 +45,8 @@ public class DeleteTagCommand extends Command { public static final String MESSAGE_DELETE_TAG_SUCCESS = "Deleted tag: %1$s"; public static final String MESSAGE_TAG_NOT_DELETED = "At least 1 tag to delete must be provided."; - public static final String MESSAGE_TAGS_DO_NOT_EXIST = "The tag(s) you want to remove are not found on the selected contact/task."; + public static final String MESSAGE_TAGS_DO_NOT_EXIST = "The tag(s) you want to remove are not found " + + "on the selected contact/task."; public static final String MESSAGE_MISSING_INDEX = "At least 1 contact or task index must be provided."; private final Index contactIndex; From 2e74a9d3f54c2bdf638722c6dc80d72690e49914 Mon Sep 17 00:00:00 2001 From: ryanguai Date: Fri, 14 Oct 2022 00:46:48 +0800 Subject: [PATCH 07/11] Fix wrong indentation --- .../seedu/address/logic/commands/tag/DeleteTagCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/tag/DeleteTagCommand.java b/src/main/java/seedu/address/logic/commands/tag/DeleteTagCommand.java index dd3a7284d89..68cfc9949b5 100644 --- a/src/main/java/seedu/address/logic/commands/tag/DeleteTagCommand.java +++ b/src/main/java/seedu/address/logic/commands/tag/DeleteTagCommand.java @@ -45,8 +45,8 @@ public class DeleteTagCommand extends Command { public static final String MESSAGE_DELETE_TAG_SUCCESS = "Deleted tag: %1$s"; public static final String MESSAGE_TAG_NOT_DELETED = "At least 1 tag to delete must be provided."; - public static final String MESSAGE_TAGS_DO_NOT_EXIST = "The tag(s) you want to remove are not found " + - "on the selected contact/task."; + public static final String MESSAGE_TAGS_DO_NOT_EXIST = "The tag(s) you want to remove are not found " + + "on the selected contact/task."; public static final String MESSAGE_MISSING_INDEX = "At least 1 contact or task index must be provided."; private final Index contactIndex; From 01d38894fd1b2a48b47b8a3ec631501f9ed9f9c1 Mon Sep 17 00:00:00 2001 From: nickeltea Date: Fri, 14 Oct 2022 01:49:02 +0800 Subject: [PATCH 08/11] Implement deleteT command Currently there is no way to delete tasks from the TaskList. The TaskList is only minimally functional with a way to both add and delete tasks. Let's implement a command to delete tasks from the TaskList. --- docs/UserGuide.md | 9 +-- .../logic/commands/task/AddTaskCommand.java | 5 +- .../commands/task/DeleteTaskCommand.java | 58 +++++++++++++++++++ .../logic/parser/AddressBookParser.java | 11 ++-- .../parser/task/AddTaskCommandParser.java | 6 +- .../parser/task/DeleteTaskCommandParser.java | 29 ++++++++++ .../java/seedu/address/model/AddressBook.java | 12 ++++ src/main/java/seedu/address/model/Model.java | 8 ++- .../seedu/address/model/ModelManager.java | 9 ++- .../seedu/address/model/task/TaskList.java | 12 ++++ .../logic/commands/AddContactCommandTest.java | 2 +- 11 files changed, 142 insertions(+), 19 deletions(-) create mode 100644 src/main/java/seedu/address/logic/commands/task/DeleteTaskCommand.java create mode 100644 src/main/java/seedu/address/logic/parser/task/DeleteTaskCommandParser.java diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 0fed3316d7b..b585752022e 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -172,8 +172,9 @@ Format: `listT` ### Adding Tasks: `addT` Adds a task to the task list. -The deadline of the task is allowed to be empty. Newly added tasks are marked as not done. -Throws an exception if the description of the task is empty. +The description and deadline of the task are not allowed to be empty. Newly added tasks are marked as not done. +Throws an exception if the description of the task is empty. +Throws an exception if the deadline of the task is empty. Throws an exception if the deadline of the task is not in dd-mm-yyyy format. Format: `addT d/DESCRIPTION D/DEADLINE` @@ -186,11 +187,11 @@ Example: Removes the specified task from the task list. Throws an exception if task does not exist. -Format: `deleteT i/INDEX` +Format: `deleteT INDEX` Example: -* `deleteT i/12` will delete the 12th task in the task list. +* `deleteT 12` will delete the 12th task in the task list. ### Marking task as done: `markT` diff --git a/src/main/java/seedu/address/logic/commands/task/AddTaskCommand.java b/src/main/java/seedu/address/logic/commands/task/AddTaskCommand.java index b709e36a5c6..b1c97d57ed7 100644 --- a/src/main/java/seedu/address/logic/commands/task/AddTaskCommand.java +++ b/src/main/java/seedu/address/logic/commands/task/AddTaskCommand.java @@ -27,11 +27,12 @@ public class AddTaskCommand extends Command { public static final String MESSAGE_ADD_TASK_SUCCESS = "New task added: %1$s"; // public static final String MESSAGE_MISSING_DESCRIPTION = "A task must have a description"; + // To be implemented later. private final Task newTask; /** - * Creates an AddTCommand to add the specified {@code Task} + * Creates an AddTaskCommand to add the specified {@code Task} */ public AddTaskCommand(Task task) { requireNonNull(task); @@ -42,7 +43,7 @@ public AddTaskCommand(Task task) { public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - model.addT(newTask); + model.addTask(newTask); return new CommandResult(String.format(MESSAGE_ADD_TASK_SUCCESS, newTask)); } diff --git a/src/main/java/seedu/address/logic/commands/task/DeleteTaskCommand.java b/src/main/java/seedu/address/logic/commands/task/DeleteTaskCommand.java new file mode 100644 index 00000000000..367f8e763df --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/task/DeleteTaskCommand.java @@ -0,0 +1,58 @@ +package seedu.address.logic.commands.task; + +import seedu.address.commons.core.Messages; +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.CommandResult; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.task.Task; + +import java.util.List; + +import static java.util.Objects.requireNonNull; + +public class DeleteTaskCommand extends Command { + + public static final String COMMAND_WORD = "deleteT"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Deletes the task identified by the index " + + "number used in the TaskList.\n" + + "Parameters: INDEX (must be a positive integer)\n" + + "Example: " + COMMAND_WORD + " 12"; + + public static final String MESSAGE_DELETE_TASK_SUCCESS = "Deleted Task: %1$s"; + + private final Index targetIndex; + + /** + * Creates a DeleteContactCommand to delete the specified {@code Task}. + * @param targetIndex + */ + public DeleteTaskCommand(Index targetIndex) { + this.targetIndex = targetIndex; + } + + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + List lastShownList = model.getFilteredTaskList(); + + if (targetIndex.getZeroBased() >= lastShownList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); + } + + Task taskToDelete = lastShownList.get(targetIndex.getZeroBased()); + model.deleteTask(taskToDelete); + return new CommandResult(String.format(MESSAGE_DELETE_TASK_SUCCESS, taskToDelete)); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof DeleteTaskCommand // instanceof handles nulls + && targetIndex.equals(((DeleteTaskCommand) other).targetIndex)); + } + +} diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index edc5ace7a2c..e70f0366467 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -17,12 +17,7 @@ import seedu.address.logic.commands.contact.ListContactCommand; import seedu.address.logic.commands.tag.AddTagCommand; import seedu.address.logic.commands.tag.DeleteTagCommand; -import seedu.address.logic.commands.task.AddTaskCommand; -import seedu.address.logic.commands.task.EditTaskCommand; -import seedu.address.logic.commands.task.FindTaskCommand; -import seedu.address.logic.commands.task.ListTaskCommand; -import seedu.address.logic.commands.task.MarkTaskCommand; -import seedu.address.logic.commands.task.UnmarkTaskCommand; +import seedu.address.logic.commands.task.*; import seedu.address.logic.parser.contact.AddContactCommandParser; import seedu.address.logic.parser.contact.DeleteContactCommandParser; import seedu.address.logic.parser.contact.EditContactCommandParser; @@ -31,6 +26,7 @@ import seedu.address.logic.parser.tag.AddTagCommandParser; import seedu.address.logic.parser.tag.DeleteTagCommandParser; import seedu.address.logic.parser.task.AddTaskCommandParser; +import seedu.address.logic.parser.task.DeleteTaskCommandParser; import seedu.address.logic.parser.task.EditTaskCommandParser; import seedu.address.logic.parser.task.FindTaskCommandParser; import seedu.address.logic.parser.task.MarkTaskCommandParser; @@ -96,6 +92,9 @@ public Command parseCommand(String userInput) throws ParseException { case AddTaskCommand.COMMAND_WORD: return new AddTaskCommandParser().parse(arguments); + case DeleteTaskCommand.COMMAND_WORD: + return new DeleteTaskCommandParser().parse(arguments); + case EditTaskCommand.COMMAND_WORD: return new EditTaskCommandParser().parse(arguments); diff --git a/src/main/java/seedu/address/logic/parser/task/AddTaskCommandParser.java b/src/main/java/seedu/address/logic/parser/task/AddTaskCommandParser.java index 9afe14d56b2..e2c697a7122 100644 --- a/src/main/java/seedu/address/logic/parser/task/AddTaskCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/task/AddTaskCommandParser.java @@ -21,13 +21,13 @@ import seedu.address.model.task.Task; /** - * Parses input arguments and creates a new AddTCommand object + * Parses input arguments and creates a new AddTaskCommand object */ public class AddTaskCommandParser implements Parser { /** - * Parses the given {@code String} of arguments in the context of the AddTCommand - * and returns an AddTCommand object for execution. + * Parses the given {@code String} of arguments in the context of the AddTaskCommand + * and returns an AddTaskCommand object for execution. * @throws ParseException if the user input does not conform the expected format */ public AddTaskCommand parse(String args) throws ParseException { diff --git a/src/main/java/seedu/address/logic/parser/task/DeleteTaskCommandParser.java b/src/main/java/seedu/address/logic/parser/task/DeleteTaskCommandParser.java new file mode 100644 index 00000000000..2e97a3ca2ed --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/task/DeleteTaskCommandParser.java @@ -0,0 +1,29 @@ +package seedu.address.logic.parser.task; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; + +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.task.DeleteTaskCommand; +import seedu.address.logic.parser.*; +import seedu.address.logic.parser.exceptions.ParseException; + +/** + * Parses input arguments and creates a new DeleteTaskCommand object + */ +public class DeleteTaskCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the AddTaskCommand + * and returns an AddTaskCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public DeleteTaskCommand parse(String args) throws ParseException { + try { + Index index = ParserUtil.parseIndex(args); + return new DeleteTaskCommand(index); + } catch (ParseException pe) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteTaskCommand.MESSAGE_USAGE), pe); + } + } +} diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index b69f0cfaf22..ed42353753d 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -146,10 +146,22 @@ public ObservableList getTaskList() { return tasks.asUnmodifiableObservableList(); } + /** + * Adds a task to the address book. + * The task must not already exist in the address book. + */ public void addTask(Task task) { tasks.addTask(task); } + /** + * Removes {@code key} from this {@code AddressBook}. + * {@code key} must exist in the address book. + */ + public void removeTask(Task key) { + tasks.remove(key); + } + /** * Returns true if a task with the same description as {@code task} exists in the address book. */ diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index 13ff2e38637..8dad4ae8900 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -94,7 +94,13 @@ public interface Model { * Adds a task to the TaskList. * @param task The task to be added. */ - void addT(Task task); + void addTask(Task task); + + /** + * Deletes a task from the TaskList. + * @param target the task to be deleted + */ + void deleteTask(Task target); /** * Returns true if a task with the same description as {@code task} exists in the address book. diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index b7d0c0da7ab..47125f233a0 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -156,13 +156,18 @@ public boolean equals(Object obj) { && filteredTags.equals(other.filteredTags); } - //=========== TaskList ====================================================================== + //=========== TaskList ================================================================================= @Override - public void addT(Task task) { + public void addTask(Task task) { addressBook.addTask(task); } + @Override + public void deleteTask(Task target) { + addressBook.removeTask(target); + } + @Override public boolean hasTask(Task task) { requireNonNull(task); diff --git a/src/main/java/seedu/address/model/task/TaskList.java b/src/main/java/seedu/address/model/task/TaskList.java index 07dfc2f0816..2db18c93e30 100644 --- a/src/main/java/seedu/address/model/task/TaskList.java +++ b/src/main/java/seedu/address/model/task/TaskList.java @@ -8,6 +8,7 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; +import seedu.address.model.person.exceptions.PersonNotFoundException; import seedu.address.model.task.exceptions.DuplicateTaskException; import seedu.address.model.task.exceptions.TaskNotFoundException; @@ -38,6 +39,17 @@ public void addTask(Task task) { internalList.add(task); } + /** + * Deletes a Task from the TaskList. + * @param toRemove The Task to be added. + */ + public void remove(Task toRemove) { + requireNonNull(toRemove); + if (!internalList.remove(toRemove)) { + throw new TaskNotFoundException(); + } + } + /** * Replaces the task {@code target} in the list with {@code editedTask}. * {@code target} must exist in the list. diff --git a/src/test/java/seedu/address/logic/commands/AddContactCommandTest.java b/src/test/java/seedu/address/logic/commands/AddContactCommandTest.java index a26eecbed45..91c7b35545b 100644 --- a/src/test/java/seedu/address/logic/commands/AddContactCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddContactCommandTest.java @@ -153,7 +153,7 @@ public void updateFilteredPersonList(Predicate predicate) { } @Override - public void addT(Task task) { + public void addTask(Task task) { throw new AssertionError("This method should not be called."); } From 6f984d92f536f84901c7b2e3e34afedd0ee48f7f Mon Sep 17 00:00:00 2001 From: nickeltea Date: Fri, 14 Oct 2022 02:02:21 +0800 Subject: [PATCH 09/11] Fix checkstyle The code does not pass checkstyle. The code should pass checkstyle. Let's improve the code quality so it passes checkstyle. --- .../logic/commands/task/DeleteTaskCommand.java | 15 +++++++++------ .../address/logic/parser/AddressBookParser.java | 8 +++++++- .../parser/task/DeleteTaskCommandParser.java | 3 ++- .../java/seedu/address/model/task/TaskList.java | 1 - .../logic/commands/AddContactCommandTest.java | 5 +++++ 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/task/DeleteTaskCommand.java b/src/main/java/seedu/address/logic/commands/task/DeleteTaskCommand.java index 367f8e763df..ee0b5cf8810 100644 --- a/src/main/java/seedu/address/logic/commands/task/DeleteTaskCommand.java +++ b/src/main/java/seedu/address/logic/commands/task/DeleteTaskCommand.java @@ -1,5 +1,9 @@ package seedu.address.logic.commands.task; +import static java.util.Objects.requireNonNull; + +import java.util.List; + import seedu.address.commons.core.Messages; import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.Command; @@ -8,16 +12,15 @@ import seedu.address.model.Model; import seedu.address.model.task.Task; -import java.util.List; - -import static java.util.Objects.requireNonNull; - +/** + * Deletes a task from the TaskList + */ public class DeleteTaskCommand extends Command { public static final String COMMAND_WORD = "deleteT"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Deletes the task identified by the index " + - "number used in the TaskList.\n" + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Deletes the task identified by the index " + + "number used in the TaskList.\n" + "Parameters: INDEX (must be a positive integer)\n" + "Example: " + COMMAND_WORD + " 12"; diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index e70f0366467..6053bb34d99 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -17,7 +17,13 @@ import seedu.address.logic.commands.contact.ListContactCommand; import seedu.address.logic.commands.tag.AddTagCommand; import seedu.address.logic.commands.tag.DeleteTagCommand; -import seedu.address.logic.commands.task.*; +import seedu.address.logic.commands.task.AddTaskCommand; +import seedu.address.logic.commands.task.DeleteTaskCommand; +import seedu.address.logic.commands.task.EditTaskCommand; +import seedu.address.logic.commands.task.FindTaskCommand; +import seedu.address.logic.commands.task.ListTaskCommand; +import seedu.address.logic.commands.task.MarkTaskCommand; +import seedu.address.logic.commands.task.UnmarkTaskCommand; import seedu.address.logic.parser.contact.AddContactCommandParser; import seedu.address.logic.parser.contact.DeleteContactCommandParser; import seedu.address.logic.parser.contact.EditContactCommandParser; diff --git a/src/main/java/seedu/address/logic/parser/task/DeleteTaskCommandParser.java b/src/main/java/seedu/address/logic/parser/task/DeleteTaskCommandParser.java index 2e97a3ca2ed..ada4fc0332a 100644 --- a/src/main/java/seedu/address/logic/parser/task/DeleteTaskCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/task/DeleteTaskCommandParser.java @@ -4,7 +4,8 @@ import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.task.DeleteTaskCommand; -import seedu.address.logic.parser.*; +import seedu.address.logic.parser.Parser; +import seedu.address.logic.parser.ParserUtil; import seedu.address.logic.parser.exceptions.ParseException; /** diff --git a/src/main/java/seedu/address/model/task/TaskList.java b/src/main/java/seedu/address/model/task/TaskList.java index 2db18c93e30..6e30fae1eb6 100644 --- a/src/main/java/seedu/address/model/task/TaskList.java +++ b/src/main/java/seedu/address/model/task/TaskList.java @@ -8,7 +8,6 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import seedu.address.model.person.exceptions.PersonNotFoundException; import seedu.address.model.task.exceptions.DuplicateTaskException; import seedu.address.model.task.exceptions.TaskNotFoundException; diff --git a/src/test/java/seedu/address/logic/commands/AddContactCommandTest.java b/src/test/java/seedu/address/logic/commands/AddContactCommandTest.java index 91c7b35545b..58877543503 100644 --- a/src/test/java/seedu/address/logic/commands/AddContactCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddContactCommandTest.java @@ -157,6 +157,11 @@ public void addTask(Task task) { throw new AssertionError("This method should not be called."); } + @Override + public void deleteTask(Task task) { + throw new AssertionError("This method should not be called."); + } + @Override public boolean hasTask(Task task) { throw new AssertionError("This method should not be called."); From 63f24165267ed69111bde763b4d97af1795913e1 Mon Sep 17 00:00:00 2001 From: nickeltea Date: Fri, 14 Oct 2022 08:06:19 +0800 Subject: [PATCH 10/11] Correct inaccuracies in JavaDocs There are inaccuracies in the JavaDocs. There should not inaccuracies in the JavaDocs. Let's correct the inaccuracies in the JavaDocs. --- .../seedu/address/logic/commands/task/DeleteTaskCommand.java | 2 +- .../address/logic/parser/task/DeleteTaskCommandParser.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/task/DeleteTaskCommand.java b/src/main/java/seedu/address/logic/commands/task/DeleteTaskCommand.java index ee0b5cf8810..66cfc6e0041 100644 --- a/src/main/java/seedu/address/logic/commands/task/DeleteTaskCommand.java +++ b/src/main/java/seedu/address/logic/commands/task/DeleteTaskCommand.java @@ -29,7 +29,7 @@ public class DeleteTaskCommand extends Command { private final Index targetIndex; /** - * Creates a DeleteContactCommand to delete the specified {@code Task}. + * Creates a DeleteTaskCommand to delete the specified {@code Task}. * @param targetIndex */ public DeleteTaskCommand(Index targetIndex) { diff --git a/src/main/java/seedu/address/logic/parser/task/DeleteTaskCommandParser.java b/src/main/java/seedu/address/logic/parser/task/DeleteTaskCommandParser.java index ada4fc0332a..ab5080515cf 100644 --- a/src/main/java/seedu/address/logic/parser/task/DeleteTaskCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/task/DeleteTaskCommandParser.java @@ -14,8 +14,8 @@ public class DeleteTaskCommandParser implements Parser { /** - * Parses the given {@code String} of arguments in the context of the AddTaskCommand - * and returns an AddTaskCommand object for execution. + * Parses the given {@code String} of arguments in the context of the DeleteTaskCommand + * and returns an DeleteTaskCommand object for execution. * @throws ParseException if the user input does not conform the expected format */ public DeleteTaskCommand parse(String args) throws ParseException { From 2ffdafaf5e85268e5a9291e48ec019ec5243b38c Mon Sep 17 00:00:00 2001 From: ryanguai Date: Fri, 14 Oct 2022 08:51:10 +0800 Subject: [PATCH 11/11] Edit UG based on new command format, fix issues raised in PR comments --- docs/UserGuide.md | 16 ++++++++-------- .../logic/commands/tag/AddTagCommand.java | 1 + .../logic/parser/tag/DeleteTagCommandParser.java | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 0fed3316d7b..e292fd7ef9a 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -279,41 +279,41 @@ Format: `listL` Adds a label to an existing contact in the address book. Each contact can have multiple labels. If there is no existing label with the same name, label is added to the label list. Throws an exception if contact does not exist. -Format: `addL c/INDEX n/label_NAME` +Format: `addL c/INDEX l/label_NAME` Example: -* `addL c/12 n/CS2103T` will add the label "CS2103T" to the 12th contact on the contact list. +* `addL c/12 l/CS2103T` will add the label "CS2103T" to the 12th contact on the contact list. ### Removing a label from a contact: `deleteL` Removes a label from an existing contact in the address book. If contact is last remaining person with said label, label is removed from the label list. Throws an exception if contact or label does not exist. -Format: `deleteL c/INDEX n/label_NAME` +Format: `deleteL c/INDEX l/label_NAME` Example: -* `deleteL c/14 n/CS2101` will remove the label "CS2101" from the 14th contact on the contact list. +* `deleteL c/14 l/CS2101` will remove the label "CS2101" from the 14th contact on the contact list. ### Adding a label to a task: `addL` Adds a label to an existing task in the address book. Each task can have multiple labels. If there is no existing label with the same name, label is added to the label list. Throws an exception if task does not exist. -Format: `addL t/INDEX n/label_NAME` +Format: `addL t/INDEX l/label_NAME` Example: -* `addL t/12 n/CS2103T` will add the label "CS2103T" to the 12th task on the task list. +* `addL t/12 l/CS2103T` will add the label "CS2103T" to the 12th task on the task list. ### Removing a label from a task: `deleteL` Removes a label from an existing task in the address book. If contact is last remaining person with said label, label is removed from the label list. Throws an exception if task or label does not exist. -Format: `deleteL t/INDEX n/label_NAME` +Format: `deleteL t/INDEX l/label_NAME` Example: -* `deleteL t/14 n/CS2101` will remove the label "CS2101" from the 14th task on the task list. +* `deleteL t/14 l/CS2101` will remove the label "CS2101" from the 14th task on the task list. ## Automatic tab switching diff --git a/src/main/java/seedu/address/logic/commands/tag/AddTagCommand.java b/src/main/java/seedu/address/logic/commands/tag/AddTagCommand.java index 06c68dfecbe..cb1e0e668e4 100644 --- a/src/main/java/seedu/address/logic/commands/tag/AddTagCommand.java +++ b/src/main/java/seedu/address/logic/commands/tag/AddTagCommand.java @@ -63,6 +63,7 @@ public class AddTagCommand extends Command { public AddTagCommand(Index contactIndex, Index taskIndex, EditPersonDescriptor editPersonDescriptor, EditTaskDescriptor editTaskDescriptor, boolean addTagToContact, boolean addTagToTask) { requireNonNull(contactIndex); + requireNonNull(taskIndex); requireNonNull(editPersonDescriptor); requireNonNull(editTaskDescriptor); diff --git a/src/main/java/seedu/address/logic/parser/tag/DeleteTagCommandParser.java b/src/main/java/seedu/address/logic/parser/tag/DeleteTagCommandParser.java index 19822c52078..919d71d9be0 100644 --- a/src/main/java/seedu/address/logic/parser/tag/DeleteTagCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/tag/DeleteTagCommandParser.java @@ -57,7 +57,7 @@ public DeleteTagCommand parse(String args) throws ParseException { EditTaskDescriptor editTaskDescriptor = new EditTaskDescriptor(); parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editTaskDescriptor::setTags); - if (!editPersonDescriptor.isAnyFieldEdited()) { + if (!editPersonDescriptor.isAnyFieldEdited() && !editTaskDescriptor.isAnyFieldEdited()) { throw new ParseException(DeleteTagCommand.MESSAGE_TAG_NOT_DELETED); }