public Object next() { DigraphNode first = (DigraphNode) zeroList.removeFirst(); // For each out node of the output node, decrement its in-degree Iterator outNodes = first.getOutNodes(); while (outNodes.hasNext()) { DigraphNode node = (DigraphNode) outNodes.next(); int inDegree = ((Integer) inDegrees.get(node)).intValue() - 1; inDegrees.put(node, new Integer(inDegree)); // If the in-degree has fallen to 0, place the node on the list if (inDegree == 0) { zeroList.add(node); } } return first.getData(); }