# LayoutElementMatcher

# LayoutElementMatcher

Artifact:[androidx.wear.protolayout:protolayout-testing](https://developer.android.com/jetpack/androidx/releases/wear-protolayout)  
[View Source](https://cs.android.com/search?q=file:androidx/wear/protolayout/testing/LayoutElementMatcher.kt+class:androidx.wear.protolayout.testing.LayoutElementMatcher)  
Added in[1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.3.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/wear/protolayout/testing/LayoutElementMatcher "View this page in Java")

<br />

```
class LayoutElementMatcher
```

<br />

*** ** * ** ***

Wrapper for element matcher lambdas that allows to build string explaining to the developer what conditions are being tested.

## Summary

|                                                                                                                                                                                                                                                                                                                                           ### Public constructors                                                                                                                                                                                                                                                                                                                                            |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [LayoutElementMatcher](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/testing/LayoutElementMatcher#LayoutElementMatcher(kotlin.String,kotlin.Function1))`(` ` description: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`,` ` matcher: (`[LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement)`) `->` `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) `)` Constructor for the Wrapper of element matcher lambdas that allows to build string explaining to the developer what conditions are being tested. |
| [LayoutElementMatcher](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/testing/LayoutElementMatcher#LayoutElementMatcher(kotlin.String,kotlin.Function2))`(` ` description: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`,` ` matcher: (`[LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement)`, `[TestContext](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/testing/TestContext)`) `->` `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) `)`                                   |

|                                                           ### Public functions                                                           |
|------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `infix `[LayoutElementMatcher](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/testing/LayoutElementMatcher)    | [and](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/testing/LayoutElementMatcher#and(androidx.wear.protolayout.testing.LayoutElementMatcher))`(other: `[LayoutElementMatcher](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/testing/LayoutElementMatcher)`)` Returns whether the given element is matched by both this and the other mather. |
| `operator `[LayoutElementMatcher](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/testing/LayoutElementMatcher) | [not](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/testing/LayoutElementMatcher#not())`()` Returns whether the given element does not match the matcher.                                                                                                                                                                                                               |
| `infix `[LayoutElementMatcher](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/testing/LayoutElementMatcher)    | [or](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/testing/LayoutElementMatcher#or(androidx.wear.protolayout.testing.LayoutElementMatcher))`(other: `[LayoutElementMatcher](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/testing/LayoutElementMatcher)`)` Returns whether the given element is matched by this or the other mather.         |

## Public constructors

### LayoutElementMatcher

Added in[1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.3.0)  

```
LayoutElementMatcher(
    description: String,
    matcher: (LayoutElementBuilders.LayoutElement) -> Boolean
)
```

Constructor for the Wrapper of element matcher lambdas that allows to build string explaining to the developer what conditions are being tested.  

|                                                                                                                         Parameters                                                                                                                          |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------|
| `description: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                                                                                                                                                            | a string explaining to the developer what conditions were being tested. |
| `matcher: (`[LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement)`) `->` `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | a lambda performing the actual logic of matching on the layout element. |

### LayoutElementMatcher

Added in[1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.3.0)  

```
LayoutElementMatcher(
    description: String,
    matcher: (LayoutElementBuilders.LayoutElement, TestContext) -> Boolean
)
```  

|                                                                                                                                                                                 Parameters                                                                                                                                                                                 |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `description: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)                                                                                                                                                                                                                                                                           | a string explaining to the developer what conditions were being tested.                                                                                                                           |
| `matcher: (`[LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement)`, `[TestContext](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/testing/TestContext)`) `->` `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | a lambda performing the actual logic of matching on the layout element, with a TextContext accessible for retrieving context data such as the dynamic data map for evaluating the dynamic values. |

## Public functions

### and

Added in[1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.3.0)  

```
infix fun and(other: LayoutElementMatcher): LayoutElementMatcher
```

Returns whether the given element is matched by both this and the other mather.  

|                                                               Parameters                                                               |
|----------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------|
| `other: `[LayoutElementMatcher](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/testing/LayoutElementMatcher) | mather that should also match in addition to current matcher. |

### not

Added in[1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.3.0)  

```
operator fun not(): LayoutElementMatcher
```

Returns whether the given element does not match the matcher.  

### or

Added in[1.3.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.3.0)  

```
infix fun or(other: LayoutElementMatcher): LayoutElementMatcher
```

Returns whether the given element is matched by this or the other mather.  

|                                                               Parameters                                                               |
|----------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------|
| `other: `[LayoutElementMatcher](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/testing/LayoutElementMatcher) | mather that can be tested to match if the current matcher does not. |