Class TreeTraverser<T>
- java.lang.Object
-
- com.google.common.collect.TreeTraverser<T>
-
@Deprecated @Beta @GwtCompatible public abstract class TreeTraverser<T> extends Object
Deprecated.UseTraverser
instead. All instance methods have their equivalent on the result ofTraverser.forTree(tree)
wheretree
implementsSuccessorsFunction
, which has a similar API aschildren(T)
or can be the same lambda function as passed intousing(Function)
.This class is scheduled to be removed in October 2019.
Views elements of a typeT
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:
Instead, you can pass a lambda expression to the// won't work TreeTraverser<NodeType> traverser = node -> node.getChildNodes();
using
factory method:TreeTraverser<NodeType> traverser = TreeTraverser.using(node -> node.getChildNodes());
- Since:
- 15.0
- Author:
- Louis Wasserman
-
-
Constructor Summary
Constructors Constructor Description TreeTraverser()
Deprecated.Constructor for use by subclasses.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description FluentIterable<T>
breadthFirstTraversal(T root)
Deprecated.UseTraverser.breadthFirst(N)
instead, which has the same behavior.abstract Iterable<T>
children(T root)
Deprecated.Returns the children of the specified node.FluentIterable<T>
postOrderTraversal(T root)
Deprecated.UseTraverser.depthFirstPostOrder(N)
instead, which has the same behavior.FluentIterable<T>
preOrderTraversal(T root)
Deprecated.UseTraverser.depthFirstPreOrder(N)
instead, which has the same behavior.static <T> TreeTraverser<T>
using(Function<T,? extends Iterable<T>> nodeToChildrenFunction)
Deprecated.
-
-
-
Constructor Detail
-
TreeTraverser
public TreeTraverser()
Deprecated.Constructor for use by subclasses.
-
-
Method Detail
-
using
@Deprecated public static <T> TreeTraverser<T> using(Function<T,? extends Iterable<T>> nodeToChildrenFunction)
Deprecated.UseTraverser.forTree(com.google.common.graph.SuccessorsFunction<N>)
instead. If you are using a lambda, these methods have exactly the same signature.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; subclassTreeTraverser
and implement itschildren(T)
method directly.- Since:
- 20.0
-
children
public abstract Iterable<T> children(T root)
Deprecated.Returns the children of the specified node. Must not contain null.
-
preOrderTraversal
@Deprecated public final FluentIterable<T> preOrderTraversal(T root)
Deprecated.UseTraverser.depthFirstPreOrder(N)
instead, which has the same behavior.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
@Deprecated public final FluentIterable<T> postOrderTraversal(T root)
Deprecated.UseTraverser.depthFirstPostOrder(N)
instead, which has the same behavior.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
@Deprecated public final FluentIterable<T> breadthFirstTraversal(T root)
Deprecated.UseTraverser.breadthFirst(N)
instead, which has the same behavior.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.
-
-