package se.dat255.grupp12; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; /** * Created by ville on 10/15/13. */ public class AssignedList extends TodoList { private HashMap<Task,Integer> taskToListID; public AssignedList() { super("My tasks"); } /** * Getter for the tasks in the TodoList * @return the tasks in the TodoList */ @Override public ArrayList<Task> getTasks() { taskToListID = new HashMap<Task, Integer>(); ArrayList<Task> tasks = new ArrayList<Task>(); for (TodoList list : TodoList.getTodoListsWithoutAssigned()) { if (list.isSoleCollaborator()) { for (Task task : list.getTasks()) { tasks.add(task); taskToListID.put(task,(int) list.getId()); } } else { for (Task task : list.getTasks()) { if (task.isAssigned()) { tasks.add(task); taskToListID.put(task,(int) list.getId()); } } } } Collections.sort(tasks, new TaskComparator()); return tasks; } /** * Get the ID of the list for the specified task. * By default, this always returns the current listid. * * @param task * @return the current listid. */ @Override public long getIdForPosition(Task task) { return this.taskToListID.get(task); } @Override public String getName() { return "My tasks"; } }