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

import java.util.HashSet;
import java.util.Set;

import seedu.task.commons.core.Messages;
import seedu.task.commons.core.UnmodifiableObservableList;
import seedu.task.commons.exceptions.IllegalValueException;
import seedu.task.model.tag.Tag;
import seedu.task.model.tag.UniqueTagList;
import seedu.task.model.task.Deadline;
import seedu.task.model.task.EventStart;
import seedu.task.model.task.Date;
import seedu.task.model.task.Time;
import seedu.task.model.task.Importance;
import seedu.task.model.task.ReadOnlyTask;
import seedu.task.model.task.Task;
import seedu.task.model.task.TaskName;
import seedu.task.model.task.UniqueTaskList.TaskNotFoundException;

//@@author A0142360U
public class EditCommand extends Command {

    public static final String COMMAND_WORD = "edit";
    public static final String EMPTY_TASK_OBJECT_STRING = "";
    public static final String EMPTY_TAG_OBJECT_STRING = "[]";
    public static final String DEFAULT_DATE_STRING = "01012000";
    public static final String MESSAGE_USAGE = COMMAND_WORD
            + ": edits the task identified by the index number used in the last task listing.\n"
            + "Parameters: INDEX (must be a positive integer)\n" + "Example: " + COMMAND_WORD + " 1";
    public static final String MESSAGE_EDIT_TASK_SUCCESS = "Edited Task: %1$s";

    public final int targetIndex;
    private final Task toEdit;
  //@@author A0142360U
    public EditCommand(String string, String taskName,String startDate,String startTime, String dueDate, String dueTime, String importance,
            Set<String> tags) throws IllegalValueException {
        System.out.println("Target index" + string);
        this.targetIndex = Integer.parseInt(string);

        final Set<Tag> tagSet = new HashSet<>();
        for (String tagName : tags) {
            tagSet.add(new Tag(tagName));
        }

        if ((dueDate == null || dueDate.isEmpty()) && dueTime != null) {
            dueDate = DEFAULT_DATE_STRING;
        }

        if ((startDate == null || startDate.isEmpty()) && startTime != null) {
            startDate = DEFAULT_DATE_STRING;
        }

        if (taskName == null) {
            this.toEdit = new Task(
                    new EventStart(new Date(startDate), new Time(startTime)),
                    new Deadline(new Date(dueDate), new Time(dueTime)),
                    new Importance(importance),
                    new UniqueTagList(tagSet));
        }

        else {
            this.toEdit = new Task(
                    new TaskName(taskName),
                    new EventStart(new Date(startDate), new Time(startTime)),
                    new Deadline(new Date(dueDate), new Time(dueTime)),
                    new Importance(importance),
                    new UniqueTagList(tagSet));
        }
    }

    @Override
    //@@author A0142360U
    public CommandResult execute() {

        UnmodifiableObservableList<ReadOnlyTask> lastShownList = model.getFilteredTaskList();

        if (lastShownList.size() < targetIndex) {
            indicateAttemptToExecuteIncorrectCommand();
            return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
        }

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

        if (taskToEdit.getDeadLine().getDueDate().toString().isEmpty()
                && this.toEdit.getDeadLine().getDueDate().toString().equals(DEFAULT_DATE_STRING)) {
            return new CommandResult(Deadline.MESSAGE_DEADLINE_CONSTRAINTS);
        }

        if (taskToEdit.getEventStart().getStartDate().toString().isEmpty()
                && this.toEdit.getEventStart().getStartDate().toString().equals(DEFAULT_DATE_STRING)) {
            return new CommandResult(EventStart.MESSAGE_EVENT_START_CONSTRAINTS);
        }
        try {
            if (this.toEdit.getName() == null) {
                this.toEdit.setName(taskToEdit.getName());
            }
            if (this.toEdit.getDeadLine().getDueDate().toString().equals(EMPTY_TASK_OBJECT_STRING)
                    || this.toEdit.getDeadLine().getDueDate().toString().equals(DEFAULT_DATE_STRING)) {
                this.toEdit.setDueDate(taskToEdit.getDeadLine().getDueDate());
            }
            if (this.toEdit.getDeadLine().getDueTime().toString().equals(EMPTY_TASK_OBJECT_STRING)) {
                this.toEdit.setDueTime(taskToEdit.getDeadLine().getDueTime());
            }
            if (this.toEdit.getEventStart().getStartDate().toString().equals(EMPTY_TASK_OBJECT_STRING)
                    || this.toEdit.getEventStart().getStartDate().toString().equals(DEFAULT_DATE_STRING)) {
                System.out.println("true!");
                this.toEdit.setStartDate(taskToEdit.getEventStart().getStartDate());
            }
            if (this.toEdit.getEventStart().getStartTime().toString().equals(EMPTY_TASK_OBJECT_STRING)) {
                this.toEdit.setStartTime(taskToEdit.getEventStart().getStartTime());
            }
            if (this.toEdit.getTags().getInternalList().toString().equals(EMPTY_TAG_OBJECT_STRING)) {
                this.toEdit.setTags(taskToEdit.getTags());
            }
            if (this.toEdit.getImportance().toString().equals(EMPTY_TASK_OBJECT_STRING)) {
                this.toEdit.setImportance(taskToEdit.getImportance());
            }
            model.editTask(taskToEdit, this.toEdit);

        } catch (TaskNotFoundException pnfe) {
            assert false : "The target task cannot be missing";
        }

        return new CommandResult(String.format(MESSAGE_EDIT_TASK_SUCCESS, taskToEdit));
    }

}<commit_msg>Small edits to the edit command<commit_after>package seedu.task.logic.commands;

import java.util.HashSet;
import java.util.Set;

