public class NodeTreeWalker extends java.lang.Object implements NodeIterator
Node
objects, in either a depth-first or breadth-first manner.
The following two diagrams show the represent tree traversal with the two different methods.构造器和说明 |
---|
NodeTreeWalker(Node rootNode)
Creates a new instance of NodeTreeWalker using depth-first tree traversal, without limits on how deep it may traverse.
|
NodeTreeWalker(Node rootNode,
boolean depthFirst)
Creates a new instance of NodeTreeWalker using the specified type of tree traversal, without limits on how deep it may traverse.
|
NodeTreeWalker(Node rootNode,
boolean depthFirst,
int maxDepth)
Creates a new instance of NodeTreeWalker using the specified type of tree traversal and maximum depth from the root Node to traverse.
|
限定符和类型 | 方法和说明 |
---|---|
Node |
getCurrentNode()
Get the Node in the tree that the NodeTreeWalker is current at.
|
int |
getCurrentNodeDepth()
Get the number of places down that the current Node is from the root Node.
|
int |
getMaxDepth()
The maximum depth (number of child-parent links) below the root Node that this NodeTreeWalker may traverse.
|
Node |
getRootNode()
Get the root Node that defines the scope of the tree to traverse.
|
boolean |
hasMoreNodes()
Returns whether or not there are more nodes available based on the current configuration of this NodeTreeWalker.
|
boolean |
isDepthFirst()
Whether the NodeTreeWalker is currently set to use depth-first or breadth-first tree traversal.
|
Node |
nextNode()
Traverses to the next Node from the current Node, using either depth-first or breadth-first tree traversal as appropriate.
|
void |
removeMaxDepthRestriction()
Removes any restrictions in place that prevent this NodeTreeWalker from traversing beyond a certain depth.
|
void |
reset()
Resets the current position in the tree,
such that calling
nextNode() will return the first Node again. |
void |
setCurrentNodeAsRootNode()
Sets the current Node as the root Node.
|
void |
setDepthFirst(boolean depthFirst)
Sets whether the NodeTreeWalker should use depth-first or breadth-first tree traversal.
|
void |
setRootNode(Node rootNode)
Sets the specified Node as the root Node.
|
public NodeTreeWalker(Node rootNode)
rootNode
- Node The Node to set as the root of the tree.java.lang.NullPointerException
- if root Node is null.public NodeTreeWalker(Node rootNode, boolean depthFirst)
rootNode
- The Node to set as the root of the tree.depthFirst
- Whether to use depth-first (true) or breadth-first (false) tree traversal.java.lang.NullPointerException
- if rootNode is null.public NodeTreeWalker(Node rootNode, boolean depthFirst, int maxDepth)
rootNode
- The Node to set as the root of the tree.depthFirst
- Whether to use depth-first (true) or breadth-first (false) tree traversal.maxDepth
- The maximum depth from the root Node that this NodeTreeWalker may traverse. This must be > 0 or equal to -1.java.lang.NullPointerException
- if rootNode is null.java.lang.IllegalArgumentException
- maxDepth is not > 0 or equal to -1.public boolean isDepthFirst()
public void setDepthFirst(boolean depthFirst)
depthFirst
- Whether to use depth-first (true) or breadth-first (false) tree traversal.public int getMaxDepth()
public void removeMaxDepthRestriction()
public Node getRootNode()
public Node getCurrentNode()
public void setCurrentNodeAsRootNode() throws java.lang.NullPointerException
java.lang.NullPointerException
- if the current Node is null (i.e. if the tree traversal has not yet begun).public void setRootNode(Node rootNode) throws java.lang.NullPointerException
rootNode
- The Node to set as the root of the tree.java.lang.NullPointerException
- if rootNode is null.public void reset()
nextNode()
will return the first Node again.public Node nextNode()
nextNode
在接口中 NodeIterator
public int getCurrentNodeDepth()
public boolean hasMoreNodes()
hasMoreNodes
在接口中 NodeIterator