MutableFloatList


public final class MutableFloatList extends FloatList


MutableFloatList is a MutableList-like collection for Float values. It allows storing and retrieving the elements without boxing. Immutable access is available through its base class FloatList, which has a List-like interface.

This implementation is not thread-safe: if multiple threads access this container concurrently, and one or more threads modify the structure of the list (insertion or removal for instance), the calling code must provide the appropriate synchronization. It is also not safe to mutate during reentrancy -- in the middle of a forEach, for example. However, concurrent reads are safe.

Summary

Public constructors

MutableFloatList(int initialCapacity)

Creates a MutableFloatList with a capacity of initialCapacity.

Public methods

final boolean
add(float element)

Adds element to the MutableFloatList and returns true.

final void
add(@IntRange(from = 0) int index, float element)

Adds element to the MutableFloatList at the given index, shifting over any elements at index and after, if any.

final boolean
addAll(@NonNull float[] elements)

Adds all elements to the end of the MutableFloatList and returns true if the MutableFloatList was changed or false if elements was empty.

final boolean

Adds all elements to the end of the MutableFloatList and returns true if the MutableFloatList was changed or false if elements was empty.

final boolean
addAll(@IntRange(from = 0) int index, @NonNull float[] elements)

Adds all elements to the MutableFloatList at the given index, shifting over any elements at index and after, if any.

final boolean
addAll(@IntRange(from = 0) int index, @NonNull FloatList elements)

Adds all elements to the MutableFloatList at the given index, shifting over any elements at index and after, if any.

final void

Removes all elements in the MutableFloatList.

final void
ensureCapacity(int capacity)

Ensures that there is enough space to store capacity elements in the MutableFloatList.

final int

Returns the total number of elements that can be held before the MutableFloatList must grow.

final void
minusAssign(float element)

remove from the MutableFloatList

final void
minusAssign(@NonNull float[] elements)

Removes all elements from the MutableFloatList.

final void

Removes all elements from the MutableFloatList.

final void
plusAssign(float element)

add to the MutableFloatList.

final void
plusAssign(@NonNull float[] elements)

Adds all elements to the end of the MutableFloatList.

final void

Adds all elements to the end of the MutableFloatList.

final boolean
remove(float element)

Removes element from the MutableFloatList.

final boolean
removeAll(@NonNull float[] elements)

Removes all elements from the MutableFloatList and returns true if anything was removed.

final boolean

Removes all elements from the MutableFloatList and returns true if anything was removed.

final float
removeAt(@IntRange(from = 0) int index)

Removes the element at the given index and returns it.

final void
removeRange(@IntRange(from = 0) int start, @IntRange(from = 0) int end)

Removes items from index start (inclusive) to end (exclusive).

final boolean
retainAll(@NonNull float[] elements)

Keeps only elements in the MutableFloatList and removes all other values.

final boolean

Keeps only elements in the MutableFloatList and removes all other values.

final float
set(@IntRange(from = 0) int index, float element)

Sets the value at index to element.

final void

Sorts the MutableFloatList elements in ascending order.

final void

Sorts the MutableFloatList elements in descending order.

final void
trim(int minCapacity)

Reduces the internal storage.

Inherited methods

From androidx.collection.FloatList
final boolean
any()

Returns true if there's at least one element in the collection.

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

Returns true if any of the elements give a true return value for predicate.

final int
binarySearch(int element, int fromIndex, int toIndex)

Searches this list the specified element in the range defined by fromIndex and toIndex.

final boolean
contains(float element)

Returns true if the FloatList contains element or false otherwise.

final boolean

Returns true if the FloatList contains all elements in elements or false if one or more are missing.

final int

Returns the number of elements in this list.

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

Counts the number of elements matching predicate.

final float
elementAt(@IntRange(from = 0) int index)

Returns the element at the given index or throws IndexOutOfBoundsException if the index is out of bounds of this collection.

final float
elementAtOrElse(
    @IntRange(from = 0) int index,
    @NonNull Function1<@NonNull Integer, @NonNull Float> defaultValue
)

Returns the element at the given index or defaultValue if index is out of bounds of the collection.

boolean
equals(Object other)

Returns true if other is a FloatList and the contents of this and other are the same.

final float

Returns the first element in the FloatList or throws a NoSuchElementException if it isEmpty.

final float
first(@NonNull Function1<@NonNull Float, @NonNull Boolean> predicate)

