org.apache.commons.configuration2.tree

## Class NodeTreeWalker

- java.lang.Object
- - org.apache.commons.configuration2.tree.NodeTreeWalker

-     public class NodeTreeWalker
      extends Object

  A class providing different algorithms for traversing a hierarchy of configuration nodes.

  The methods provided by this class accept a `ConfigurationNodeVisitor` and visit all nodes in a hierarchy starting from a given root node. Because a `NodeHandler` has to be passed in, too, arbitrary types of nodes can be processed. The `walk()` methods differ in the order in which nodes are visited. Details can be found in the method documentation.

  An instance of this class does not define any state; therefore, it can be shared and used concurrently. The `INSTANCE` member field can be used for accessing a default instance. If desired (e.g. for testing purposes), new instances can be created.

  Since:
    2.0
  Version:
    $Id: NodeTreeWalker.java 1624601 2014-09-12 18:04:36Z oheger $

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static NodeTreeWalker` | `INSTANCE` The default instance of this class.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NodeTreeWalker()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `<T> void` | `walkBFS(T root, ConfigurationNodeVisitor<T> visitor, NodeHandler<T> handler)` Visits all nodes in the hierarchy represented by the given root node in breadth first search manner.
    `<T> void` | `walkDFS(T root, ConfigurationNodeVisitor<T> visitor, NodeHandler<T> handler)` Visits all nodes in the hierarchy represented by the given root node in depth first search manner.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### INSTANCE

          public static final NodeTreeWalker INSTANCE

      The default instance of this class.

  - ### Constructor Detail

    - #### NodeTreeWalker

          public NodeTreeWalker()

  - ### Method Detail

    - #### walkDFS

          public <T> void walkDFS(T root,
                                  ConfigurationNodeVisitor<T> visitor,
                                  NodeHandler<T> handler)

      Visits all nodes in the hierarchy represented by the given root node in depth first search manner. This means that first `ConfigurationNodeVisitor.visitBeforeChildren(Object, NodeHandler)` is called on a node, then recursively all of its children are processed, and eventually `ConfigurationNodeVisitor.visitAfterChildren(Object, NodeHandler)` gets invoked.
      Type Parameters:
        `T` - the type of the nodes involved
      Parameters:
        `root` - the root node of the hierarchy to be processed (may be null, then this call has no effect)
        `visitor` - the `ConfigurationNodeVisitor` (must not be null)
        `handler` - the `NodeHandler` (must not be null)
      Throws:
        `IllegalArgumentException` - if a required parameter is null

    - #### walkBFS

          public <T> void walkBFS(T root,
                                  ConfigurationNodeVisitor<T> visitor,
                                  NodeHandler<T> handler)

      Visits all nodes in the hierarchy represented by the given root node in breadth first search manner. This means that the nodes are visited in an order corresponding to the distance from the root node: first the root node is visited, then all direct children of the root node, then all direct children of the first child of the root node, etc. In this mode of traversal, there is no direct connection between the encounter of a node and its children. Therefore, on the visitor object only the `visitBeforeChildren()` method gets called!.
      Type Parameters:
        `T` - the type of the nodes involved
      Parameters:
        `root` - the root node of the hierarchy to be processed (may be null, then this call has no effect)
        `visitor` - the `ConfigurationNodeVisitor` (must not be null)
        `handler` - the `NodeHandler` (must not be null)
      Throws:
        `IllegalArgumentException` - if a required parameter is null

Copyright © 2001–2015 The Apache Software Foundation. All rights reserved.