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

import java.util.Optional;

import seedu.taskmanager.commons.core.Messages;
import seedu.taskmanager.commons.core.UnmodifiableObservableList;
import seedu.taskmanager.logic.commands.exceptions.CommandException;
import seedu.taskmanager.model.tag.UniqueTagList;
import seedu.taskmanager.model.task.Description;
import seedu.taskmanager.model.task.EndDate;
import seedu.taskmanager.model.task.ReadOnlyTask;
import seedu.taskmanager.model.task.StartDate;
import seedu.taskmanager.model.task.Status;
import seedu.taskmanager.model.task.Task;
import seedu.taskmanager.model.task.Title;
import seedu.taskmanager.model.task.UniqueTaskList;

/**
 * Mark a task as done in the Task Manager
 */
public class DoneCommand extends Command {

    public static final String COMMAND_WORD = "done";
    public static final String ALTERNATIVE_COMMAND_WORD = "completed";

    public static final String MESSAGE_USAGE = COMMAND_WORD
            + ": Mark 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 + " or " + ALTERNATIVE_COMMAND_WORD + " 1";

    public static final String MESSAGE_MARK_DONE_TASK_SUCCESS = "Task marked done: %1$s";
    public static final String MESSAGE_MARK_DONE_TASK_FAILURE = "ERROR! Task is already done.";
    public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the task manager.";
    
    public final int targetIndex;
    
    public DoneCommand(int targetIndex) {
        this.targetIndex = targetIndex;
    }
    
    @Override
    public CommandResult execute() throws CommandException {
        UnmodifiableObservableList<ReadOnlyTask> lastShownList = model.getFilteredTaskList();

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

        ReadOnlyTask taskToMarkDone = lastShownList.get(targetIndex - 1);
        if (!taskToMarkDone.getStatus().value) {
            Task markedDoneTask = createDoneTask(taskToMarkDone);
            try {
                model.updateTask(targetIndex - 1, markedDoneTask);
            } catch (UniqueTaskList.DuplicateTaskException dpe) {
                throw new CommandException(MESSAGE_DUPLICATE_TASK);
            }
        } else {
            return new CommandResult(String.format(MESSAGE_MARK_DONE_TASK_FAILURE, taskToMarkDone));
        }
        model.updateFilteredListToShowAll();

        return new CommandResult(String.format(MESSAGE_MARK_DONE_TASK_SUCCESS, taskToMarkDone));
    }
    
    /**
     * Creates and returns a {@code Task} with the status marked done
     */
    private static Task createDoneTask(ReadOnlyTask taskToMarkDone) {
        assert taskToMarkDone != null;

        Title updatedTitle = taskToMarkDone.getTitle();
        Optional <StartDate> updatedStartDate = taskToMarkDone.getStartDate();
        Optional <EndDate> updatedEndDate = taskToMarkDone.getEndDate();
        Optional <Description> updatedDescription = taskToMarkDone.getDescription();
        Status updatedStatus = new Status(true);
        UniqueTagList updatedTags = taskToMarkDone.getTags();

        return new Task(updatedTitle, updatedStartDate, updatedEndDate, updatedDescription, updatedStatus, 
                updatedTags);
    }
}<commit_msg>Modify command word for done command<commit_after>package seedu.taskmanager.logic.commands;

import java.util.Optional;

import seedu.taskmanager.commons.core.Messages;
import seedu.taskmanager.commons.core.UnmodifiableObservableList;
import seedu.taskmanager.logic.commands.exceptions.CommandException;
import seedu.taskmanager.model.tag.UniqueTagList;
import seedu.taskmanager.model.task.Description;
import seedu.taskmanager.model.task.EndDate;
import seedu.taskmanager.model.task.ReadOnlyTask;
import seedu.taskmanager.model.task.StartDate;
import seedu.taskmanager.model.task.Status;
import seedu.taskmanager.model.task.Task;
import seedu.taskmanager.model.task.Title;
import seedu.taskmanager.model.task.UniqueTaskList;

// @@author A0114269E
/**
 * Mark a task as done in the Task Manager
 */
public class DoneCommand extends Command {

    public static final String COMMAND_WORD = "done";
    public static final String ALTERNATIVE_COMMAND_WORD_1 = "completed";
    public static final String ALTERNATIVE_COMMAND_WORD_2 = "finished";

    public static final String MESSAGE_USAGE = COMMAND_WORD
            + ": Mark 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 + " or " + ALTERNATIVE_COMMAND_WORD_1 + " or "
            + ALTERNATIVE_COMMAND_WORD_2 + " 1";

    public static final String MESSAGE_MARK_DONE_TASK_SUCCESS = "Task marked done: %1$s";
    public static final String MESSAGE_MARK_DONE_TASK_FAILURE = "ERROR! Task is already done.";
    public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the task manager.";
    
    public final int targetIndex;
    
    public DoneCommand(int targetIndex) {
        this.targetIndex = targetIndex;
    }
    
    @Override
    public CommandResult execute() throws CommandException {
        UnmodifiableObservableList<ReadOnlyTask> lastShownList = model.getFilteredTaskList();

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

        ReadOnlyTask taskToMarkDone = lastShownList.get(targetIndex - 1);
        if (!taskToMarkDone.getStatus().value) {
            Task markedDoneTask = createDoneTask(taskToMarkDone);
            try {
                model.updateTask(targetIndex - 1, markedDoneTask);
            } catch (UniqueTaskList.DuplicateTaskException dpe) {
                throw new CommandException(MESSAGE_DUPLICATE_TASK);
            }
        } else {
            return new CommandResult(String.format(MESSAGE_MARK_DONE_TASK_FAILURE, taskToMarkDone));
        }
        model.updateFilteredListToShowAll();

        return new CommandResult(String.format(MESSAGE_MARK_DONE_TASK_SUCCESS, taskToMarkDone));
    }
    
    /**
     * Creates and returns a {@code Task} with the status marked done
     */
    private static Task createDoneTask(ReadOnlyTask taskToMarkDone) {
        assert taskToMarkDone != null;

        Title updatedTitle = taskToMarkDone.getTitle();
        Optional <StartDate> updatedStartDate = taskToMarkDone.getStartDate();
        Optional <EndDate> updatedEndDate = taskToMarkDone.getEndDate();
        Optional <Description> updatedDescription = taskToMarkDone.getDescription();
        Status updatedStatus = new Status(true);
        UniqueTagList updatedTags = taskToMarkDone.getTags();

        return new Task(updatedTitle, updatedStartDate, updatedEndDate, updatedDescription, updatedStatus, 
                updatedTags);
    }
}
// @@author
{'fraction_non_alphanumeric': 0.0810772501771793, 'fraction_numerical': 0.0026931254429482638, 'mean_word_length': 3.4942675159235668, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 11, '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': '6719755', 'n_tokens_mistral': 1977, 'n_tokens_neox': 1931, 'n_words': 460}