public abstract class AbstractReflectiveNodeHierarchicalVisitor extends java.lang.Object implements NodeHierarchicalVisitor
AbstractReflectiveNodeHierarchicalVisitor
is used for traversing the structure of a Node
in a hierarchical fashion.
This abstract class delegates method calls for visitEnter(Node)
and visitLeave(Node)
to overloaded methods with the same name.
The delegation is completely driven by the Java Reflection API. This means that you can create a subclass containing any number of overloaded methods, provided that it has exactly one parameter argument and that parameter argument is assignment
compatible to the interface Node
.
The names of the overloaded methods must be either visitEnter
or visitLeave
.
The return type does not matter. But if being able to skip entering child or sibling Node
s are important, the return type has to be either Boolean
or boolean
and the returned value has to be either Boolean.FALSE
or
false
. Any other return type and returned value will be interpreted as boolean
and true
, respectively.
Any access modifier may be used, so private methods are allowed.
Modifier | Constructor and Description |
---|---|
protected |
AbstractReflectiveNodeHierarchicalVisitor()
Constructs a new
AbstractReflectiveNodeHierarchicalVisitor instance. |
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. |
protected AbstractReflectiveNodeHierarchicalVisitor()
AbstractReflectiveNodeHierarchicalVisitor
instance.public final 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
will be thrown.
If node
could not be traversed by this AbstractReflectiveNodeHierarchicalVisitor
, a NodeTraversalException
will be thrown.
The implementation provided by this class will attempt to delegate all calls to overloaded methods with a single parameter argument that is assignment compatible to Node
. If an overloaded method can be found for node
, that method
will be called. If a method was called and its return type is either Boolean
or boolean
, its returned value will be returned by this method. In any other case, true
will be returned. The overloaded method may have any
access modifier assigned to it, so private methods are allowed.
visitEnter
in interface NodeHierarchicalVisitor
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 AbstractReflectiveNodeHierarchicalVisitor
java.lang.NullPointerException
- thrown if, and only if, node
is null
public final 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
will be thrown.
If node
could not be traversed by this AbstractReflectiveNodeHierarchicalVisitor
, a NodeTraversalException
will be thrown.
The implementation provided by this class will attempt to delegate all calls to overloaded methods with a single parameter argument that is assignment compatible to Node
. If an overloaded method can be found for node
, that method
will be called. If a method was called and its return type is either Boolean
or boolean
, its returned value will be returned by this method. In any other case, true
will be returned. The overloaded method may have any
access modifier assigned to it, so private methods are allowed.
visitLeave
in interface NodeHierarchicalVisitor
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 AbstractReflectiveNodeHierarchicalVisitor
java.lang.NullPointerException
- thrown if, and only if, node
is null