<commit_before>package seedu.tasklist.logic.commands;

import java.util.List;

import seedu.tasklist.commons.core.Messages;
import seedu.tasklist.logic.commands.exceptions.CommandException;
import seedu.tasklist.model.task.ReadOnlyTask;
import seedu.tasklist.model.task.Task;
import seedu.tasklist.model.task.UniqueTaskList;

/**
 * Marks a task as done using its last displayed index from FlexiTask
 * @author A0143355J
 */
public class DoneCommand extends Command {

    public static final String COMMAND_WORD = "done";

    public static final String MESSAGE_USAGE = COMMAND_WORD
            + ": Marks the task identified by the index number used in the last task listing as done.\n"
            + "Parameters: INDEX (must be a positive integer)\n"
            + "Example: " + COMMAND_WORD + " 1";

    public static final String MESSAGE_DONE_TASK_SUCCESS = "Done Task: %1$s";

    public final int targetIndex;

    public DoneCommand(int targetIndex) {
        this.targetIndex = targetIndex;
    }

    @Override
    public CommandResult execute() throws CommandException {
        List<ReadOnlyTask> lastShownList = model.getFilteredTaskList();

        if (lastShownList.size() < targetIndex) {
            throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
        }

        ReadOnlyTask taskToDone = lastShownList.get(targetIndex - 1);

        Task doneTask;

        doneTask = createDoneTask(taskToDone);

        model.updateTask(targetIndex, doneTask);

        model.updateFilteredListToShowAll();
        return new CommandResult(String.format(MESSAGE_DONE_TASK_SUCCESS, taskToDone));
        return null;
    }

}<commit_msg>update execute in DoneCommand<commit_after>package seedu.tasklist.logic.commands;

import java.util.List;

import seedu.tasklist.commons.core.Messages;
import seedu.tasklist.commons.exceptions.IllegalValueException;
import seedu.tasklist.logic.commands.exceptions.CommandException;
import seedu.tasklist.model.task.DeadlineTask;
import seedu.tasklist.model.task.EventTask;
import seedu.tasklist.model.task.FloatingTask;
import seedu.tasklist.model.task.ReadOnlyDeadlineTask;
import seedu.tasklist.model.task.ReadOnlyEventTask;
import seedu.tasklist.model.task.ReadOnlyFloatingTask;
import seedu.tasklist.model.task.ReadOnlyTask;
import seedu.tasklist.model.task.Status;
import seedu.tasklist.model.task.Task;
import seedu.tasklist.model.task.UniqueTaskList.DuplicateTaskException;

/**
 * Marks a task as done using its last displayed index from FlexiTask
 * @author A0143355J
 */
public class DoneCommand extends Command {

    public static final String COMMAND_WORD = "done";

    public static final String MESSAGE_USAGE = COMMAND_WORD
            + ": Marks the task identified by the index number used in the last task listing as done.\n"
            + "Parameters: INDEX (must be a positive integer)\n"
            + "Example: " + COMMAND_WORD + " 1";

    public static final String MESSAGE_DONE_TASK_SUCCESS = "Done Task: %1$s";
    public static final String MESSAGE_DONE_ERROR = "Task is already marked as done!";

    public final int targetIndex;

    public DoneCommand(int targetIndex) {
        this.targetIndex = targetIndex;
    }

    @Override
    public CommandResult execute() throws CommandException {
        List<ReadOnlyTask> lastShownList = model.getFilteredTaskList();

        if (lastShownList.size() < targetIndex) {
            throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
        }

        ReadOnlyTask taskToDone = lastShownList.get(targetIndex - 1);

        Task doneTask;

        try {
            doneTask = createDoneTask(taskToDone);
        } catch (IllegalValueException ive) {
            throw new CommandException(ive.getMessage());
        }

        try {
            model.updateTask(targetIndex, doneTask);
        } catch (DuplicateTaskException e) {
            //Task should never be a duplicate
            assert false;
        }

        model.updateFilteredListToShowAll();
        return new CommandResult(String.format(MESSAGE_DONE_TASK_SUCCESS, taskToDone));
    }

    /**
     * Creates and returns a {@code Task} with the details of {@code taskToDone}
     * edited with status as COMPLETED.
     * @throws IllegalValueException
     */
    private Task createDoneTask(ReadOnlyTask taskToDone) throws IllegalValueException {
        assert taskToDone != null;

        Status status = taskToDone.getStatus();
        if (status.checkStatus() == Status.COMPLETED) {
            throw new IllegalValueException(MESSAGE_DONE_ERROR);
        }

        String type = taskToDone.getType();
        switch (type) {
        case FloatingTask.TYPE:
            FloatingTask doneFloatingTask = new FloatingTask((ReadOnlyFloatingTask) taskToDone);
            doneFloatingTask.getStatus().setCompleted();
            return doneFloatingTask;

        case DeadlineTask.TYPE:
            DeadlineTask doneDeadlineTask = new DeadlineTask((ReadOnlyDeadlineTask) taskToDone);
            doneDeadlineTask.getStatus().setCompleted();
            return doneDeadlineTask;

        case EventTask.TYPE:
            EventTask doneEventTask = new EventTask((ReadOnlyEventTask) taskToDone);
            doneEventTask.getStatus().setCompleted();
            return doneEventTask;

        default:
            return null;
        }
    }

}
{'fraction_non_alphanumeric': 0.08283803863298662, 'fraction_numerical': 0.003714710252600297, 'mean_word_length': 3.1232771822358347, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '979389', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1479, 'n_words': 362}