SparseArrayKt

Added in 1.19.0

public final class SparseArrayKt


Summary

Public methods

static final boolean
<T extends Object> all(
    @NonNull SparseArray<@NonNull T> receiver,
    @NonNull Function2<@NonNull Integer, @NonNull value, @NonNull Boolean> predicate
)

Returns true if all entries match the given predicate.

static final boolean
<T extends Object> any(
    @NonNull SparseArray<@NonNull T> receiver,
    @NonNull Function2<@NonNull Integer, @NonNull value, @NonNull Boolean> predicate
)

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

static final boolean
<T extends Object> contains(@NonNull SparseArray<@NonNull T> receiver, int key)

Returns true if the collection contains key.

static final boolean
<T extends Object> containsKey(@NonNull SparseArray<@NonNull T> receiver, int key)

Returns true if the collection contains key.

static final boolean
<T extends Object> containsValue(
    @NonNull SparseArray<@NonNull T> receiver,
    @NonNull T value
)

Returns true if the collection contains value.

static final void
<T extends Object> forEach(
    @NonNull SparseArray<@NonNull T> receiver,
    @NonNull Function2<@NonNull Integer, @NonNull value, Unit> action
)

Performs the given action for each key/value entry.

static final @NonNull T
<T extends Object> getOrDefault(
    @NonNull SparseArray<@NonNull T> receiver,
    int key,
    @NonNull T defaultValue
)

Return the value corresponding to key, or defaultValue when not present.

static final @NonNull T
<T extends Object> getOrElse(
    @NonNull SparseArray<@NonNull T> receiver,
    int key,
    @NonNull Function0<@NonNull T> defaultValue
)

Return the value corresponding to key, or from defaultValue when not present.

static final @NonNull T
<T extends Object> getOrPut(
    @NonNull SparseArray<@NonNull T> receiver,
    int key,
    @NonNull Function0<@NonNull T> defaultValue
)

Return the value corresponding to key, or put the defaultValue into the collection when not present.

static final int
<T extends Object> getSize(@NonNull SparseArray<@NonNull T> receiver)

Returns the number of key/value pairs in the collection.

static final boolean
<T extends Object> isEmpty(@NonNull SparseArray<@NonNull T> receiver)

Return true when the collection contains no elements.

static final boolean
<T extends Object> isNotEmpty(@NonNull SparseArray<@NonNull T> receiver)

Return true when the collection contains elements.

static final @NonNull IntIterator
<T extends Object> keyIterator(@NonNull SparseArray<@NonNull T> receiver)

Return an iterator over the collection's keys.

static final boolean
<T extends Object> none(
    @NonNull SparseArray<@NonNull T> receiver,
    @NonNull Function2<@NonNull Integer, @NonNull value, @NonNull Boolean> predicate
)

Returns true if no entries match the given predicate.

static final @NonNull SparseArray<@NonNull T>
<T extends Object> plus(
    @NonNull SparseArray<@NonNull T> receiver,
    @NonNull SparseArray<@NonNull T> other
)

Creates a new collection by adding or replacing entries from other.

static final void
<T extends Object> putAll(
    @NonNull SparseArray<@NonNull T> receiver,
    @NonNull SparseArray<@NonNull T> other
)

Update this collection by adding or replacing entries from other.

static final boolean
<T extends Object> remove(
    @NonNull SparseArray<@NonNull T> receiver,
    int key,
    @NonNull T value
)

Removes the entry for key only if it is mapped to value.

static final void
<T extends Object> set(
    @NonNull SparseArray<@NonNull T> receiver,
    int key,
    @NonNull T value
)

Allows the use of the index operator for storing values in the collection.

static final @NonNull SparseArray<@NonNull T>
<T extends Object> sparseArrayOf()

Returns an empty SparseArray.

static final @NonNull SparseArray<@NonNull T>
<T extends Object> sparseArrayOf(
    @NonNull Pair<@NonNull Integer, @NonNull T>... pairs
)

Returns a new SparseArray filled with the specified pairs.

static final @NonNull Iterator<@NonNull T>
<T extends Object> valueIterator(@NonNull SparseArray<@NonNull T> receiver)

Return an iterator over the collection's values.

Public methods