import seedu.task.commons.core.Messages;
import seedu.task.commons.core.UnmodifiableObservableList;
import seedu.task.commons.exceptions.IllegalValueException;
import seedu.task.model.tag.Tag;
import seedu.task.model.tag.UniqueTagList;
import seedu.task.model.task.Deadline;
import seedu.task.model.task.EventStart;
import seedu.task.model.task.Date;
import seedu.task.model.task.Time;
import seedu.task.model.task.Importance;
import seedu.task.model.task.ReadOnlyTask;
import seedu.task.model.task.Task;
import seedu.task.model.task.TaskName;
import seedu.task.model.task.UniqueTaskList.TaskNotFoundException;

//@@author A0142360U
public class EditCommand extends Command {

    public static final String COMMAND_WORD = "edit";
    public static final String EMPTY_TASK_OBJECT_STRING = "";
    public static final String EMPTY_TAG_OBJECT_STRING = "[]";
    public static final String DEFAULT_DATE_STRING = "01012000";
    public static final String MESSAGE_USAGE = COMMAND_WORD
            + ": edits the task identified by the index number used in the last task listing.\n"
            + "Parameters: INDEX (must be a positive integer)\n" + "Example: " + COMMAND_WORD + " 1";
    public static final String MESSAGE_EDIT_TASK_SUCCESS = "Edited Task: %1$s";

    public final int targetIndex;
    private final Task toEdit;

    // @@author A0142360U
    public EditCommand(String string, String taskName, String startDate, String startTime, String dueDate,
            String dueTime, String importance, Set<String> tags) throws IllegalValueException {
        System.out.println("Target index" + string);
        this.targetIndex = Integer.parseInt(string);

        final Set<Tag> tagSet = new HashSet<>();
        for (String tagName : tags) {
            tagSet.add(new Tag(tagName));
        }

        if ((dueDate == null || dueDate.isEmpty()) && dueTime != null) {
            dueDate = DEFAULT_DATE_STRING;
        }

        if ((startDate == null || startDate.isEmpty()) && startTime != null) {
            startDate = DEFAULT_DATE_STRING;
        }

        if (taskName == null) {
            this.toEdit = new Task(new EventStart(new Date(startDate), new Time(startTime)),
                    new Deadline(new Date(dueDate), new Time(dueTime)), new Importance(importance),
                    new UniqueTagList(tagSet));
        }

        else {
            this.toEdit = new Task(new TaskName(taskName), new EventStart(new Date(startDate), new Time(startTime)),
                    new Deadline(new Date(dueDate), new Time(dueTime)), new Importance(importance),
                    new UniqueTagList(tagSet));
        }
    }

    @Override
    // @@author A0142360U
    public CommandResult execute() {

        UnmodifiableObservableList<ReadOnlyTask> lastShownList = model.getFilteredTaskList();

        if (lastShownList.size() < targetIndex) {
            indicateAttemptToExecuteIncorrectCommand();
            return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
        }

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

        if (taskToEdit.getDeadLine().getDueDate().toString().isEmpty()
                && this.toEdit.getDeadLine().getDueDate().toString().equals(DEFAULT_DATE_STRING)) {
            return new CommandResult(Deadline.MESSAGE_DEADLINE_CONSTRAINTS);
        }

        if (taskToEdit.getEventStart().getStartDate().toString().isEmpty()
                && this.toEdit.getEventStart().getStartDate().toString().equals(DEFAULT_DATE_STRING)) {
            return new CommandResult(EventStart.MESSAGE_EVENT_START_CONSTRAINTS);
        }
        try {
            if (this.toEdit.getName() == null) {
                this.toEdit.setName(taskToEdit.getName());
            }
            if (this.toEdit.getDeadLine().getDueDate().toString().equals(EMPTY_TASK_OBJECT_STRING)
                    || this.toEdit.getDeadLine().getDueDate().toString().equals(DEFAULT_DATE_STRING)) {
                this.toEdit.setDueDate(taskToEdit.getDeadLine().getDueDate());
            }
            if (this.toEdit.getDeadLine().getDueTime().toString().equals(EMPTY_TASK_OBJECT_STRING)) {
                this.toEdit.setDueTime(taskToEdit.getDeadLine().getDueTime());
            }
            if (this.toEdit.getEventStart().getStartDate().toString().equals(EMPTY_TASK_OBJECT_STRING)
                    || this.toEdit.getEventStart().getStartDate().toString().equals(DEFAULT_DATE_STRING)) {
                this.toEdit.setStartDate(taskToEdit.getEventStart().getStartDate());
            }
            if (this.toEdit.getEventStart().getStartTime().toString().equals(EMPTY_TASK_OBJECT_STRING)) {
                this.toEdit.setStartTime(taskToEdit.getEventStart().getStartTime());
            }
            if (this.toEdit.getTags().getInternalList().toString().equals(EMPTY_TAG_OBJECT_STRING)) {
                this.toEdit.setTags(taskToEdit.getTags());
            }
            if (this.toEdit.getImportance().toString().equals(EMPTY_TASK_OBJECT_STRING)) {
                this.toEdit.setImportance(taskToEdit.getImportance());
            }
            model.editTask(taskToEdit, this.toEdit);

        } catch (TaskNotFoundException pnfe) {
            assert false : "The target task cannot be missing";
        }

        return new CommandResult(String.format(MESSAGE_EDIT_TASK_SUCCESS, taskToEdit));
    }

}
{'fraction_non_alphanumeric': 0.11330225887414844, 'fraction_numerical': 0.005736823234134099, 'mean_word_length': 2.7845997286295794, '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': '674374', 'n_tokens_mistral': 3244, 'n_tokens_neox': 3111, 'n_words': 556}