forked from AY2324S2-CS2103T-W13-4/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into adding-list-command
- Loading branch information
Showing
18 changed files
with
440 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,5 @@ src/test/data/sandbox/ | |
.DS_Store | ||
docs/_site/ | ||
docs/_markbind/logs/ | ||
|
||
build.gradle |
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
77 changes: 77 additions & 0 deletions
77
src/main/java/seedu/address/logic/commands/DeleteTaskCommand.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,77 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.task.Task; | ||
|
||
/** | ||
* Deletes a task in the task list. | ||
*/ | ||
public class DeleteTaskCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "deletetask"; | ||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Deletes the task identified by the index number used in the displayed task list.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
public static final String MESSAGE_SUCCESS = "Deleted Task: %1$s"; | ||
public static final String MESSAGE_INDEX_TOO_LARGE = "The index is not valid, use \"listtask\" to " | ||
+ "display all tasks."; | ||
|
||
public static final String MESSAGE_INDEX_BELOW_ONE = "The index must be greater than 0."; | ||
|
||
private final Index taskIndexToDelete; | ||
|
||
/** | ||
* Creates an DeleteTaskCommand to add the specified {@code index} | ||
*/ | ||
public DeleteTaskCommand(Index index) { | ||
taskIndexToDelete = index; | ||
} | ||
|
||
/** | ||
* Executes the command and returns the result message. | ||
* | ||
* @param model {@code Model} which the command should operate on. | ||
* @return feedback message of the operation result for display | ||
* @throws CommandException If an error occurs during command execution. | ||
*/ | ||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
||
if (!model.isValidTaskIndex(taskIndexToDelete)) { | ||
throw new CommandException(MESSAGE_INDEX_TOO_LARGE); | ||
} | ||
|
||
Task taskToDelete = model.getTask(taskIndexToDelete); | ||
model.deleteTask(taskToDelete); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, taskToDelete.getDescription())); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof DeleteTaskCommand)) { | ||
return false; | ||
} | ||
|
||
DeleteTaskCommand otherDeleteCommand = (DeleteTaskCommand) other; | ||
return taskIndexToDelete.equals(otherDeleteCommand.taskIndexToDelete); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("toDelete", taskIndexToDelete.getOneBased()) | ||
.toString(); | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
src/main/java/seedu/address/logic/parser/DeleteTaskCommandParser.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,31 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.DeleteTaskCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new DeleteTaskCommand object | ||
*/ | ||
public class DeleteTaskCommandParser implements Parser<DeleteTaskCommand> { | ||
|
||
/** | ||
* Parses {@code userInput} into a command and returns it. | ||
* | ||
* @param userInput | ||
* @throws ParseException if {@code userInput} does not conform the expected format | ||
*/ | ||
@Override | ||
public DeleteTaskCommand parse(String userInput) throws ParseException { | ||
try { | ||
Index taskIndexToDelete = ParserUtil.parseIndex(userInput.trim()); | ||
return new DeleteTaskCommand(taskIndexToDelete); | ||
} catch (ParseException pe) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteTaskCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
} | ||
|
||
} |
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
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
Oops, something went wrong.