public List<TreeNode<N>> getLeaves() { List<TreeNode<N>> leaves = new ArrayList<>(); DepthFirstIterator it = this.new DepthFirstIterator(); while (it.hasNext()) { TreeNode<N> node = it.next(); if (node.isLeaf()) leaves.add(node); } return leaves; }
public void start() { DepthFirstIterator iter = new DepthFirstIterator(program); for (; ; ) { Loop loop = null; try { loop = iter.next(Loop.class); } catch (NoSuchElementException e) { break; } analyzeLoop(loop); } }
/** {@inheritDoc} */ protected void encounterVertexAgain(V vertex, E edge) { super.encounterVertexAgain(vertex, edge); int i; if (root != null) { // For rooted detection, the path must either // double back to the root, or to a node of a cycle // which has already been detected. if (vertex.equals(root)) { i = 0; } else if ((cycleSet != null) && cycleSet.contains(vertex)) { i = 0; } else { return; } } else { i = path.indexOf(vertex); } if (i > -1) { if (cycleSet == null) { // we're doing yes/no cycle detection throw new CycleDetectedException(); } else { for (; i < path.size(); ++i) { cycleSet.add(path.get(i)); } } } }