# TreeIterables

Summary:[Nested Classes](https://developer.android.com/reference/android/support/test/espresso/util/TreeIterables#nestedclasses)\|[Methods](https://developer.android.com/reference/android/support/test/espresso/util/TreeIterables#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/test/espresso/util/TreeIterables#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/test/espresso/util/TreeIterables#)  

# TreeIterables

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public

final

class
TreeIterables
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object.html)`


``


`

|---|--------------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) ||
| ↳ | android.support.test.espresso.util.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 classes                                                                                                ||
|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` class` | [TreeIterables.ViewAndDistance](https://developer.android.com/reference/android/support/test/espresso/util/TreeIterables.ViewAndDistance) Represents the distance a given view is from the root view. |

|                                                                                                                                                                                                                                                                                                   ### Public methods                                                                                                                                                                                                                                                                                                    ||
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static `[Iterable](https://developer.android.com/reference/java/lang/Iterable.html)`<`[View](https://developer.android.com/reference/android/view/View.html)`>`                                                                    | ` `[breadthFirstViewTraversal](https://developer.android.com/reference/android/support/test/espresso/util/TreeIterables#breadthFirstViewTraversal(android.view.View))`(`[View](https://developer.android.com/reference/android/view/View.html)` root) ` Returns an iterable which iterates thru the provided view and its children in a breadth-first, row-level-order traversal. |
| ` static `[Iterable](https://developer.android.com/reference/java/lang/Iterable.html)`<`[View](https://developer.android.com/reference/android/view/View.html)`>`                                                                    | ` `[depthFirstViewTraversal](https://developer.android.com/reference/android/support/test/espresso/util/TreeIterables#depthFirstViewTraversal(android.view.View))`(`[View](https://developer.android.com/reference/android/view/View.html)` root) ` Returns an iterable which iterates thru the provided view and its children in a depth-first, in-order traversal.              |
| ` static `[Iterable](https://developer.android.com/reference/java/lang/Iterable.html)`<`[TreeIterables.ViewAndDistance](https://developer.android.com/reference/android/support/test/espresso/util/TreeIterables.ViewAndDistance)`>` | ` `[depthFirstViewTraversalWithDistance](https://developer.android.com/reference/android/support/test/espresso/util/TreeIterables#depthFirstViewTraversalWithDistance(android.view.View))`(`[View](https://developer.android.com/reference/android/view/View.html)` root) ` Creates an iterable that traverses the tree formed by the given root.                                 |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/test/espresso/util/TreeIterables#)From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object.html)` ` |-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object.html)          | ` clone() `                                                                                | | ` boolean`                                                                          | ` equals(`[Object](https://developer.android.com/reference/java/lang/Object.html)` arg0) ` | | ` void`                                                                             | ` finalize() `                                                                             | | ` final `[Class](https://developer.android.com/reference/java/lang/Class.html)`<?>` | ` getClass() `                                                                             | | ` int`                                                                              | ` hashCode() `                                                                             | | ` final void`                                                                       | ` notify() `                                                                               | | ` final void`                                                                       | ` notifyAll() `                                                                            | | ` `[String](https://developer.android.com/reference/java/lang/String.html)          | ` toString() `                                                                             | | ` final void`                                                                       | ` wait(long arg0, int arg1) `                                                              | | ` final void`                                                                       | ` wait(long arg0) `                                                                        | | ` final void`                                                                       | ` wait() `                                                                                 | ||

## 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

<br />

|                   Parameters                    ||
|--------|-----------------------------------------|
| `root` | `View`: the non-null, root view. <br /> |

|                                                                             Returns                                                                             ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------|--------|
| [Iterable](https://developer.android.com/reference/java/lang/Iterable.html)`<`[View](https://developer.android.com/reference/android/view/View.html)`>` | <br /> |

### 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.

<br />

|                   Parameters                    ||
|--------|-----------------------------------------|
| `root` | `View`: the non-null, root view. <br /> |

|                                                                             Returns                                                                             ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------|--------|
| [Iterable](https://developer.android.com/reference/java/lang/Iterable.html)`<`[View](https://developer.android.com/reference/android/view/View.html)`>` | <br /> |

### 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.

<br />

|                     Parameters                      ||
|--------|---------------------------------------------|
| `root` | `View`: the root view to track from. <br /> |

|                                                                                                                                                                              Returns                                                                                                                                                                               ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|
| [Iterable](https://developer.android.com/reference/java/lang/Iterable.html)`<`[TreeIterables.ViewAndDistance](https://developer.android.com/reference/android/support/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. <br /> |

-

  ## Classes

  - [ActivityLifecycles](https://developer.android.com/reference/android/support/test/espresso/util/ActivityLifecycles)
  - [EspressoOptional](https://developer.android.com/reference/android/support/test/espresso/util/EspressoOptional)
  - [HumanReadables](https://developer.android.com/reference/android/support/test/espresso/util/HumanReadables)
  - [TreeIterables](https://developer.android.com/reference/android/support/test/espresso/util/TreeIterables)
  - [TreeIterables.ViewAndDistance](https://developer.android.com/reference/android/support/test/espresso/util/TreeIterables.ViewAndDistance)