public interface NodeHierarchicalVisitor
NodeHierarchicalVisitor
is used for traversing the structure of a Node
in a hierarchical fashion.
It uses a design pattern called Hierarchical Visitor.
This makes it possible to keep track of the current depth or skip a Node
s children or siblings.
Implement it in order to perform various operations on various Node
s in sequence.
Modifier and Type | Method and Description |
---|---|
boolean |
visitEnter(Node node)
Called by a
Node instance when entering it. |
boolean |
visitLeave(Node node)
Called by a
Node instance when leaving it. |
boolean visitEnter(Node node)
Node
instance when entering it.
Returns true
if, and only if, node
s child Node
s should be visited, false
otherwise.
This method should be called by a Node
instance soon after its accept(NodeHierarchicalVisitor)
method has been called.
If node
is null
, a NullPointerException
may be thrown. But no guarantees can be made.
If node
could not be traversed by this NodeHierarchicalVisitor
, a NodeTraversalException
may be thrown. But no guarantees can be made.
node
- the Node
to entertrue
if, and only if, node
s child Node
s should be visited, false
otherwiseNodeTraversalException
- thrown if, and only if, node
could not be traversed by this NodeHierarchicalVisitor
java.lang.NullPointerException
- thrown if, and only if, node
is null
boolean visitLeave(Node node)
Node
instance when leaving it.
Returns true
if, and only if, node
s sibling Node
s should be visited, false
otherwise
This method should be called by a Node
instance just before its accept(NodeHierarchicalVisitor)
method returns. It should be the result returned by that method.
If node
is null
, a NullPointerException
may be thrown. But no guarantees can be made.
If node
could not be traversed by this NodeHierarchicalVisitor
, a NodeTraversalException
may be thrown. But no guarantees can be made.
node
- the Node
to leavetrue
if, and only if, node
s sibling Node
s should be visited, false
otherwiseNodeTraversalException
- thrown if, and only if, node
could not be traversed by this NodeHierarchicalVisitor
java.lang.NullPointerException
- thrown if, and only if, node
is null