gt:             for (Iterator iter = subTasks.iterator(); iter.hasNext();) {
context: /**
   * TaskListImpl.java
   * Created on 21.02.2003, 12:29:54 Alex
   * Package: net.sf.memoranda
   *
   * @author Alex V. Alishevskikh, alex@openmechanics.net
   * Copyright (c) 2003 Memoranda Team. http://memoranda.sf.net
   */
  package net.sf.memoranda;
  
  import java.util.Collection;
  import java.util.Hashtable;
  import java.util.Iterator;
  import java.util.Vector;
  
  import net.sf.memoranda.date.CalendarDate;
  import net.sf.memoranda.util.Configuration;
  import net.sf.memoranda.util.Util;
  import nu.xom.Attribute;
  import nu.xom.Document;
  import nu.xom.Element;
  import nu.xom.Elements;
  import nu.xom.Node;
  
  /**
   *
   */
  /*$Id: TaskListImpl.java,v 1.14 2006/07/03 11:59:19 alexeya Exp $*/
  public class TaskListImpl implements TaskList {
  
      private Project _project = null;
      private Document _doc = null;
      private Element _root = null;
  
  	/*
  	 * Hastable of "task" XOM elements for quick searching them by ID's
  	 * (ID => element)
  	 */
  
  	private Hashtable<String, Element> elements =
          new Hashtable<String, Element>();
      /**
       * Constructor for TaskListImpl.
       */
      public TaskListImpl(Document doc, Project prj) {
          _doc = doc;
          _root = _doc.getRootElement();
          _project = prj;
  		buildElements(_root);
      }
  
      public TaskListImpl(Project prj) {
              _root = new Element("tasklist");
              _doc = new Document(_root);
              _project = prj;
      }
  
  	public Project getProject() {
  		return _project;
  	}
  
  	/*
  	 * Build the hashtable recursively
  	 */
  	private void buildElements(Element parent) {
  		Elements els = parent.getChildElements("task");
  		for (int i = 0; i < els.size(); i++) {
  			Element el = els.get(i);
  			elements.put(el.getAttribute("id").getValue(), el);
  			buildElements(el);
  		}
  	}
  
      /**
       * All methods to obtain list of tasks are consolidated under
       * getAllSubTasks and getActiveSubTasks. If a root task is required, just
       * send a null taskId
       */
      public Collection getAllSubTasks(String taskId) {
      	if ((taskId == null) || (taskId.length() == 0)) {
      		return getAllRootTasks();
      	}
      	else {
              Element task = getTaskElement(taskId);
              if (task == null)
                  return new Vector();
              Elements subTasks = task.getChildElements("task");
              return convertToTaskObjects(subTasks);
      	}
      }
  
      public Collection getTopLevelTasks() {
          return getAllRootTasks();
      }
  
      /**
       * All methods to obtain list of tasks are consolidated under
       * getAllSubTasks and getActiveSubTasks. If a root task is required, just
       * send a null taskId
       */
      public Collection getActiveSubTasks(String taskId,CalendarDate date) {
          Collection allTasks = getAllSubTasks(taskId);
          return filterActiveTasks(allTasks,date);
      }
  
      public Task createTask(CalendarDate startDate, CalendarDate endDate,
              String text, int priority, long effort, String description,
              String parentTaskId) {
          Element el = new Element("task");
          el.addAttribute(new Attribute("elapsedTime", "0"));
          el.addAttribute(new Attribute("startDate", startDate.toString()));
          el.addAttribute(new Attribute("endDate",
                      endDate != null? endDate.toString():""));
  		String id = Util.generateId();
          el.addAttribute(new Attribute("id", id));
          el.addAttribute(new Attribute("progress", "0"));
          el.addAttribute(new Attribute("effort", String.valueOf(effort)));
          el.addAttribute(new Attribute("priority", String.valueOf(priority)));
  
          Element txt = new Element("text");
          txt.appendChild(text);
          el.appendChild(txt);
  
          Element desc = new Element("description");
          desc.appendChild(description);
          el.appendChild(desc);
  
          if (parentTaskId == null) {
              _root.appendChild(el);
          } else {
              Element parent = getTaskElement(parentTaskId);
              parent.appendChild(el);
          }
  		elements.put(id, el);
  
          Util.debug("Created task " + id + " with parent " + parentTaskId);
  
          Task newTask = new TaskImpl(el, this);
  
          // if the preference is set, automatically aggregate data from
          // subtasks by calculating on the root
          if (Configuration.get("TASK_AUTO_AGGREGATE").toString()
                  .equalsIgnoreCase("yes")) {
              Util.debug("Auto-aggregating while creating task");
              // get the root task
              Task ptask = newTask;
              while (ptask.getParentTask() != null) {
                  ptask = ptask.getParentTask();
              }
  
              CurrentProject.getTaskList()
                  .calculateCompletionFromSubTasks(ptask);
              CurrentProject.getTaskList()
                  .calculateTotalEffortFromSubTasks(ptask);
          }
          return newTask;
  
      }
  
  	/**
       * @see net.sf.memoranda.TaskList#removeTask(import net.sf.memoranda.Task)
       */
  
      public void removeTask(Task task) {
          String parentTaskId = task.getParentId();
          if (parentTaskId == null) {
              _root.removeChild(task.getContent());
          }
          else {
              Element parentNode = getTaskElement(parentTaskId);
              parentNode.removeChild(task.getContent());
          }
  		elements.remove(task.getID());
      }
  
      public boolean hasSubTasks(String id) {
          Element task = getTaskElement(id);
          if (task == null) return false;
          if(task.getChildElements("task").size() > 0) {
              return true;
          }
          else {
              return false;
          }
      }
  
      public Task getTask(String id) {
          Util.debug("Getting task " + id);
          return new TaskImpl(getTaskElement(id), this);
      }
  
      public boolean hasParentTask(String id) {
      	Element t = getTaskElement(id);
  
      	Node parentNode = t.getParent();
      	if (parentNode instanceof Element) {
      	    Element parent = (Element) parentNode;
          	if (parent.getLocalName().equalsIgnoreCase("task")) {
          	    return true;
          	}
          	else {
          	    return false;
          	}
      	}
      	else {
      	    return false;
      	}
      }
  
      /**
       * @see net.sf.memoranda.TaskList#getXMLContent()
       */
      public Document getXMLContent() {
          return _doc;
      }
  
      /**
       * Recursively calculate total effort based on subtasks for every node in
       * the task tree. The values are saved as they are calculated as well
       *
       * @param t
       * @return
       */
      public long calculateTotalEffortFromSubTasks(Task t) {
          long totalEffort = 0;
          if (hasSubTasks(t.getID())) {
              Collection subTasks = getAllSubTasks(t.getID());
  