|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.faunos.util.tree.AbstractTraverser<T>
public abstract class AbstractTraverser<T>
A depth-first, tree structure traverser. The traverser implements an Euler traversal over the tree structure (generalized for tree nodes with arbitrary number of children). As it traverses the tree, an instance fires pre-order and post-order events along the way.
The tree structure does not have to be defined by the parametric type <T> itself (although it typically is); rather, it is the implementation (a subclass of this class) that decides the structure. This is done by implementing the following abstract methods:hasChildren(Object)
hasChildren(T node)getChildren(T node)
TraverseListener
,
Euler
Traversal
Constructor Summary | |
---|---|
protected |
AbstractTraverser(T root)
Creates a new instance with the given root node. |
Method Summary | |
---|---|
protected abstract T[] |
getChildren(T node)
Returns the child nodes for the specified node. |
TraverseListener<T> |
getListener()
Returns the listener set for traversal. |
Comparator<T> |
getSiblingOrder()
Returns the comparator used to determine the order in which sibling nodes are visited. |
protected abstract boolean |
hasChildren(T node)
Determines whether the given node has child nodes. |
void |
run()
Performs the traversal over the tree structure. |
void |
setListener(TraverseListener<T> listener)
Sets the listener for the traversal. |
void |
setSiblingOrder(Comparator<T> siblingOrder)
Sets the comparator used to determine the order in which sibling nodes are visited. |
void |
visitPostorder(Visitor<T> visitor)
Traverses the tree and visits the tree nodes in post-order. |
void |
visitPreorder(Visitor<T> visitor)
Traverses the tree and visits the tree nodes in pre-order. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected AbstractTraverser(T root)
Method Detail |
---|
public void setListener(TraverseListener<T> listener)
public TraverseListener<T> getListener()
public void setSiblingOrder(Comparator<T> siblingOrder)
public Comparator<T> getSiblingOrder()
public void visitPreorder(Visitor<T> visitor)
IllegalStateException
- if the tree has already been traversedpublic void visitPostorder(Visitor<T> visitor)
IllegalStateException
- if the tree has already been traversedpublic void run()
run
in interface Runnable
IllegalStateException
- if the tree has already been traversedprotected abstract boolean hasChildren(T node)
protected abstract T[] getChildren(T node)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |