forked from nus-cs2103-AY1617S1/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
b125f10
commit 76f7c67
Showing
26 changed files
with
776 additions
and
552 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
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
75 changes: 75 additions & 0 deletions
75
src/main/java/seedu/task/logic/commands/FavoriteCommand.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.task.logic.commands; | ||
|
||
import seedu.task.commons.core.Messages; | ||
import seedu.task.commons.core.UnmodifiableObservableList; | ||
import seedu.task.logic.RollBackCommand; | ||
import seedu.task.model.task.ReadOnlyTask; | ||
import seedu.task.model.task.Task; | ||
import seedu.task.model.task.UniqueTaskList; | ||
import seedu.task.model.task.UniqueTaskList.TaskNotFoundException; | ||
|
||
/** | ||
* Favorite a task from the task manager. | ||
* @@author A0147335E | ||
*/ | ||
public class FavoriteCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "fav"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Favorite the task identified by the index number used in the last task listing.\n" | ||
+ "Parameters: INDEX TASKNAME\n" | ||
+ "Example: " + COMMAND_WORD | ||
+ " 4"; | ||
|
||
public static final String MESSAGE_FAVORITE_TASK_SUCCESS = "Favorite Task: %1$s"; | ||
|
||
public static final String MESSAGE_ALREADY_FAVORITED = "Task has already been favorited!"; | ||
|
||
public final int targetIndex; | ||
|
||
public FavoriteCommand(int targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(boolean isUndo) { | ||
assert model != null; | ||
UnmodifiableObservableList<ReadOnlyTask> lastShownList = model.getFilteredTaskList(); | ||
|
||
if (lastShownList.size() < targetIndex) { | ||
indicateAttemptToExecuteIncorrectCommand(); | ||
return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); | ||
} | ||
|
||
ReadOnlyTask currentTask = lastShownList.get(targetIndex - 1); | ||
boolean oldStatus = currentTask.getStatus().getFavoriteStatus(); | ||
|
||
try { | ||
model.deleteTask(currentTask); | ||
} catch (TaskNotFoundException tnfe) { | ||
assert false : "The target task cannot be missing"; | ||
} | ||
|
||
Task newTask = new Task(currentTask); | ||
newTask.getStatus().setFavoriteStatus(true); | ||
|
||
try { | ||
model.addTask(targetIndex - 1, newTask); | ||
} catch (UniqueTaskList.DuplicateTaskException e) {} | ||
|
||
if (oldStatus == newTask.getStatus().getFavoriteStatus()) { | ||
return new CommandResult(MESSAGE_ALREADY_FAVORITED); | ||
} | ||
|
||
if (isUndo == false) { | ||
history.getUndoList().add(new RollBackCommand(COMMAND_WORD, newTask, null)); | ||
} | ||
return new CommandResult(String.format(MESSAGE_FAVORITE_TASK_SUCCESS, newTask.getName())); | ||
} | ||
|
||
@Override | ||
public CommandResult execute(int index) { | ||
return null; | ||
} | ||
} |
Oops, something went wrong.