MutableObjectFloatMap


public final class MutableObjectFloatMap<K extends Object> extends ObjectFloatMap


MutableObjectFloatMap is a container with a MutableMap-like interface for keys with reference types and Float primitives for values.

The underlying implementation is designed to avoid allocations from boxing, and insertion, removal, retrieval, and iteration operations. Allocations may still happen on insertion when the underlying storage needs to grow to accommodate newly added entries to the table. In addition, this implementation minimizes memory usage by avoiding the use of separate objects to hold key/value pairs.

This implementation is not thread-safe: if multiple threads access this container concurrently, and one or more threads modify the structure of the map (insertion or removal for instance), the calling code must provide the appropriate synchronization. Multiple threads are safe to read from this map concurrently if no write is happening.

Summary

Public constructors

<K extends Object> MutableObjectFloatMap(int initialCapacity)

Creates a new MutableObjectFloatMap

Public methods

final void

Removes all mappings from this map.

final float
getOrPut(@NonNull K key, @NonNull Function0<@NonNull Float> defaultValue)

Returns the value to which the specified key is mapped, if the value is present in the map.

final void

Removes the specified key and its associated value from the map.

final void
minusAssign(@NonNull K[] keys)

Removes the specified keys and their associated value from the map.

final void

Removes the specified keys and their associated value from the map.

final void

Removes the specified keys and their associated value from the map.

final void

Removes the specified keys and their associated value from the map.

final void

Puts all the key/value mappings in the from map into this map.

final void
put(@NonNull K key, float value)

Creates a new mapping from key to value in this map.

final float
put(@NonNull K key, float value, float default)

Creates a new mapping from key to value in this map.

final void

Puts all the key/value mappings in the from map into this map.

final void
remove(@NonNull K key)

Removes the specified key and its associated value from the map.

final boolean
remove(@NonNull K key, float value)

Removes the specified key and its associated value from the map if the associated value equals value.

final void
removeIf(
    @NonNull Function2<@NonNull K, @NonNull Float, @NonNull Boolean> predicate
)

Removes any mapping for which the specified predicate returns true.

final void
set(@NonNull K key, float value)

Creates a new mapping from key to value in this map.

final int

Trims this MutableObjectFloatMap's storage so it is sized appropriately to hold the current mappings.

Inherited methods

From androidx.collection.ObjectFloatMap
final boolean
all(
    @NonNull Function2<@NonNull K, @NonNull Float, @NonNull Boolean> predicate
)

Returns true if all entries match the given predicate.

final boolean
any()

Returns true if this map has at least one entry.

final boolean
any(
    @NonNull Function2<@NonNull K, @NonNull Float, @NonNull Boolean> predicate
)

Returns true if at least one entry matches the given predicate.

final boolean
contains(@NonNull K key)

Returns true if the specified key is present in this map, false otherwise.

final boolean

Returns true if the specified key is present in this map, false otherwise.

final boolean
containsValue(float value)

Returns true if the specified value is present in this map, false otherwise.

final int

Returns the number of entries in this map.

final int
count(
    @NonNull Function2<@NonNull K, @NonNull Float, @NonNull Boolean> predicate
)

Returns the number of entries matching the given predicate.

boolean
equals(Object other)

Compares the specified object other with this hash map for equality.

final void
forEach(@NonNull Function2<@NonNull key, @NonNull FloatUnit> block)

Iterates over every key/value pair stored in this map by invoking the specified block lambda.

final void
forEachKey(@NonNull Function1<@NonNull key, Unit> block)

Iterates over every key stored in this map by invoking the specified block lambda.

final void
forEachValue(@NonNull Function1<@NonNull FloatUnit> block)

Iterates over every value stored in this map by invoking the specified block lambda.

final float
get(@NonNull K key)

Returns the value corresponding to the given key, or throws if the key is not present in the map.

final int

Returns the number of key-value pairs that can be stored in this map without requiring internal storage reallocation.

final float
getOrDefault(@NonNull K key, float defaultValue)

Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.

final float
getOrElse(@NonNull K key, @NonNull Function0<@NonNull Float> defaultValue)

Returns the value for the given key if the value is present.

final int

Returns the number of key-value pairs in this map.

int

Returns the hash code value for this map.

final boolean

