package com.vci.client.ui.util; import java.util.Enumeration; import java.util.NoSuchElementException; import javax.swing.tree.TreeNode; public class PostorderEnumeration implements Enumeration { static public final Enumeration EMPTY_ENUMERATION = new Enumeration() { public boolean hasMoreElements() { return false; } public TreeNode nextElement() { throw new NoSuchElementException("No more elements"); } }; protected TreeNode root; protected Enumeration children; protected Enumeration subtree; @SuppressWarnings("unchecked") public PostorderEnumeration(TreeNode rootNode) { super(); root = rootNode; children = root.children(); subtree = EMPTY_ENUMERATION; } public boolean hasMoreElements() { return root != null; } public TreeNode nextElement() { TreeNode retval; if (subtree.hasMoreElements()) { retval = subtree.nextElement(); } else if (children.hasMoreElements()) { subtree = new PostorderEnumeration( (TreeNode) children.nextElement()); retval = subtree.nextElement(); } else { retval = root; root = null; } return retval; } } // End of class PostorderEnumeration