package seedu.address.logic.commands;

import java.util.Iterator;
import java.util.Set;

/**
 * Lists all persons in the address book to the user.
 */
public class ListCommand extends Command {

    public static final String COMMAND_WORD = "list";

    public static final String MESSAGE_SUCCESS = "Listed all tasks";

    public static final String MESSAGE_USAGE = COMMAND_WORD + ": List tasks as per the parameters\n"
            + "the specified listname/list index and displays them as a list with index numbers.\n"
            + "Parameters: [LISTNAME/LISTINDEX]\n"
            + "Example: " + COMMAND_WORD + " CS2103";

    private static final String LIST_SEPARATOR = ", ";

    private final Set<String> keywords;

    public ListCommand(Set<String> keywords) {
        this.keywords = keywords;
    }

    public ListCommand() {
        this.keywords = null;
    }

    @Override
    public CommandResult execute() {
        if (keywords == null) {
            model.updateFilteredListToShowAllTasks();
            return new CommandResult(MESSAGE_SUCCESS);
        } else {
            model.updateFilteredTaskListGivenListName(keywords);
            return new CommandResult(formatter(keywords));
        }
    }

    private String formatter(Set<String> keywords) {
        String formatted = MESSAGE_SUCCESS + " in list ";
        for (Iterator<String> it = keywords.iterator(); it.hasNext(); ) {
            formatted += it.next();
            if (it.hasNext()) {
                formatted += LIST_SEPARATOR;
            }
        }
        return formatted;
    }
}

@@ -241,16 +241,70 @@
  %22list%22;
+%0A    %0A    public static final String LIST_ALL = %22all%22;
 %0A%0A    pu
@@ -1124,17 +1124,172 @@
        %7D
- 
+else if(keywords.contains(LIST_ALL))%7B%0A        %09model.updateFilteredListToShowAllTasksAll();%0A            return new CommandResult(MESSAGE_SUCCESS);%0A        %7D
 else %7B%0A 

edit list command to list all tasks