Traverser
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(T)
or can be
the same lambda function as passed into using(Function)
.
This class is scheduled to be removed in October 2019.
@Deprecated @Beta @GwtCompatible public abstract class TreeTraverser<T> extends java.lang.Object
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.
For Java 8 users: Because this is an abstract class, not an interface, you can't use a lambda expression to extend 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 |
TreeTraverser.BreadthFirstIterator
Deprecated.
|
private class |
TreeTraverser.PostOrderIterator
Deprecated.
|
private static class |
TreeTraverser.PostOrderNode<T>
Deprecated.
|
private class |
TreeTraverser.PreOrderIterator
Deprecated.
|
Constructor and Description |
---|
TreeTraverser()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
FluentIterable<T> |
breadthFirstTraversal(T root)
Deprecated.
Use
Traverser.breadthFirst(N) instead, which has the
same behavior. |
abstract java.lang.Iterable<T> |
children(T root)
Deprecated.
Returns the children of the specified node.
|
(package private) UnmodifiableIterator<T> |
postOrderIterator(T root)
Deprecated.
|
FluentIterable<T> |
postOrderTraversal(T root)
Deprecated.
Use
Traverser.depthFirstPostOrder(N) instead, which
has the same behavior. |
(package private) UnmodifiableIterator<T> |
preOrderIterator(T root)
Deprecated.
|
FluentIterable<T> |
preOrderTraversal(T root)
Deprecated.
Use
Traverser.depthFirstPreOrder(N) instead, which has
the same behavior. |
static <T> TreeTraverser<T> |
using(Function<T,? extends java.lang.Iterable<T>> nodeToChildrenFunction)
Deprecated.
Use
Traverser.forTree(com.google.common.graph.SuccessorsFunction<N>) instead. If you are using a
lambda, these methods have exactly the same signature. |
@Deprecated public static <T> TreeTraverser<T> using(Function<T,? extends java.lang.Iterable<T>> nodeToChildrenFunction)
Traverser.forTree(com.google.common.graph.SuccessorsFunction<N>)
instead. If you are using a
lambda, these methods have exactly the same signature.TreeTraverser
and implement its children(T)
method directly.public abstract java.lang.Iterable<T> children(T root)
@Deprecated public final FluentIterable<T> preOrderTraversal(T root)
Traverser.depthFirstPreOrder(N)
instead, which has
the same behavior.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.
UnmodifiableIterator<T> preOrderIterator(T root)
@Deprecated public final FluentIterable<T> postOrderTraversal(T root)
Traverser.depthFirstPostOrder(N)
instead, which
has the same behavior.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.
UnmodifiableIterator<T> postOrderIterator(T root)
@Deprecated public final FluentIterable<T> breadthFirstTraversal(T root)
Traverser.breadthFirst(N)
instead, which has the
same behavior.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.