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

import seedu.watodo.commons.core.Messages;
import seedu.watodo.commons.core.UnmodifiableObservableList;
import seedu.watodo.logic.commands.exceptions.CommandException;
import seedu.watodo.model.task.ReadOnlyTask;
import seedu.watodo.model.task.Task;
import seedu.watodo.model.task.TaskStatus;
import seedu.watodo.model.task.UniqueTaskList;
import seedu.watodo.model.task.UniqueTaskList.DuplicateTaskException;

//@@author A0141077L
/**
 * Marks a task identified using it's last displayed index from the task manager
 * as completed.
 */
public class MarkCommand extends Command {

    public static final String COMMAND_WORD = "mark";

    public static final String MESSAGE_USAGE = COMMAND_WORD + ": Sets the status of the task identified to done "
            + "by the index number used in the last task listing as completed.\n"
            + "Parameters: INDEX (must be a positive integer) [MORE_INDICES]\n" + "Example: " + COMMAND_WORD
            + " 1 2";

    public static final String MESSAGE_MARK_TASK_SUCCESS = "Task completed: %1$s";
    public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the task manager.";
    public static final String MESSAGE_STATUS_DONE = "The task status is already set to Done.";

    private int[] filteredTaskListIndices;
    private int undoMarkInt;
    private Task undoMark;
    private Task markedTask;

    public MarkCommand(int[] args) {
        this.filteredTaskListIndices = args;

        for (int i = 0; i < filteredTaskListIndices.length; i++) {
            assert filteredTaskListIndices != null;
            assert filteredTaskListIndices.length > 0;
            assert filteredTaskListIndices[i] > 0;

            // converts filteredTaskListIndex to from one-based to zero-based.
            filteredTaskListIndices[i] = filteredTaskListIndices[i] - 1;
        }
    }

    @Override
    public CommandResult execute() throws CommandException {
        final StringBuilder tasksMarkedMessage = new StringBuilder();

        for (int i = 0; i < filteredTaskListIndices.length; i++) {
            UnmodifiableObservableList<ReadOnlyTask> lastShownList = model.getFilteredTaskList();

            if (filteredTaskListIndices[i] >= lastShownList.size()) {
                throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
            }

            ReadOnlyTask taskToMark = lastShownList.get(filteredTaskListIndices[i]);
            this.undoMark = new Task(taskToMark);

            try {
                markedTask = createMarkedTask(taskToMark);
                model.updateTask(filteredTaskListIndices[i], markedTask);
                this.undoMarkInt = filteredTaskListIndices[i];

            } catch (UniqueTaskList.DuplicateTaskException dpe) {
                throw new CommandException(MESSAGE_DUPLICATE_TASK);
            }

            tasksMarkedMessage.append(String.format(MESSAGE_MARK_TASK_SUCCESS, taskToMark) + "\n");
        }

        return new CommandResult(tasksMarkedMessage.toString());
    }

    //@@author A0139845R

    @Override
    public void unexecute() {
        try {
            model.updateFilteredListToShowAll();
            model.updateTask(undoMarkInt, undoMark);
        } catch (DuplicateTaskException e) {

        }
    }

    @Override
    public void redo() {
        try {
            model.updateFilteredListToShowAll();
            this.execute();
        } catch (CommandException e) {
        }
    }

    //@@author

    /**
     * Creates and returns a {@code Task} with the details of {@code taskToMark}
     */
    private static Task createMarkedTask(ReadOnlyTask taskToMark) throws CommandException {
        assert taskToMark != null;

        if (taskToMark.getStatus() == TaskStatus.DONE) {
            throw new CommandException(MESSAGE_STATUS_DONE);
        }

        Task markedTask = new Task(taskToMark.getDescription(), taskToMark.getStartDate(), taskToMark.getEndDate(),
                taskToMark.getTags());
        markedTask.setStatus(TaskStatus.DONE);

        return markedTask;
    }

}
<commit_msg>Fix undo and redo for mark task to support multiple marks<commit_after>package seedu.watodo.logic.commands;

import java.util.Stack;

