ObjectFloatMap


public sealed class ObjectFloatMap<K extends Object>

Known direct subclasses
MutableObjectFloatMap

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


ObjectFloatMap is a container with a Map-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 makes no guarantee as to the order of the keys and values stored, nor does it make guarantees that the order remains constant over time.

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.

This implementation is read-only and only allows data to be queried. A mutable implementation is provided by MutableObjectFloatMap.

Summary

Protected constructors

<K extends Object> ObjectFloatMap()

Public methods

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.

Protected constructors

ObjectFloatMap

protected <K extends Object> ObjectFloatMap()

Public methods

all

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

Returns true if all entries match the given predicate.

any

Added in 1.4.0
public final boolean any()

Returns true if this map has at least one entry.

any

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

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

contains

Added in 1.4.0
public final boolean contains(@NonNull K key)

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

containsKey

Added in 1.4.0
public final boolean containsKey(@NonNull K key)

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

containsValue

Added in 1.4.0
public final boolean containsValue(float value)

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

count

Added in 1.4.0
public final int count()

Returns the number of entries in this map.

count

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

Returns the number of entries matching the given predicate.

equals

public boolean equals(Object other)

Compares the specified object other with this hash map for equality. The two objects are considered equal if other:

  • Is a ObjectFloatMap

  • Has the same size as this map

  • Contains key/value pairs equal to this map's pair

forEach

Added in 1.4.0
public 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.

forEachKey

Added in 1.4.0
public final void forEachKey(@NonNull Function1<@NonNull key, Unit> block)

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

forEachValue

Added in 1.4.0
public final void forEachValue(@NonNull Function1<@NonNull FloatUnit> block)

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

get

Added in 1.4.0
public 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.

Throws
kotlin.NoSuchElementException

when key is not found

getCapacity

Added in 1.4.0
public final int getCapacity()

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

getOrDefault

Added in 1.4.0
public 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.

getOrElse

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

Returns the value for the given key if the value is present. Otherwise, returns the result of the defaultValue function.

getSize

Added in 1.4.0
public final int getSize()

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

hashCode

public int hashCode()

Returns the hash code value for this map. The hash code the sum of the hash codes of each key/value pair.

isEmpty

Added in 1.4.0
public final boolean isEmpty()

Indicates whether this map is empty.

isNotEmpty

Added in 1.4.0
public final boolean isNotEmpty()

Returns true if this map is not empty.

joinToString

Added in 1.4.0
public 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.

When a non-negative value of limit is provided, a maximum of limit items are used to generate the string. If the collection holds more than limit items, the string is terminated with truncated.

joinToString

public 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. Each entry is created with transform.

When a non-negative value of limit is provided, a maximum of limit items are used to generate the string. If the collection holds more than limit items, the string is terminated with truncated.

none

Added in 1.4.0
public final boolean none()

Returns true if this map has no entries.

toString

public @NonNull String toString()

Returns a string representation of this map. The map is denoted in the string by the {}. Each key/value pair present in the map is represented inside '{}by a substring of the form key=value, and pairs are separated by , `.