package seedu.address.model.task;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import seedu.address.commons.exceptions.DuplicateDataException;
import seedu.address.commons.util.CollectionUtil;

import java.util.*;

/**
 * A list of persons that enforces uniqueness between its elements and does not allow nulls.
 *
 * Supports a minimal set of list operations.
 *
 * @see Task#equals(Object)
 * @see CollectionUtil#elementsAreUnique(Collection)
 */
public class UniqueTaskList implements Iterable<Task> {

    /**
     * Signals that an operation would have violated the 'no duplicates' property of the list.
     */
    public static class DuplicatePersonException extends DuplicateDataException {
        protected DuplicatePersonException() {
            super("Operation would result in duplicate persons");
        }
    }

    /**
     * Signals that an operation targeting a specified person in the list would fail because
     * there is no such matching person in the list.
     */
    public static class PersonNotFoundException extends Exception {}

    private final ObservableList<Task> internalList = FXCollections.observableArrayList();

    /**
     * Constructs empty PersonList.
     */
    public UniqueTaskList() {}

    /**
     * Returns true if the list contains an equivalent person as the given argument.
     */
    public boolean contains(ReadOnlyTask toCheck) {
        assert toCheck != null;
        return internalList.contains(toCheck);
    }

    /**
     * Adds a person to the list.
     *
     * @throws DuplicatePersonException if the person to add is a duplicate of an existing person in the list.
     */
    public void add(Task toAdd) throws DuplicatePersonException {
        assert toAdd != null;
        if (contains(toAdd)) {
            throw new DuplicatePersonException();
        }
        internalList.add(toAdd);
    }

    /**
     * Removes the equivalent person from the list.
     *
     * @throws PersonNotFoundException if no such person could be found in the list.
     */
    public boolean remove(ReadOnlyTask toRemove) throws PersonNotFoundException {
        assert toRemove != null;
        boolean personFoundAndDeleted = false;
        for (Task i: internalList){
        	if(i.getUniqueID()==toRemove.getUniqueID()){
        		personFoundAndDeleted = true;
        		internalList.remove(i);
        		return personFoundAndDeleted;
        	}
        }
        if (!personFoundAndDeleted) {
            throw new PersonNotFoundException();
        }
        return personFoundAndDeleted;
    }

    public ObservableList<Task> getInternalList() {
        return internalList;
    }

    @Override
    public Iterator<Task> iterator() {
        return internalList.iterator();
    }

    @Override
    public boolean equals(Object other) {
        return other == this // short circuit if same object
                || (other instanceof UniqueTaskList // instanceof handles nulls
                && this.internalList.equals(
                ((UniqueTaskList) other).internalList));
    }

    @Override
    public int hashCode() {
        return internalList.hashCode();
    }
}

@@ -1893,32 +1893,525 @@
 dd(toAdd);%0A    %7D
+%0A    %0A    /**%0A     * Adds a person to the list.%0A     *%0A     * @throws PersonNotFoundException if no such person could be found in the list.%0A     */%0A    public boolean setComplete(ReadOnlyTask toComplete) throws PersonNotFoundException %7B%0A        assert toComplete != null;%0A        for (Task i: internalList)%7B%0A        %09if(i.getUniqueID()==toComplete.getUniqueID())%7B%0A        %09%09i.markAsComplete();%0A        %09%09return true;%0A        %09%7D%0A        %7D%0A        throw new PersonNotFoundException();%0A    %7D%0A    
 %0A%0A    /**%0A     *
@@ -2675,55 +2675,8 @@
 ll;%0A
-        boolean personFoundAndDeleted = false;%0A
     
@@ -2765,48 +2765,8 @@
 ))%7B%0A
-        %09%09personFoundAndDeleted = true;%0A
     
@@ -2812,37 +2812,20 @@
 %09return 
-personFoundAndDeleted
+true
 ;%0A      
@@ -2851,133 +2851,43 @@
     
-if (!personFoundAndDeleted) %7B%0A            throw new PersonNotFoundException();%0A        %7D%0A        return personFoundAndDeleted
+throw new PersonNotFoundException()
 ;%0A  

Add setComplete to UniqueTaskList