import seedu.watodo.commons.core.Messages;
import seedu.watodo.commons.core.UnmodifiableObservableList;
import seedu.watodo.logic.commands.exceptions.CommandException;
import seedu.watodo.model.task.ReadOnlyTask;
import seedu.watodo.model.task.Task;
import seedu.watodo.model.task.TaskStatus;
import seedu.watodo.model.task.UniqueTaskList;
import seedu.watodo.model.task.UniqueTaskList.DuplicateTaskException;

//@@author A0141077L
/**
 * Marks a task identified using it's last displayed index from the task manager
 * as completed.
 */
public class MarkCommand extends Command {

    public static final String COMMAND_WORD = "mark";

    public static final String MESSAGE_USAGE = COMMAND_WORD
            + ": Sets the status of the task identified to done "
            + "by the index number used in the last task listing as completed.\n"
            + "Parameters: INDEX (must be a positive integer) [MORE_INDICES]\n" + "Example: "
            + COMMAND_WORD
            + " 1 2";

    public static final String MESSAGE_MARK_TASK_SUCCESS = "Task completed: %1$s";
    public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the task manager.";
    public static final String MESSAGE_STATUS_DONE = "The task status is already set to Done.";

    private int[] filteredTaskListIndices;
    private Stack< Integer > undoMarkInt;
    private Stack< Task > undoMark;
    private Task markedTask;

    public MarkCommand(int[] args) {
        this.filteredTaskListIndices = args;

        undoMark = new Stack< Task >();
        undoMarkInt = new Stack< Integer >();

        for (int i = 0; i < filteredTaskListIndices.length; i++) {
            assert filteredTaskListIndices != null;
            assert filteredTaskListIndices.length > 0;
            assert filteredTaskListIndices[i] > 0;

            // converts filteredTaskListIndex to from one-based to zero-based.
            filteredTaskListIndices[i] = filteredTaskListIndices[i] - 1;
        }
    }

    @Override
    public CommandResult execute() throws CommandException {
        final StringBuilder tasksMarkedMessage = new StringBuilder();

        for (int i = 0; i < filteredTaskListIndices.length; i++) {
            UnmodifiableObservableList<ReadOnlyTask> lastShownList = model.getFilteredTaskList();

            if (filteredTaskListIndices[i] >= lastShownList.size()) {
                throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
            }

            ReadOnlyTask taskToMark = lastShownList.get(filteredTaskListIndices[i]);
            this.undoMark.push(new Task(taskToMark));


            try {
                markedTask = createMarkedTask(taskToMark);
                model.updateTask(filteredTaskListIndices[i], markedTask);
                this.undoMarkInt.push(filteredTaskListIndices[i]);

            } catch (UniqueTaskList.DuplicateTaskException dpe) {
                throw new CommandException(MESSAGE_DUPLICATE_TASK);
            }

            tasksMarkedMessage.append(String.format(MESSAGE_MARK_TASK_SUCCESS, taskToMark) + "\n");
        }

        return new CommandResult(tasksMarkedMessage.toString());
    }

    //@@author A0139845R

    @Override
    public void unexecute() {
        try {
            model.updateFilteredListToShowAll();
            while (!undoMark.isEmpty()) {
                model.updateTask(undoMarkInt.pop(), undoMark.pop());
            }
        } catch (DuplicateTaskException e) {

        }
    }

    @Override
    public void redo() {
        try {
            model.updateFilteredListToShowAll();
            this.execute();
        } catch (CommandException e) {
        }
    }

    //@@author

    /**
     * Creates and returns a {@code Task} with the details of {@code taskToMark}
     */
    private static Task createMarkedTask(ReadOnlyTask taskToMark) throws CommandException {
        assert taskToMark != null;

        if (taskToMark.getStatus() == TaskStatus.DONE) {
            throw new CommandException(MESSAGE_STATUS_DONE);
        }

        Task markedTask = new Task(taskToMark.getDescription(), taskToMark.getStartDate(), taskToMark.getEndDate(),
                taskToMark.getTags());
        markedTask.setStatus(TaskStatus.DONE);

        return markedTask;
    }

}

{'fraction_non_alphanumeric': 0.08916676405282226, 'fraction_numerical': 0.00514198901484165, 'mean_word_length': 2.7387505460899955, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 15, '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': '6718004', 'n_tokens_mistral': 2440, 'n_tokens_neox': 2314, 'n_words': 574}