# TreeIterables

# TreeIterables

Artifact:[androidx.test.espresso:espresso-core](https://developer.android.com/jetpack/androidx/releases/test-espresso)  
[View Source](https://cs.android.com/search?q=file:androidx/test/espresso/util/TreeIterables.java+class:androidx.test.espresso.util.TreeIterables)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/test/espresso/util/TreeIterables "View this page in Java")

<br />

```
class TreeIterables
```

<br />

*** ** * ** ***

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 types                                                                                                |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `class `[TreeIterables.ViewAndDistance](https://developer.android.com/reference/kotlin/androidx/test/espresso/util/TreeIterables.ViewAndDistance) Represents the distance a given view is from the root view. |

|                                                                                                                                                                             ### Public functions                                                                                                                                                                             |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static (`[Mutable](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-iterable/index.html)`)`[Iterable](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterable/index.html)`<`[View](https://developer.android.com/reference/android/view/View.html)`!>!`                                                                    | [breadthFirstViewTraversal](https://developer.android.com/reference/kotlin/androidx/test/espresso/util/TreeIterables#breadthFirstViewTraversal(android.view.View))`(root: `[View](https://developer.android.com/reference/android/view/View.html)`!)` Returns an iterable which iterates thru the provided view and its children in a breadth-first, row-level-order traversal. |
| `java-static (`[Mutable](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-iterable/index.html)`)`[Iterable](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterable/index.html)`<`[View](https://developer.android.com/reference/android/view/View.html)`!>!`                                                                    | [depthFirstViewTraversal](https://developer.android.com/reference/kotlin/androidx/test/espresso/util/TreeIterables#depthFirstViewTraversal(android.view.View))`(root: `[View](https://developer.android.com/reference/android/view/View.html)`!)` Returns an iterable which iterates thru the provided view and its children in a depth-first, in-order traversal.              |
| `java-static (`[Mutable](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-iterable/index.html)`)`[Iterable](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterable/index.html)`<`[TreeIterables.ViewAndDistance](https://developer.android.com/reference/kotlin/androidx/test/espresso/util/TreeIterables.ViewAndDistance)`!>!` | [depthFirstViewTraversalWithDistance](https://developer.android.com/reference/kotlin/androidx/test/espresso/util/TreeIterables#depthFirstViewTraversalWithDistance(android.view.View))`(root: `[View](https://developer.android.com/reference/android/view/View.html)`!)` Creates an iterable that traverses the tree formed by the given root.                                 |

## Public functions

### breadthFirstViewTraversal

```
java-static fun breadthFirstViewTraversal(root: View!): (Mutable)Iterable<View!>!
```

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](https://developer.android.com/reference/android/view/View.html)`!` | the non-null, root view. |

### depthFirstViewTraversal

```
java-static fun depthFirstViewTraversal(root: View!): (Mutable)Iterable<View!>!
```

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](https://developer.android.com/reference/android/view/View.html)`!` | the non-null, root view. |

### depthFirstViewTraversalWithDistance

```
java-static fun depthFirstViewTraversalWithDistance(root: View!): (Mutable)Iterable<TreeIterables.ViewAndDistance!>!
```

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](https://developer.android.com/reference/android/view/View.html)`!` | the root view to track from. |

|                                                                                                                                                                             Returns                                                                                                                                                                              |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|
| `(`[Mutable](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-iterable/index.html)`)`[Iterable](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterable/index.html)`<`[TreeIterables.ViewAndDistance](https://developer.android.com/reference/kotlin/androidx/test/espresso/util/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. |