TreeIterables
  public
  
  final
  
  class
  TreeIterables
  
    extends Object
  
  
  
  
  
  
| java.lang.Object | |
| ↳ | android.support.test.espresso.util.TreeIterables | 
Utility methods for iterating over tree structured items.
Since the view hierarchy is a tree - having a method of iterating over its contents is useful.
This is generalized for any object which can display tree like qualities - but this generalization was done for testability concerns (since creating View hierarchies is a pain).
Only public methods of this utility class are considered public API of the test framework.
Summary
| Nested classes | |
|---|---|
| 
        
        
        
        
        class | TreeIterables.ViewAndDistanceRepresents the distance a given view is from the root view. | 
| Public methods | |
|---|---|
| 
        
        
        static
        
        
        Iterable<View> | 
      breadthFirstViewTraversal(View root)
      Returns an iterable which iterates thru the provided view and its children in a breadth-first, row-level-order traversal. | 
| 
        
        
        static
        
        
        Iterable<View> | 
      depthFirstViewTraversal(View root)
      Returns an iterable which iterates thru the provided view and its children in a depth-first, in-order traversal. | 
| 
        
        
        static
        
        
        Iterable<TreeIterables.ViewAndDistance> | 
      depthFirstViewTraversalWithDistance(View root)
      Creates an iterable that traverses the tree formed by the given root. | 
| Inherited methods | |
|---|---|
|  From
class 
  
    java.lang.Object
  
 | |
Public methods
breadthFirstViewTraversal
Iterable<View> breadthFirstViewTraversal (View root)
Returns an iterable which iterates thru the provided view and its children in a breadth-first, row-level-order traversal. That is to say that for a view such as: Root / | \ A R U /| |\ B D G N Will be iterated: Root, A, R, U, B, D, G, N
| Parameters | |
|---|---|
| root | View: the non-null, root view. | 
| Returns | |
|---|---|
| Iterable<View> | |
depthFirstViewTraversal
Iterable<View> depthFirstViewTraversal (View root)
Returns an iterable which iterates thru the provided view and its children in a depth-first, in-order traversal. That is to say that for a view such as: Root / | \ A R U /| |\ B D G N Will be iterated: Root, A, B, D, R, G, N, U.
| Parameters | |
|---|---|
| root | View: the non-null, root view. | 
| Returns | |
|---|---|
| Iterable<View> | |
depthFirstViewTraversalWithDistance
Iterable<TreeIterables.ViewAndDistance> depthFirstViewTraversalWithDistance (View root)
Creates an iterable that traverses the tree formed by the given root.
Along with iteration order, the distance from the root element is also tracked.
| Parameters | |
|---|---|
| root | View: the root view to track from. | 
| Returns | |
|---|---|
| Iterable<TreeIterables.ViewAndDistance> | An iterable of ViewAndDistance containing the view tree in a depth first order with the distance of a given node from the root. | 
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
