MutableLongList



MutableLongList is a MutableList-like collection for Long values. It allows storing and retrieving the elements without boxing. Immutable access is available through its base class LongList, 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

MutableLongList(initialCapacity: Int)

Creates a MutableLongList with a capacity of initialCapacity.

Cmn

Public functions

Boolean
add(element: Long)

Adds element to the MutableLongList and returns true.

Cmn
Unit
add(index: @IntRange(from = 0) Int, element: Long)

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

Cmn
inline Boolean
addAll(elements: LongArray)

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

Cmn
inline Boolean
addAll(elements: LongList)

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

Cmn
Boolean
addAll(index: @IntRange(from = 0) Int, elements: LongArray)

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

Cmn
Boolean
addAll(index: @IntRange(from = 0) Int, elements: LongList)

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

Cmn
Unit

Removes all elements in the MutableLongList.

Cmn
Unit
ensureCapacity(capacity: Int)

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

Cmn
inline operator Unit
minusAssign(element: Long)

remove from the MutableLongList

Cmn
operator Unit

Removes all elements from the MutableLongList.

Cmn
operator Unit
minusAssign(elements: LongList)

Removes all elements from the MutableLongList.

Cmn
inline operator Unit
plusAssign(element: Long)

add to the MutableLongList.

Cmn
inline operator Unit
plusAssign(elements: LongArray)

Adds all elements to the end of the MutableLongList.

Cmn
inline operator Unit
plusAssign(elements: LongList)

Adds all elements to the end of the MutableLongList.

Cmn
Boolean
remove(element: Long)

Removes element from the MutableLongList.

Cmn
Boolean
removeAll(elements: LongArray)

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

Cmn
Boolean
removeAll(elements: LongList)

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

Cmn
Long
removeAt(index: @IntRange(from = 0) Int)

Removes the element at the given index and returns it.

Cmn
Unit
removeRange(start: @IntRange(from = 0) Int, end: @IntRange(from = 0) Int)

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

Cmn
Boolean
retainAll(elements: LongArray)

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

Cmn
Boolean
retainAll(elements: LongList)

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

Cmn
operator Long
set(index: @IntRange(from = 0) Int, element: Long)

Sets the value at index to element.

Cmn
Unit

Sorts the MutableLongList elements in ascending order.

Cmn
Unit

Sorts the MutableLongList elements in descending order.

Cmn
Unit
trim(minCapacity: Int)

Reduces the internal storage.

Cmn

Public properties

Int

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

Cmn

Inherited functions

From androidx.collection.LongList
inline Boolean
any()

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

Cmn
inline Boolean
any(predicate: (element: Long) -> Boolean)

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

Cmn
Int
binarySearch(element: Int, fromIndex: Int, toIndex: Int)

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

Cmn
operator Boolean
contains(element: Long)

Returns true if the LongList contains element or false otherwise.

Cmn
Boolean
containsAll(elements: LongList)

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

Cmn
inline Int

Returns the number of elements in this list.

Cmn
inline Int
count(predicate: (element: Long) -> Boolean)

Counts the number of elements matching predicate.

Cmn
Long
elementAt(index: @IntRange(from = 0) Int)

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

Cmn
inline Long
elementAtOrElse(
    index: @IntRange(from = 0) Int,
    defaultValue: (index: Int) -> Long
)

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

Cmn
open operator Boolean
equals(other: Any?)

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

Cmn
Long

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

Cmn
inline Long
first(predicate: (element: Long) -> Boolean)

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

Cmn
inline R
<R : Any?> fold(initial: R, operation: (acc, element: Long) -> R)

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

Cmn
inline R
<R : Any?> foldIndexed(initial: R, operation: (index: Int, acc, element: Long) -> R)

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

Cmn
inline R
<R : Any?> foldRight(initial: R, operation: (element: Long, acc) -> R)

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

Cmn
inline R
<R : Any?> foldRightIndexed(
    initial: R,
    operation: (index: Int, element: Long, acc) -> R
)

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

Cmn
inline Unit
forEach(block: (element: Long) -> Unit)

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

Cmn
inline Unit
forEachIndexed(block: (index: Int, element: Long) -> Unit)

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

Cmn
inline Unit
forEachReversed(block: (element: Long) -> Unit)

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

Cmn
inline Unit
forEachReversedIndexed(block: (index: Int, element: Long) -> Unit)

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

Cmn
operator Long
get(index: @IntRange(from = 0) Int)

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

