public interface TreeVisitor
TreeVisitor
interface is to be implemented by all visitor objects
that are applied to hierarchical (tree-like or forest-like) structures to collect
information or to perform transformations. The interface describes the protocol for
traversal of hierarchical structures. The general idea is:
Traversal of hierarchical structures starts with calling the onBegin
method and ends with calling the onEnd
methods. Likewise, traversal of
any non-terminal node of the structure starts with calling a method with
the Begin
suffix and ends with calling a method with the End
suffix.
Steps taken in the traversal process depend on the current status of the
visitor (see TreeVisitor.Status
). There are three possible statuses:
OK
- continue traversal;
SKIP
- skip child nodes;
ABORT
- stop traversal.
The status is checked after calling any visitor method. Once ABORT
is set,
all traversal methods return. If after a call to a method having the Begin
suffix,
the SKIP
status is set (not ABORT
and not OK
), nested elements of
the visited node (child nodes or subtrees) are not traversed and a corresponding
terminating method (that has the End
suffix) is called.
Modifier and Type | Interface and Description |
---|---|
static class |
TreeVisitor.Status
The
TreeVisitor.Status enumeration describes possible statuses of the visitor. |
Modifier and Type | Method and Description |
---|---|
TreeVisitor.Status |
getStatus()
Returns the current status of the visitor.
|
void |
onBegin()
Notifies that processing of a hierarchical structure has been started.
|
void |
onEnd()
Notifies that processing of a hierarchical structure has been finished.
|
TreeVisitor.Status getStatus()
void onBegin()
void onEnd()