@@ -0,0 +1,2383 @@
+package seedu.address.logic.commands;%0A%0A%0Aimport seedu.address.model.ModelManager;%0Aimport seedu.address.model.task.Task;%0Aimport seedu.address.model.task.ReadOnlyTask;%0Aimport seedu.address.model.task.UniqueTaskList.TaskNotFoundException;%0Aimport seedu.address.model.task.UniqueTaskList.DuplicateTaskException;%0A%0A%0A%0Apublic class UndoCommand extends Command %7B%0A%0A%09public static final String COMMAND_WORD = %22undo%22;%0A%0A%09public static final String MESSAGE_USAGE = COMMAND_WORD + %22:%5Cn%22 + %22Undo a previous add/ delete command%22%0A%09%09%09+ %22Example: %22 + COMMAND_WORD;%0A%0A%09public static final String MESSAGE_SUCCESS = %22Previous command has been undo%22;%0A%09public static final String MESSAGE_FAIL = %22No previous command found%22;%0A%09%0A%09String PREVCOMMAND;%0A%09%0A%09public CommandResult execute()%7B%0A%0A%09%09if (!model.getUndoStack().isEmpty()) %7B%0A%09%09%09PREVCOMMAND = model.getUndoStack().pop();%0A%0A%09%09%09switch (PREVCOMMAND) %7B%0A%0A%09%09%09case AddCommand.COMMAND_WORD:%0A%09%09%09%09return undoAdd();%0A%0A%09%09%09case DeleteCommand.COMMAND_WORD:%0A%09%09%09%09return undoDelete();%0A%0A%09%09%09%7D%0A%09%09%09%0A%0A%09%09%7D%0A%09%09%0A%09%09return new CommandResult(MESSAGE_FAIL);%0A%09%09%0A%0A%09%7D%0A%09%0A%0A   private CommandResult undoAdd() %7B%0A        assert model != null;%0A        if (model.getDeletedStackOfTasksAdd().isEmpty()) %7B%0A            return new CommandResult(String.format(%22Unable to undo%22));%0A        %7D else %7B%0A            try %7B%0A                ReadOnlyTask reqTask = model.getDeletedStackOfTasksAdd().pop();%0A                model.deleteTask(reqTask);%0A            %7D catch (TaskNotFoundException tnfe) %7B%0A                return new CommandResult(String.format(%22Unable to undo%22));%0A            %7D%0A            return new CommandResult(String.format(UndoCommand.MESSAGE_SUCCESS));%0A        %7D%0A    %7D%0A   %0A   private CommandResult undoDelete() %7B%0A       if (model.getDeletedStackOfTasks().isEmpty() %7C%7C model.getDeletedStackOfTasksIndex().isEmpty()) %7B%0A           return new CommandResult(%22Unable to undo%22);%0A       %7D%0A       %0A      ReadOnlyTask taskToReAdd = model.getDeletedStackOfTasks()%0A               .pop(); /** Gets the required task to reAdd */%0A%0A       /* int idxToReAdd = model.getDeletedStackOfTasksIndex()%0A               .pop(); /** Gets the required task index to reAdd */ %0A%0A       try %7B%0A           model.addTask((Task)taskToReAdd);%0A       %7D catch (DuplicateTaskException e) %7B%0A           return new CommandResult(%22Unable to undo%22);%0A       %7D%0A       return new CommandResult(String.format(UndoCommand.MESSAGE_SUCCESS));%0A   %7D%0A%09%0A%7D%0A%09%0A

Undo Class