Cmn
open Int

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

Cmn
Int
indexOf(element: Long)

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

Cmn
inline Int
indexOfFirst(predicate: (element: Long) -> Boolean)

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

Cmn
inline Int
indexOfLast(predicate: (element: Long) -> Boolean)

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

Cmn
inline Boolean

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

Cmn
inline Boolean

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

Cmn
String
joinToString(
    separator: CharSequence,
    prefix: CharSequence,
    postfix: CharSequence,
    limit: Int,
    truncated: CharSequence
)

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

Cmn
inline String
joinToString(
    separator: CharSequence,
    prefix: CharSequence,
    postfix: CharSequence,
    limit: Int,
    truncated: CharSequence,
    crossinline transform: (Long) -> CharSequence
)

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

Cmn
Long

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

Cmn
inline Long
last(predicate: (element: Long) -> Boolean)

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

Cmn
Int
lastIndexOf(element: Long)

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

Cmn
inline Boolean

Returns true if the collection has no elements in it.

Cmn
inline Boolean
reversedAny(predicate: (element: Long) -> Boolean)

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

Cmn
open String

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

Cmn

Inherited properties

From androidx.collection.LongList
IntRange

Returns an IntRange of the valid indices for this LongList.

Cmn
Int

Returns the last valid index in the LongList.

Cmn
Int

The number of elements in the LongList.

Cmn

Public constructors

MutableLongList

MutableLongList(initialCapacity: Int = 16)

Creates a MutableLongList with a capacity of initialCapacity.

Public functions

add

fun add(element: Long): Boolean

Adds element to the MutableLongList and returns true.

add

fun add(index: @IntRange(from = 0) Int, element: Long): Unit

Adds element to the MutableLongList 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

inline fun addAll(elements: LongArray): Boolean

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

addAll

inline fun addAll(elements: LongList): Boolean

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

addAll

fun addAll(index: @IntRange(from = 0) Int, elements: LongArray): Boolean

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

Returns
Boolean

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

Throws
kotlin.IndexOutOfBoundsException

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

addAll

fun addAll(index: @IntRange(from = 0) Int, elements: LongList): Boolean

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

Returns
Boolean

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

Throws
kotlin.IndexOutOfBoundsException

if index isn't between 0 and size, inclusive

clear

fun clear(): Unit

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

See also
trim

ensureCapacity

fun ensureCapacity(capacity: Int): Unit

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

See also
trim

minusAssign

inline operator fun minusAssign(element: Long): Unit

remove from the MutableLongList

minusAssign

operator fun minusAssign(elements: LongArray): Unit

Removes all elements from the MutableLongList.

minusAssign

operator fun minusAssign(elements: LongList): Unit

Removes all elements from the MutableLongList.

plusAssign

inline operator fun plusAssign(element: Long): Unit

add to the MutableLongList.

plusAssign

inline operator fun plusAssign(elements: LongArray): Unit

Adds all elements to the end of the MutableLongList.

plusAssign

inline operator fun plusAssign(elements: LongList): Unit

Adds all elements to the end of the MutableLongList.

remove

fun remove(element: Long): Boolean

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

removeAll

fun removeAll(elements: LongArray): Boolean

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

removeAll

fun removeAll(elements: LongList): Boolean

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

removeAt

fun removeAt(index: @IntRange(from = 0) Int): Long

Removes the element at the given index and returns it.

Throws
kotlin.IndexOutOfBoundsException

if index isn't between 0 and lastIndex, inclusive

removeRange

fun removeRange(start: @IntRange(from = 0) Int, end: @IntRange(from = 0) Int): Unit

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

fun retainAll(elements: LongArray): Boolean

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

Returns
Boolean

true if the MutableLongList has changed.

retainAll

fun retainAll(elements: LongList): Boolean

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

Returns
Boolean

true if the MutableLongList has changed.

set

operator fun set(index: @IntRange(from = 0) Int, element: Long): Long

Sets the value at index to element.

Returns
Long

the previous value set at index

Throws
kotlin.IndexOutOfBoundsException

if index isn't between 0 and lastIndex, inclusive

sort

fun sort(): Unit

Sorts the MutableLongList elements in ascending order.

sortDescending

fun sortDescending(): Unit

Sorts the MutableLongList elements in descending order.

trim

fun trim(minCapacity: Int = _size): Unit

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

Public properties

capacity

val capacityInt

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

See also
ensureCapacity