# StateBuilders.State.Builder

Artifact: [androidx.wear.protolayout:protolayout](https://developer.android.com/jetpack/androidx/releases/wear-protolayout) [View Source](https://cs.android.com/search?q=file:androidx/wear/protolayout/StateBuilders.java+class:androidx.wear.protolayout.StateBuilders.State.Builder) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

*** ** * ** ***

<br />

```
public final class StateBuilders.State.Builder
```

<br />

*** ** * ** ***

Builder for `https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State`

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State.Builder#Builder()()` Creates an instance of `https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State.Builder`. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State.Builder` | `@https://developer.android.com/reference/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 200) <T extends https://developer.android.com/reference/androidx/wear/protolayout/expression/DynamicBuilders.DynamicType> https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State.Builder#addKeyToValueMapping(androidx.wear.protolayout.expression.AppDataKey<T>,androidx.wear.protolayout.expression.DynamicDataBuilders.DynamicDataValue<T>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/expression/AppDataKey<T> sourceKey, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/expression/DynamicDataBuilders.DynamicDataValue<T> value )` Adds an entry into any shared state between the provider and renderer. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State.Builder` | `@https://developer.android.com/reference/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 200) https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State.Builder#addToStateMap(androidx.wear.protolayout.expression.DynamicDataPair<?>...)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html DynamicDataPair[] entries)` Adds the entries into any shared state between the provider and renderer. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State` | `https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State.Builder#build()()` Builds an instance from accumulated values. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State.Builder` | `@https://developer.android.com/reference/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 200) https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State.Builder#setStateMap(androidx.wear.protolayout.expression.DynamicDataMap)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/expression/DynamicDataMap map)` Sets the mapping for any shared state between the provider and renderer. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State.Builder` | `@https://developer.android.com/reference/androidx/wear/protolayout/expression/RequiresSchemaVersion(major = 1, minor = 200) https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State.Builder#setStateMap(androidx.wear.protolayout.expression.DynamicDataPair<?>...)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html DynamicDataPair[] pairs)` Sets the mapping for any shared state between the provider and renderer. |

## Public constructors

### Builder

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

```
public Builder()
```

Creates an instance of `https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State.Builder`.

## Public methods

### addKeyToValueMapping

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

```
@RequiresSchemaVersion(major = 1, minor = 200)
public @NonNull StateBuilders.State.Builder <T extends DynamicBuilders.DynamicType> addKeyToValueMapping(
    @NonNull AppDataKey<T> sourceKey,
    @NonNull DynamicDataBuilders.DynamicDataValue<T> value
)
```

Adds an entry into any shared state between the provider and renderer.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if adding the new key/value will make the state larger than the allowed limit (`https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State#getMaxStateEntryCount()`). |

### addToStateMap

```
@RequiresSchemaVersion(major = 1, minor = 200)
public @NonNull StateBuilders.State.Builder addToStateMap(@NonNull DynamicDataPair[] entries)
```

Adds the entries into any shared state between the provider and renderer.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if adding the new key/value will make the state larger than the allowed limit (`https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State#getMaxStateEntryCount()`). |

### build

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

```
public @NonNull StateBuilders.State build()
```

Builds an instance from accumulated values.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if number of key/value pairs are greater than `https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State#getMaxStateEntryCount()`. |

### setStateMap

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

```
@RequiresSchemaVersion(major = 1, minor = 200)
public @NonNull StateBuilders.State.Builder setStateMap(@NonNull DynamicDataMap map)
```

Sets the mapping for any shared state between the provider and renderer. This method replaces the current state map with the entries from `map`.Any previous entries added using this `https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State.Builder#setStateMap(androidx.wear.protolayout.expression.DynamicDataMap)` or `https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State.Builder#addKeyToValueMapping(androidx.wear.protolayout.expression.AppDataKey<T>,androidx.wear.protolayout.expression.DynamicDataBuilders.DynamicDataValue<T>)` will be overwritten.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if the size of `map` is larger than the allowed limit (`https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State#getMaxStateEntryCount()`). |

### setStateMap

```
@RequiresSchemaVersion(major = 1, minor = 200)
public @NonNull StateBuilders.State.Builder setStateMap(@NonNull DynamicDataPair[] pairs)
```

Sets the mapping for any shared state between the provider and renderer. This method replaces the current state map with the entries from `map`. Any previous entries added using this `https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State.Builder#setStateMap(androidx.wear.protolayout.expression.DynamicDataMap)` or `https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State.Builder#addKeyToValueMapping(androidx.wear.protolayout.expression.AppDataKey<T>,androidx.wear.protolayout.expression.DynamicDataBuilders.DynamicDataValue<T>)` will be overwritten.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if the size of `map` is larger than the allowed limit (`https://developer.android.com/reference/androidx/wear/protolayout/StateBuilders.State#getMaxStateEntryCount()`). |