package com.vci.client.ui.util;
|
|
import java.util.Enumeration;
|
import java.util.NoSuchElementException;
|
|
import javax.swing.tree.TreeNode;
|
|
|
public class PostorderEnumeration implements Enumeration<TreeNode> {
|
static public final Enumeration<TreeNode> EMPTY_ENUMERATION = new Enumeration<TreeNode>() {
|
public boolean hasMoreElements() {
|
return false;
|
}
|
|
public TreeNode nextElement() {
|
throw new NoSuchElementException("No more elements");
|
}
|
};
|
|
protected TreeNode root;
|
protected Enumeration<TreeNode> children;
|
protected Enumeration<TreeNode> 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
|