Indicates whether this map is empty.

final boolean

Returns true if this map is not empty.

final @NonNull String
joinToString(
    @NonNull CharSequence separator,
    @NonNull CharSequence prefix,
    @NonNull CharSequence postfix,
    int limit,
    @NonNull CharSequence truncated
)

Creates a String from the entries, separated by separator and using prefix before and postfix after, if supplied.

final @NonNull String
joinToString(
    @NonNull CharSequence separator,
    @NonNull CharSequence prefix,
    @NonNull CharSequence postfix,
    int limit,
    @NonNull CharSequence truncated,
    @NonNull Function2<@NonNull key, @NonNull Float, @NonNull CharSequence> transform
)

Creates a String from the entries, separated by separator and using prefix before and postfix after, if supplied.

final boolean

Returns true if this map has no entries.

@NonNull String

Returns a string representation of this map.

Public constructors

MutableObjectFloatMap

public <K extends Object> MutableObjectFloatMap(int initialCapacity)

Creates a new MutableObjectFloatMap

Parameters
int initialCapacity

The initial desired capacity for this container. the container will honor this value by guaranteeing its internal structures can hold that many entries without requiring any allocations. The initial capacity can be set to 0.

Public methods

clear

Added in 1.4.0
public final void clear()

Removes all mappings from this map.

getOrPut

Added in 1.4.0
public final float getOrPut(@NonNull K key, @NonNull Function0<@NonNull Float> defaultValue)

Returns the value to which the specified key is mapped, if the value is present in the map. Otherwise, calls defaultValue() and puts the result in the map associated with key.

minusAssign

Added in 1.4.0
public final void minusAssign(@NonNull K key)

Removes the specified key and its associated value from the map.

minusAssign

Added in 1.4.0
public final void minusAssign(@NonNull K[] keys)

Removes the specified keys and their associated value from the map.

minusAssign

public final void minusAssign(@NonNull Iterable<@NonNull K> keys)

Removes the specified keys and their associated value from the map.

minusAssign

Added in 1.4.0
public final void minusAssign(@NonNull ScatterSet<@NonNull K> keys)

Removes the specified keys and their associated value from the map.

minusAssign

public final void minusAssign(@NonNull Sequence<@NonNull K> keys)

Removes the specified keys and their associated value from the map.

plusAssign

Added in 1.4.0
public final void plusAssign(@NonNull ObjectFloatMap<@NonNull K> from)

Puts all the key/value mappings in the from map into this map.

put

Added in 1.4.0
public final void put(@NonNull K key, float value)

Creates a new mapping from key to value in this map. If key is already present in the map, the association is modified and the previously associated value is replaced with value. If key is not present, a new entry is added to the map, which may require to grow the underlying storage and cause allocations.

put

Added in 1.4.0
public final float put(@NonNull K key, float value, float default)

Creates a new mapping from key to value in this map. If key is already present in the map, the association is modified and the previously associated value is replaced with value. If key is not present, a new entry is added to the map, which may require to grow the underlying storage and cause allocations.

Returns
float

value previously associated with key or default if key was not present.

putAll

Added in 1.4.0
public final void putAll(@NonNull ObjectFloatMap<@NonNull K> from)

Puts all the key/value mappings in the from map into this map.

remove

Added in 1.4.0
public final void remove(@NonNull K key)

Removes the specified key and its associated value from the map.

remove

Added in 1.4.0
public final boolean remove(@NonNull K key, float value)

Removes the specified key and its associated value from the map if the associated value equals value. Returns whether the removal happened.

removeIf

Added in 1.4.0
public final void removeIf(
    @NonNull Function2<@NonNull K, @NonNull Float, @NonNull Boolean> predicate
)

Removes any mapping for which the specified predicate returns true.

set

Added in 1.4.0
public final void set(@NonNull K key, float value)

Creates a new mapping from key to value in this map. If key is already present in the map, the association is modified and the previously associated value is replaced with value. If key is not present, a new entry is added to the map, which may require to grow the underlying storage and cause allocations.

trim

Added in 1.4.0
public final int trim()

Trims this MutableObjectFloatMap's storage so it is sized appropriately to hold the current mappings.

Returns the number of empty entries removed from this map's storage. Returns be 0 if no trimming is necessary or possible.