package jfdi.logic.commands;

import java.util.ArrayList;
import java.util.stream.Collectors;

import jfdi.logic.events.ListDoneEvent;
import jfdi.logic.interfaces.Command;
import jfdi.storage.apis.TaskAttributes;
import jfdi.storage.apis.TaskDb;

/**
 * @author Liu Xinan
 */
public class ListCommand extends Command {

    public enum ListType {
        ALL,
        COMPLETED,
        INCOMPLETE,
        ALIASES,
        OVERDUE,
        UPCOMING
    }

    private ListType listType;

    private ListCommand(Builder builder) {
        this.listType = builder.listType;
    }

    public static class Builder {

        ListType listType;

        public Builder setListType(ListType listType) {
            this.listType = listType;
            return this;
        }

        public ListCommand build() {
            return new ListCommand(this);
        }
    }

    public ListType getListType() {
        return this.listType;
    }

    @Override
    public void execute() {
        ArrayList<TaskAttributes> tasks = new ArrayList<>(TaskDb.getInstance()
            .getAll());
        switch (listType) {
            case ALL:
                break;
            case COMPLETED:
                tasks = tasks.stream().filter(task -> task.isCompleted())
                    .collect(Collectors.toCollection(ArrayList::new));
                break;
            case INCOMPLETE:
                tasks = tasks.stream().filter(task -> !task.isCompleted())
                    .collect(Collectors.toCollection(ArrayList::new));
                break;
            case ALIASES:
                break;
            case OVERDUE:
                // TODO:
                break;
            case UPCOMING:
                // TODO:
                break;
            default:
                break;
        }
        eventBus.post(new ListDoneEvent(listType, tasks));
    }

    @Override
    public void undo() {
        throw new UnsupportedOperationException();
    }

}

package jfdi.logic.commands;

import java.util.ArrayList;
import java.util.stream.Collectors;

import org.ocpsoft.prettytime.shade.edu.emory.mathcs.backport.java.util.Collections;

import jfdi.logic.events.ListDoneEvent;
import jfdi.logic.interfaces.Command;
import jfdi.storage.apis.TaskAttributes;
import jfdi.storage.apis.TaskDb;

/**
 * @author Liu Xinan
 */
public class ListCommand extends Command {

    public enum ListType {
        ALL,
        COMPLETED,
        INCOMPLETE,
        ALIASES,
        OVERDUE,
        UPCOMING
    }

    private ListType listType;

    private ListCommand(Builder builder) {
        this.listType = builder.listType;
    }

    public static class Builder {

        ListType listType;

        public Builder setListType(ListType listType) {
            this.listType = listType;
            return this;
        }

        public ListCommand build() {
            return new ListCommand(this);
        }
    }

    public ListType getListType() {
        return this.listType;
    }

    @Override
    public void execute() {
        ArrayList<TaskAttributes> tasks = new ArrayList<>(TaskDb.getInstance()
            .getAll());
        switch (listType) {
            case ALL:
                break;
            case COMPLETED:
                tasks = tasks.stream().filter(task -> task.isCompleted())
                    .collect(Collectors.toCollection(ArrayList::new));
                break;
            case INCOMPLETE:
                tasks = tasks.stream().filter(task -> !task.isCompleted())
                    .collect(Collectors.toCollection(ArrayList::new));
                break;
            case ALIASES:
                break;
            case OVERDUE:
                tasks = new ArrayList<TaskAttributes>(TaskDb.getInstance().getOverdue());
                Collections.sort(tasks);
                break;
            case UPCOMING:
                tasks = new ArrayList<TaskAttributes>(TaskDb.getInstance().getUpcoming());
                Collections.sort(tasks);
                break;
            default:
                break;
        }
        eventBus.post(new ListDoneEvent(listType, tasks));
    }

    @Override
    public void undo() {
        throw new UnsupportedOperationException();
    }

}

Add list overdue/upcoming command