Returns the first element in the FloatList for which predicate returns true or throws NoSuchElementException if nothing matches.

final @NonNull R
<R extends Object> fold(
    @NonNull R initial,
    @NonNull Function2<@NonNull acc, @NonNull Float, @NonNull R> operation
)

Accumulates values, starting with initial, and applying operation to each element in the FloatList in order.

final @NonNull R
<R extends Object> foldIndexed(
    @NonNull R initial,
    @NonNull Function3<@NonNull Integer, @NonNull acc, @NonNull Float, @NonNull R> operation
)

Accumulates values, starting with initial, and applying operation to each element in the FloatList in order.

final @NonNull R
<R extends Object> foldRight(
    @NonNull R initial,
    @NonNull Function2<@NonNull Float, @NonNull acc, @NonNull R> operation
)

Accumulates values, starting with initial, and applying operation to each element in the FloatList in reverse order.

final @NonNull R
<R extends Object> foldRightIndexed(
    @NonNull R initial,
    @NonNull Function3<@NonNull Integer, @NonNull Float, @NonNull acc, @NonNull R> operation
)

Accumulates values, starting with initial, and applying operation to each element in the FloatList in reverse order.

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

Calls block for each element in the FloatList, in order.

final void
forEachIndexed(
    @NonNull Function2<@NonNull Integer, @NonNull FloatUnit> block
)

Calls block for each element in the FloatList along with its index, in order.

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

Calls block for each element in the FloatList in reverse order.

final void
forEachReversedIndexed(
    @NonNull Function2<@NonNull Integer, @NonNull FloatUnit> block
)

Calls block for each element in the FloatList along with its index, in reverse order.

final float
get(@IntRange(from = 0) int index)

Returns the element at the given index or throws IndexOutOfBoundsException if the index is out of bounds of this collection.

final @NonNull IntRange

Returns an IntRange of the valid indices for this FloatList.

final @IntRange(from = -1) int

Returns the last valid index in the FloatList.

final @IntRange(from = 0) int

The number of elements in the FloatList.

int

Returns a hash code based on the contents of the FloatList.

final int
indexOf(float element)

Returns the index of element in the FloatList or -1 if element is not there.

final int
indexOfFirst(@NonNull Function1<@NonNull Float, @NonNull Boolean> predicate)

Returns the index if the first element in the FloatList for which predicate returns true.

final int
indexOfLast(@NonNull Function1<@NonNull Float, @NonNull Boolean> predicate)

Returns the index if the last element in the FloatList for which predicate returns true.

final boolean

Returns true if the FloatList has no elements in it or false otherwise.

final boolean

Returns true if there are elements in the FloatList or false if it is empty.

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

Creates a String from the elements 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 Function1<@NonNull Float, @NonNull CharSequence> transform
)

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

final float

Returns the last element in the FloatList or throws a NoSuchElementException if it isEmpty.

final float
last(@NonNull Function1<@NonNull Float, @NonNull Boolean> predicate)

Returns the last element in the FloatList for which predicate returns true or throws NoSuchElementException if nothing matches.

final int
lastIndexOf(float element)

Returns the index of the last element in the FloatList that is the same as element or -1 if no elements match.

final boolean

Returns true if the collection has no elements in it.

final boolean
reversedAny(@NonNull Function1<@NonNull Float, @NonNull Boolean> predicate)

Returns true if any of the elements give a true return value for predicate while iterating in the reverse order.

@NonNull String

Returns a String representation of the list, surrounded by "[]" and each element separated by ", ".

Public constructors

MutableFloatList

Added in 1.4.0
public MutableFloatList(int initialCapacity)

Creates a MutableFloatList with a capacity of initialCapacity.

Public methods

add

Added in 1.4.0
public final boolean add(float element)

Adds element to the MutableFloatList and returns true.

add

Added in 1.4.0
public final void add(@IntRange(from = 0) int index, float element)

Adds element to the MutableFloatList at the given index, shifting over any elements at index and after, if any.

Throws
kotlin.IndexOutOfBoundsException

if index isn't between 0 and size, inclusive

addAll

Added in 1.4.0
public final boolean addAll(@NonNull float[] elements)

Adds all elements to the end of the MutableFloatList and returns true if the MutableFloatList was changed or false if elements was empty.

addAll

Added in 1.4.0
public final boolean addAll(@NonNull FloatList elements)

