{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

SnapshotStateMap

public final class SnapshotStateMap<K extends Object, V extends Object> implements MutableMap, StateObject


An implementation of MutableMap that can be observed and snapshot. This is the result type created by androidx.compose.runtime.mutableStateMapOf.

This class closely implements the same semantics as HashMap.

See also
mutableStateMapOf

Summary

Public constructors

<K extends Object, V extends Object> SnapshotStateMap()

Public methods

void
boolean
boolean
V
get(@NonNull K key)
@NonNull Set<@NonNull Map.Entry<@NonNull K, @NonNull V>>
@NonNull StateRecord

The first state record in a linked list of state records.

@NonNull Set<@NonNull K>
int
@NonNull Collection<@NonNull V>
boolean
void

Add a new state record to the beginning of a list.

V
put(@NonNull K key, @NonNull V value)
void
putAll(@NonNull Map<@NonNull K, @NonNull V> from)
V
remove(@NonNull K key)
final @NonNull Map<@NonNull K, @NonNull V>

Returns an immutable map containing all key-value pairs from the original map.

Inherited methods

From androidx.compose.runtime.snapshots.StateObject
StateRecord
mergeRecords(
    @NonNull StateRecord previous,
    @NonNull StateRecord current,
    @NonNull StateRecord applied
)

Produce a merged state based on the conflicting state changes.

Public constructors

SnapshotStateMap

public <K extends Object, V extends Object> SnapshotStateMap()

Public methods

clear

public void clear()

containsKey

public boolean containsKey(@NonNull K key)

containsValue

public boolean containsValue(@NonNull V value)

get

public V get(@NonNull K key)

getEntries

public @NonNull Set<@NonNull Map.Entry<@NonNull K, @NonNull V>> getEntries()

getFirstStateRecord

public @NonNull StateRecord getFirstStateRecord()

The first state record in a linked list of state records.

getKeys

public @NonNull Set<@NonNull K> getKeys()

getSize

public int getSize()

getValues

public @NonNull Collection<@NonNull V> getValues()

isEmpty

public boolean isEmpty()

prependStateRecord

public void prependStateRecord(@NonNull StateRecord value)

Add a new state record to the beginning of a list. After this call firstStateRecord should be value.

put

public V put(@NonNull K key, @NonNull V value)

putAll

public void putAll(@NonNull Map<@NonNull K, @NonNull V> from)

remove

public V remove(@NonNull K key)

toMap

public final @NonNull Map<@NonNull K, @NonNull V> toMap()

Returns an immutable map containing all key-value pairs from the original map.

The content of the map returned will not change even if the content of the map is changed in the same snapshot. It also will be the same instance until the content is changed. It is not, however, guaranteed to be the same instance for the same content as adding and removing the same item from the this map might produce a different instance with the same content.

This operation is O(1) and does not involve a physically copying the map. It instead returns the underlying immutable map used internally to store the content of the map.

It is recommended to use toMap when using returning the value of this map from androidx.compose.runtime.snapshotFlow.