Deprecated
Use com. instead. All instance methods have
their equivalent on the result of Traverser.forTree(tree) where tree
implements SuccessorsFunction, which has a similar API as children or can be
the same lambda function as passed into using(Function).
This class is scheduled to be removed in October 2019.
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.
Because this is an abstract class, not an interface, you can't use a lambda expression to implement it:
// won't work
TreeTraverser<NodeType> traverser = node -> node.getChildNodes();
Instead, you can pass a lambda expression to the using factory method:
TreeTraverser<NodeType> traverser = TreeTraverser.using(node -> node.getChildNodes());
| Modifier and Type | Class and Description |
|---|---|
| private class | |
| private class | |
| private static class | |
| private class |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public final FluentIterable | breadthFirstTraversal(final T root)
Deprecated
Use
Returns an unmodifiable iterable over the nodes in a tree structure, using breadth-first
traversal.
com. instead, which has the
same behavior.
|
| public abstract Iterable | |
| pack-priv UnmodifiableIterator | |
| public final FluentIterable | postOrderTraversal(final T root)
Deprecated
Use
Returns an unmodifiable iterable over the nodes in a tree structure, using post-order
traversal.
com. instead, which
has the same behavior.
|
| pack-priv UnmodifiableIterator | |
| public final FluentIterable | preOrderTraversal(final T root)
Deprecated
Use
Returns an unmodifiable iterable over the nodes in a tree structure, using pre-order traversal.
com. instead, which has
the same behavior.
|
| public static <T> TreeTraverser | using(final Function<T, ? extends Iterable<T>> nodeToChildrenFunction)
Deprecated
Use
Returns a tree traverser that uses the given function to navigate from a node to its children.
com. instead.
|
| TreeTraverser | back to summary |
|---|---|
| public TreeTraverser() | |
| breadthFirstTraversal | back to summary |
|---|---|
| public final FluentIterable Deprecated Use 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 | back to summary |
|---|---|
| public abstract Iterable Returns the children of the specified node. Must not contain null. | |
| postOrderIterator | back to summary |
|---|---|
| pack-priv UnmodifiableIterator | |
| postOrderTraversal | back to summary |
|---|---|
| public final FluentIterable Deprecated Use 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
| |
| preOrderIterator | back to summary |
|---|---|
| pack-priv UnmodifiableIterator | |
| preOrderTraversal | back to summary |
|---|---|
| public final FluentIterable Deprecated Use 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
| |
| using | back to summary |
|---|---|
| public static <T> TreeTraverser Deprecated Use Returns a tree traverser that uses the given function to navigate from a node to its children.
This is useful if the function instance already exists, or so that you can supply a lambda
expressions. If those circumstances don't apply, you probably don't need to use this; subclass
| |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public T | next()
Implements com. |
| public T | peek()
Implements com. |
| queue | back to summary |
|---|---|
| private final Queue<T> queue | |
| BreadthFirstIterator | back to summary |
|---|---|
| pack-priv BreadthFirstIterator(T root) | |
| hasNext | back to summary |
|---|---|
| public boolean hasNext() Implements java. Doc from java. Returns
| |
| next | back to summary |
|---|---|
| public T next() Implements com. Doc from com. Returns the next element in the iteration. The objects returned by consecutive calls to
| |
| peek | back to summary |
|---|---|
| public T peek() Implements com. Doc from com. Returns the next element in the iteration, without advancing the iteration. Calls to
| |
| Modifier and Type | Field and Description |
|---|---|
| private final ArrayDeque |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| protected T | computeNext()
Implements abstract com. Note the implementation must call |
| private TreeTraverser. |
| stack | back to summary |
|---|---|
| private final ArrayDeque<TreeTraverser. | |
| PostOrderIterator | back to summary |
|---|---|
| pack-priv PostOrderIterator(T root) | |
| computeNext | back to summary |
|---|---|
| protected T computeNext() Implements abstract com. Doc from com. Returns the next element Note the implementation must call The initial invocation of If this method throws an exception, it will propagate outward to the The implementation of this method may not invoke the
| |
| expand | back to summary |
|---|---|
| private TreeTraverser. | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final Iterator | |
| pack-priv final T |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| childIterator | back to summary |
|---|---|
| pack-priv final Iterator<T> childIterator | |
| root | back to summary |
|---|---|
| pack-priv final T root | |
| PostOrderNode | back to summary |
|---|---|
| pack-priv PostOrderNode(T root, Iterator<T> childIterator) | |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public T |
| stack | back to summary |
|---|---|
| private final Deque<Iterator<T>> stack | |
| PreOrderIterator | back to summary |
|---|---|
| pack-priv PreOrderIterator(T root) | |
| hasNext | back to summary |
|---|---|
| public boolean hasNext() Implements java. Doc from java. Returns
| |
| next | back to summary |
|---|---|
| public T next() Implements java. Doc from java. Returns the next element in the iteration.
| |