Adds all elements to the end of the MutableFloatList and returns true if the MutableFloatList was changed or false if elements was empty.

addAll

Added in 1.4.0
public final boolean addAll(@IntRange(from = 0) int index, @NonNull float[] elements)

Adds all elements to the MutableFloatList at the given index, shifting over any elements at index and after, if any.

Returns
boolean

true if the MutableFloatList was changed or false if elements was empty

Throws
kotlin.IndexOutOfBoundsException

if index isn't between 0 and size, inclusive.

addAll

Added in 1.4.0
public final boolean addAll(@IntRange(from = 0) int index, @NonNull FloatList elements)

Adds all elements to the MutableFloatList at the given index, shifting over any elements at index and after, if any.

Returns
boolean

true if the MutableFloatList was changed or false if elements was empty

Throws
kotlin.IndexOutOfBoundsException

if index isn't between 0 and size, inclusive

clear

Added in 1.4.0
public final void clear()

Removes all elements in the MutableFloatList. The storage isn't released.

See also
trim

ensureCapacity

Added in 1.4.0
public final void ensureCapacity(int capacity)

Ensures that there is enough space to store capacity elements in the MutableFloatList.

See also
trim

getCapacity

Added in 1.4.0
public final int getCapacity()

Returns the total number of elements that can be held before the MutableFloatList must grow.

See also
ensureCapacity

minusAssign

Added in 1.4.0
public final void minusAssign(float element)

remove from the MutableFloatList

minusAssign

Added in 1.4.0
public final void minusAssign(@NonNull float[] elements)

Removes all elements from the MutableFloatList.

minusAssign

Added in 1.4.0
public final void minusAssign(@NonNull FloatList elements)

Removes all elements from the MutableFloatList.

plusAssign

Added in 1.4.0
public final void plusAssign(float element)

add to the MutableFloatList.

plusAssign

Added in 1.4.0
public final void plusAssign(@NonNull float[] elements)

Adds all elements to the end of the MutableFloatList.

plusAssign

Added in 1.4.0
public final void plusAssign(@NonNull FloatList elements)

Adds all elements to the end of the MutableFloatList.

remove

Added in 1.4.0
public final boolean remove(float element)

Removes element from the MutableFloatList. If element was in the MutableFloatList and was removed, true will be returned, or false will be returned if the element was not found.

removeAll

Added in 1.4.0
public final boolean removeAll(@NonNull float[] elements)

Removes all elements from the MutableFloatList and returns true if anything was removed.

removeAll

Added in 1.4.0
public final boolean removeAll(@NonNull FloatList elements)

Removes all elements from the MutableFloatList and returns true if anything was removed.

removeAt

Added in 1.4.0
public final float removeAt(@IntRange(from = 0) int index)

Removes the element at the given index and returns it.

Throws
kotlin.IndexOutOfBoundsException

if index isn't between 0 and lastIndex, inclusive

removeRange

Added in 1.4.0
public final void removeRange(@IntRange(from = 0) int start, @IntRange(from = 0) int end)

Removes items from index start (inclusive) to end (exclusive).

Throws
kotlin.IndexOutOfBoundsException

if start or end isn't between 0 and size, inclusive

kotlin.IllegalArgumentException

if start is greater than end

retainAll

Added in 1.4.0
public final boolean retainAll(@NonNull float[] elements)

Keeps only elements in the MutableFloatList and removes all other values.

Returns
boolean

true if the MutableFloatList has changed.

retainAll

Added in 1.4.0
public final boolean retainAll(@NonNull FloatList elements)

Keeps only elements in the MutableFloatList and removes all other values.

Returns
boolean

true if the MutableFloatList has changed.

set

Added in 1.4.0
public final float set(@IntRange(from = 0) int index, float element)

Sets the value at index to element.

Returns
float

the previous value set at index

Throws
kotlin.IndexOutOfBoundsException

if index isn't between 0 and lastIndex, inclusive

sort

Added in 1.4.0
public final void sort()

Sorts the MutableFloatList elements in ascending order.

sortDescending

Added in 1.4.0
public final void sortDescending()

Sorts the MutableFloatList elements in descending order.

trim

Added in 1.4.0
public final void trim(int minCapacity)

Reduces the internal storage. If capacity is greater than minCapacity and size, the internal storage is reduced to the maximum of size and minCapacity.

See also
ensureCapacity