package seedu.todo.models;

import java.time.LocalDateTime;
import java.util.ArrayList;

/**
 * @@author A0093907W
 * 
 * Task model
 */
public class Task implements CalendarItem {
    
    private String name;
    private LocalDateTime dueDate;
    private boolean isCompleted = false;
    private ArrayList<String> tagList = new ArrayList<String>();
    
    private static final int MAX_TAG_LIST_SIZE = 20;

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Get the due date of a Task.
     * @return dueDate
     */
    public LocalDateTime getDueDate() {
        return dueDate;
    }

    /**
     * Set the due date of a Task.
     * @param dueDate
     */
    public void setDueDate(LocalDateTime dueDate) {
        this.dueDate = dueDate;
    }
    
    @Override
    public LocalDateTime getCalendarDateTime() {
        return getDueDate();
    }
    
    @Override
    public void setCalendarDateTime(LocalDateTime date) {
        setDueDate(date);
    }
    
    @Override
    public boolean isOver() {
        if (dueDate == null) {
            return false;
        } else {
            return dueDate.isBefore(LocalDateTime.now());
        }
    }

    /**
     * Returns true if the Task is completed, false otherwise.
     * @return isCompleted
     */
    public boolean isCompleted() {
        return isCompleted;
    }
    
    /**
     * Marks a Task as completed.
     */
    public void setCompleted() {
        this.isCompleted = true;
    }

    /**
     * Marks a Task as incomplete.
     */
    public void setIncomplete() {
        this.isCompleted = false;
    }

    @Override
    //@@author Tiong YaoCong A0139922Y
    public ArrayList<String> getTagList() {
        return tagList;
    }

    @Override
    //@@author Tiong YaoCong A0139922Y
    public boolean addTag(String tagName) {
        if(tagList.size() < MAX_TAG_LIST_SIZE) {
            tagList.add(tagName);
            return true;
        } else {
            return false;
        }
    }

    @Override
    //@@author Tiong YaoCong A0139922Y
    public boolean removeTag(String tagName) {
        return tagList.remove(tagName);
    }

}

@@ -80,16 +80,108 @@
 rayList;
+%0Aimport java.util.List;%0Aimport java.util.function.Predicate;%0Aimport java.util.regex.Pattern;
 %0A%0A/**%0A *
@@ -2339,12 +2339,1393 @@
 );%0A    %7D
+%0A    %0A    %0A    /**%0A     * @@author A0093907W%0A     * %0A     * Filtering methods intended to replace hacky one-filter-method-per-permutation from Yaocong.%0A     * Seriously, why??!!%0A     */%0A    public static List%3CTask%3E where(List%3CPredicate%3CTask%3E%3E predicates) %7B%0A        List%3CTask%3E result = TodoListDB.getInstance().getAllTasks();%0A        for (Predicate%3CTask%3E predicate : predicates) %7B%0A            filter(predicate, result);%0A        %7D%0A        return result;%0A    %7D%0A    %0A    public static Predicate%3CTask%3E predByName(String name) %7B%0A        return (Task task) -%3E Pattern.compile(String.format(%22%5C%5Cb%25s%5C%5Cb%22, name), Pattern.CASE_INSENSITIVE)%0A                .matcher(task.getName()).find();%0A    %7D%0A    %0A    public static Predicate%3CTask%3E predBeforeDueDate(LocalDateTime date) %7B%0A        return (Task task) -%3E task.getDueDate().isBefore(date);%0A    %7D%0A    %0A    public static Predicate%3CTask%3E predAfterDueDate(LocalDateTime date) %7B%0A        return (Task task) -%3E task.getDueDate().isAfter(date);%0A    %7D%0A    %0A    public static Predicate%3CTask%3E predCompleted(boolean completed) %7B%0A        return (Task task) -%3E task.isCompleted() == completed;%0A    %7D%0A    %0A    public static void filter(Predicate%3CTask%3E predicate, List%3CTask%3E taskList) %7B%0A        for (int i = taskList.size() - 1; i %3E= 0; i--) %7B%0A            if (!predicate.test(taskList.get(i))) %7B%0A                taskList.remove(i);%0A            %7D%0A        %7D%0A    %7D
 %0A%0A%7D%0A

Add proper filtering methods