ObserverMap

class ObserverMap<K : Any, V : Any>
kotlin.Any
   ↳ androidx.compose.ObserverMap

A map from a key to a set of values used for keeping the relation between some entities and a models changes of which this entities are observing.

Two main differences from a regular Map<K, Set>:

  1. Object.hashCode is not used, so the values can be mutable and change their hashCode value
  2. Objects are stored with WeakReference to prevent leaking them.

Summary

Public constructors

A map from a key to a set of values used for keeping the relation between some entities and a models changes of which this entities are observing.

Public methods

Unit
add(key: K, value: V)

Adds a value into a set associated with this key.

Unit

Clears all the keys and values from the map.

Unit
clearValues(predicate: (V) -> Boolean)

Clears all the values that match the given predicate from all the sets.

Boolean
contains(key: K, value: V)

Returns true when the map contains the given key and value

operator List<V>
get(keys: Iterable<K>)

List<V>
remove(key: K)

Removes all the values associated with this key.

Unit
remove(key: K, value: V)

Removes exact value from the set associated with this key.

Public constructors

<init>

ObserverMap()

A map from a key to a set of values used for keeping the relation between some entities and a models changes of which this entities are observing.

Two main differences from a regular Map<K, Set>:

  1. Object.hashCode is not used, so the values can be mutable and change their hashCode value
  2. Objects are stored with WeakReference to prevent leaking them.

Public methods

add

fun add(
    key: K,
    value: V
): Unit

Adds a value into a set associated with this key.

clear

fun clear(): Unit

Clears all the keys and values from the map.

clearValues

fun clearValues(predicate: (V) -> Boolean): Unit

Clears all the values that match the given predicate from all the sets.

contains

fun contains(
    key: K,
    value: V
): Boolean

Returns true when the map contains the given key and value

get

operator fun get(keys: Iterable<K>): List<V>
Return
a list of values associated with the provided keys.

remove

fun remove(key: K): List<V>

Removes all the values associated with this key.

Return
the list of values removed from the set as a result of this operation.

remove

fun remove(
    key: K,
    value: V
): Unit

Removes exact value from the set associated with this key.