TreeTraverser
Date: 2016-05-24

com.google.common.collect

## Class TreeTraverser<T>

- java.lang.Object
- - com.google.common.collect.TreeTraverser<T>

- Direct Known Subclasses:
    BinaryTreeTraverser

      @Beta
      @GwtCompatible(emulated=true)
      public abstract class TreeTraverser<T>
      extends java.lang.Object

  Views elements of a type `T` as nodes in a tree, and provides methods to traverse the trees induced by this traverser.

  For example, the tree

                h
              / | \
             /  e  \
            d       g
           /|\      |
          / | \     f
         a  b  c

  can be iterated over in preorder (hdabcegf), postorder (abcdefgh), or breadth-first order (hdegabcf).

  Null nodes are strictly forbidden.

  Since:
    15.0

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `TreeTraverser()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `FluentIterable<T>` | `breadthFirstTraversal(T root)` Returns an unmodifiable iterable over the nodes in a tree structure, using breadth-first traversal.
    `abstract java.lang.Iterable<T>` | `children(T root)` Returns the children of the specified node.
    `FluentIterable<T>` | `postOrderTraversal(T root)` Returns an unmodifiable iterable over the nodes in a tree structure, using post-order traversal.
    `FluentIterable<T>` | `preOrderTraversal(T root)` Returns an unmodifiable iterable over the nodes in a tree structure, using pre-order traversal.

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

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

- - ### Constructor Detail

    - #### TreeTraverser

          public TreeTraverser()

  - ### Method Detail

    - #### children

          public abstract java.lang.Iterable<T> children(T root)

      Returns the children of the specified node. Must not contain null.

    - #### preOrderTraversal

          public final FluentIterable<T> preOrderTraversal(T root)

      Returns an unmodifiable iterable over the nodes in a tree structure, using pre-order traversal. That is, each node's subtrees are traversed after the node itself is returned.

      No guarantees are made about the behavior of the traversal when nodes change while iteration is in progress or when the iterators generated by `children(T)` are advanced.

    - #### postOrderTraversal

          public final FluentIterable<T> postOrderTraversal(T root)

      Returns an unmodifiable iterable over the nodes in a tree structure, using post-order traversal. That is, each node's subtrees are traversed before the node itself is returned.

      No guarantees are made about the behavior of the traversal when nodes change while iteration is in progress or when the iterators generated by `children(T)` are advanced.

    - #### breadthFirstTraversal

          public final FluentIterable<T> breadthFirstTraversal(T root)

      Returns an unmodifiable iterable over the nodes in a tree structure, using breadth-first traversal. That is, all the nodes of depth 0 are returned, then depth 1, then 2, and so on.

      No guarantees are made about the behavior of the traversal when nodes change while iteration is in progress or when the iterators generated by `children(T)` are advanced.