public static final boolean <T extends Object> all(
    @NonNull SparseArray<@NonNull T> receiver,
    @NonNull Function2<@NonNull Integer, @NonNull value, @NonNull Boolean> predicate
)

Returns true if all entries match the given predicate.

public static final boolean <T extends Object> any(
    @NonNull SparseArray<@NonNull T> receiver,
    @NonNull Function2<@NonNull Integer, @NonNull value, @NonNull Boolean> predicate
)

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

contains

public static final boolean <T extends Object> contains(@NonNull SparseArray<@NonNull T> receiver, int key)

Returns true if the collection contains key.

containsKey

public static final boolean <T extends Object> containsKey(@NonNull SparseArray<@NonNull T> receiver, int key)

Returns true if the collection contains key.

containsValue

public static final boolean <T extends Object> containsValue(
    @NonNull SparseArray<@NonNull T> receiver,
    @NonNull T value
)

Returns true if the collection contains value.

forEach

public static final void <T extends Object> forEach(
    @NonNull SparseArray<@NonNull T> receiver,
    @NonNull Function2<@NonNull Integer, @NonNull value, Unit> action
)

Performs the given action for each key/value entry.

getOrDefault

public static final @NonNull T <T extends Object> getOrDefault(
    @NonNull SparseArray<@NonNull T> receiver,
    int key,
    @NonNull T defaultValue
)

Return the value corresponding to key, or defaultValue when not present.

getOrElse

public static final @NonNull T <T extends Object> getOrElse(
    @NonNull SparseArray<@NonNull T> receiver,
    int key,
    @NonNull Function0<@NonNull T> defaultValue
)

Return the value corresponding to key, or from defaultValue when not present.

getOrPut

public static final @NonNull T <T extends Object> getOrPut(
    @NonNull SparseArray<@NonNull T> receiver,
    int key,
    @NonNull Function0<@NonNull T> defaultValue
)

Return the value corresponding to key, or put the defaultValue into the collection when not present.

getSize

public static final int <T extends Object> getSize(@NonNull SparseArray<@NonNull T> receiver)

Returns the number of key/value pairs in the collection.

isEmpty

public static final boolean <T extends Object> isEmpty(@NonNull SparseArray<@NonNull T> receiver)

Return true when the collection contains no elements.

isNotEmpty

public static final boolean <T extends Object> isNotEmpty(@NonNull SparseArray<@NonNull T> receiver)

Return true when the collection contains elements.

keyIterator

public static final @NonNull IntIterator <T extends Object> keyIterator(@NonNull SparseArray<@NonNull T> receiver)

Return an iterator over the collection's keys.

public static final boolean <T extends Object> none(
    @NonNull SparseArray<@NonNull T> receiver,
    @NonNull Function2<@NonNull Integer, @NonNull value, @NonNull Boolean> predicate
)

Returns true if no entries match the given predicate.

plus

public static final @NonNull SparseArray<@NonNull T> <T extends Object> plus(
    @NonNull SparseArray<@NonNull T> receiver,
    @NonNull SparseArray<@NonNull T> other
)

Creates a new collection by adding or replacing entries from other.

putAll

public static final void <T extends Object> putAll(
    @NonNull SparseArray<@NonNull T> receiver,
    @NonNull SparseArray<@NonNull T> other
)

Update this collection by adding or replacing entries from other.

remove

public static final boolean <T extends Object> remove(
    @NonNull SparseArray<@NonNull T> receiver,
    int key,
    @NonNull T value
)

Removes the entry for key only if it is mapped to value.

set

public static final void <T extends Object> set(
    @NonNull SparseArray<@NonNull T> receiver,
    int key,
    @NonNull T value
)

Allows the use of the index operator for storing values in the collection.

sparseArrayOf

public static final @NonNull SparseArray<@NonNull T> <T extends Object> sparseArrayOf()

Returns an empty SparseArray.

sparseArrayOf

public static final @NonNull SparseArray<@NonNull T> <T extends Object> sparseArrayOf(
    @NonNull Pair<@NonNull Integer, @NonNull T>... pairs
)

Returns a new SparseArray filled with the specified pairs.

valueIterator

public static final @NonNull Iterator<@NonNull T> <T extends Object> valueIterator(@NonNull SparseArray<@NonNull T> receiver)

Return an iterator over the collection's values.