MutableObjectList



MutableObjectList is a MutableList-like collection for reference types. It is optimized for fast access, avoiding virtual and interface method access. Methods avoid allocation whenever possible. For example forEach does not need allocate an Iterator.

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.

Note List access is available through asList when developers need access to the common API.

Note MutableList access is available through asMutableList when developers need access to the common API.

It is best to use this for all internal implementations where a list of reference types is needed. Use MutableList in public API to take advantage of the commonly-used interface. It is common to use MutableObjectList internally and use asMutableList or asList to get a MutableList or List interface for interacting with public APIs.

MutableLongList

Summary

Public constructors

<E : Any?> MutableObjectList(initialCapacity: Int)
Cmn

Public functions

Boolean
add(element: E)

Adds element to the MutableObjectList and returns true.

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

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

Cmn
Boolean
addAll(elements: Array<E>)

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

Cmn
Boolean
addAll(elements: Iterable<E>)

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

Cmn
Boolean
addAll(elements: List<E>)

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

Cmn
Boolean
addAll(elements: ObjectList<E>)

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

Cmn
Boolean
addAll(elements: ScatterSet<E>)

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

Cmn
Boolean
addAll(elements: Sequence<E>)

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

Cmn
Boolean
addAll(index: @IntRange(from = 0) Int, elements: Array<E>)

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

Cmn
Boolean
addAll(index: @IntRange(from = 0) Int, elements: Collection<E>)

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

Cmn
Boolean
addAll(index: @IntRange(from = 0) Int, elements: ObjectList<E>)

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

Cmn
open List<E>

Returns a List view into the ObjectList.

Cmn
MutableList<E>

Returns a MutableList view into the MutableObjectList.

Cmn
Unit

Removes all elements in the MutableObjectList.

Cmn
Unit
ensureCapacity(capacity: Int)

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

Cmn
inline operator Unit
minusAssign(element: E)

remove from the MutableObjectList

Cmn
operator Unit
minusAssign(elements: Array<E>)

Removes all elements from the MutableObjectList.

Cmn
operator Unit
minusAssign(elements: Iterable<E>)

Removes all elements from the MutableObjectList.

Cmn
operator Unit
minusAssign(elements: List<E>)

Removes all elements from the MutableObjectList.

Cmn
operator Unit
minusAssign(elements: ObjectList<E>)

Removes all elements from the MutableObjectList.

Cmn
operator Unit
minusAssign(elements: ScatterSet<E>)

Removes all elements from the MutableObjectList.

Cmn
operator Unit
minusAssign(elements: Sequence<E>)

Removes all elements from the MutableObjectList.

Cmn
inline operator Unit
plusAssign(element: E)

add to the MutableObjectList.

Cmn
operator Unit
plusAssign(elements: Array<E>)

Adds all elements to the end of the MutableObjectList.

Cmn
operator Unit
plusAssign(elements: Iterable<E>)

Adds all elements to the end of the MutableObjectList.

Cmn
operator Unit
plusAssign(elements: List<E>)

Adds all elements to the end of the MutableObjectList.

Cmn
operator Unit
plusAssign(elements: ObjectList<E>)

Adds all elements to the end of the MutableObjectList.

Cmn
operator Unit
plusAssign(elements: ScatterSet<E>)

Adds all elements to the end of the MutableObjectList.

Cmn
operator Unit
plusAssign(elements: Sequence<E>)

Adds all elements to the end of the MutableObjectList.

Cmn
Boolean
remove(element: E)

Removes element from the MutableObjectList.

Cmn
Boolean
removeAll(elements: Array<E>)

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

Cmn
Boolean
removeAll(elements: Iterable<E>)

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

Cmn
Boolean
removeAll(elements: List<E>)

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

Cmn
Boolean
removeAll(elements: ObjectList<E>)

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

Cmn
Boolean
removeAll(elements: ScatterSet<E>)

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

Cmn
Boolean
removeAll(elements: Sequence<E>)

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

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

Removes the element at the given index and returns it.

Cmn
inline Unit
removeIf(predicate: (element) -> Boolean)

Removes all elements in this list for which predicate returns true.

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

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

Cmn
Boolean
retainAll(elements: Array<E>)

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

Cmn
Boolean
retainAll(elements: Collection<E>)

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

Cmn
Boolean
retainAll(elements: Iterable<E>)

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

Cmn
Boolean
retainAll(elements: ObjectList<E>)

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

Cmn
Boolean
retainAll(elements: Sequence<E>)

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

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

Sets the value at index to element.

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 MutableObjectList must grow.

Cmn

Inherited functions

From androidx.collection.ObjectList
Boolean
any()

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

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

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

Cmn
operator Boolean
contains(element: E)

Returns true if the ObjectList contains element or false otherwise.

Cmn
Boolean
containsAll(elements: Array<E>)

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

Cmn
Boolean
containsAll(elements: Iterable<E>)

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

Cmn
Boolean
containsAll(elements: List<E>)

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

Cmn
Boolean
containsAll(elements: ObjectList<E>)

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

Cmn
Int

Returns the number of elements in this list.

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

Counts the number of elements matching predicate.

Cmn
E
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 E
elementAtOrElse(index: @IntRange(from = 0) Int, defaultValue: (index: Int) -> E)

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 ObjectList and the contents of this and other are the same.

Cmn
E

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

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

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

Cmn
inline E?

Returns the first element in the ObjectList or null if it isEmpty.

Cmn
inline E?
firstOrNull(predicate: (element) -> Boolean)

Returns the first element in the ObjectList for which predicate returns true or null if nothing matches.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Cmn
operator E
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 ObjectList.

Cmn
Int
indexOf(element: E)

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

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

Returns the index if the first element in the ObjectList for which predicate returns true or -1 if there was no element for which predicate returned true.

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

Returns the index if the last element in the ObjectList for which predicate returns true or -1 if there was no element for which predicate returned true.

Cmn
Boolean

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

Cmn
Boolean

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

Cmn
String
joinToString(
    separator: CharSequence,
    prefix: CharSequence,
    postfix: CharSequence,
    limit: Int,
    truncated: CharSequence,
    transform: ((E) -> CharSequence)?
)

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

Cmn
E

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

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

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

Cmn
Int
lastIndexOf(element: E)

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

Cmn
inline E?

Returns the last element in the ObjectList or null if it isEmpty.

Cmn
inline E?
lastOrNull(predicate: (element) -> Boolean)

Returns the last element in the ObjectList for which predicate returns true or null if nothing matches.

Cmn
Boolean

Returns true if the collection has no elements in it.

Cmn
inline Boolean
reversedAny(predicate: (element) -> 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.ObjectList
IntRange

Returns an IntRange of the valid indices for this ObjectList.

Cmn
Int

Returns the last valid index in the ObjectList.

Cmn
Int

The number of elements in the ObjectList.

Cmn

Public constructors

MutableObjectList

<E : Any?> MutableObjectList(initialCapacity: Int = 16)

Public functions

add

fun add(element: E): Boolean

Adds element to the MutableObjectList and returns true.

add

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

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

fun addAll(elements: Array<E>): Boolean

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

addAll

fun addAll(elements: Iterable<E>): Boolean

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

addAll

fun addAll(elements: List<E>): Boolean

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

addAll

fun addAll(elements: ObjectList<E>): Boolean

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

addAll

fun addAll(elements: ScatterSet<E>): Boolean

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

addAll

fun addAll(elements: Sequence<E>): Boolean

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

addAll

fun addAll(index: @IntRange(from = 0) Int, elements: Array<E>): Boolean

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

Returns
Boolean

true if the MutableObjectList 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: Collection<E>): Boolean

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

Returns
Boolean

true if the MutableObjectList 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: ObjectList<E>): Boolean

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

Returns
Boolean

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

Throws
kotlin.IndexOutOfBoundsException

if index isn't between 0 and size, inclusive

asList

open fun asList(): List<E>

Returns a List view into the ObjectList. All access to the collection will be less efficient and abides by the allocation requirements of the List. For example, List.forEach will allocate an iterator. All access will go through the more expensive interface calls. Critical performance areas should use the ObjectList API rather than List API, when possible.

asMutableList

fun asMutableList(): MutableList<E>

Returns a MutableList view into the MutableObjectList. All access to the collection will be less efficient and abides by the allocation requirements of the MutableList. For example, MutableList.forEach will allocate an iterator. All access will go through the more expensive interface calls. Critical performance areas should use the MutableObjectList API rather than MutableList API, when possible.

clear

fun clear(): Unit

Removes all elements in the MutableObjectList. 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 MutableObjectList.

See also
trim

minusAssign

inline operator fun minusAssign(element: E): Unit

remove from the MutableObjectList

minusAssign

operator fun minusAssign(elements: Array<E>): Unit

Removes all elements from the MutableObjectList.

minusAssign

operator fun minusAssign(elements: Iterable<E>): Unit

Removes all elements from the MutableObjectList.

minusAssign

operator fun minusAssign(elements: List<E>): Unit

Removes all elements from the MutableObjectList.

minusAssign

operator fun minusAssign(elements: ObjectList<E>): Unit

Removes all elements from the MutableObjectList.

minusAssign

operator fun minusAssign(elements: ScatterSet<E>): Unit

Removes all elements from the MutableObjectList.

minusAssign

operator fun minusAssign(elements: Sequence<E>): Unit

Removes all elements from the MutableObjectList.

plusAssign

inline operator fun plusAssign(element: E): Unit

add to the MutableObjectList.

plusAssign

operator fun plusAssign(elements: Array<E>): Unit

Adds all elements to the end of the MutableObjectList.

plusAssign

operator fun plusAssign(elements: Iterable<E>): Unit

Adds all elements to the end of the MutableObjectList.

plusAssign

operator fun plusAssign(elements: List<E>): Unit

Adds all elements to the end of the MutableObjectList.

plusAssign

operator fun plusAssign(elements: ObjectList<E>): Unit

Adds all elements to the end of the MutableObjectList.

plusAssign

operator fun plusAssign(elements: ScatterSet<E>): Unit

Adds all elements to the end of the MutableObjectList.

plusAssign

operator fun plusAssign(elements: Sequence<E>): Unit

Adds all elements to the end of the MutableObjectList.

remove

fun remove(element: E): Boolean

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

removeAll

fun removeAll(elements: Array<E>): Boolean

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

removeAll

fun removeAll(elements: Iterable<E>): Boolean

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

removeAll

fun removeAll(elements: List<E>): Boolean

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

removeAll

fun removeAll(elements: ObjectList<E>): Boolean

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

removeAll

fun removeAll(elements: ScatterSet<E>): Boolean

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

removeAll

fun removeAll(elements: Sequence<E>): Boolean

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

removeAt

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

Removes the element at the given index and returns it.

Throws
kotlin.IndexOutOfBoundsException

if index isn't between 0 and lastIndex, inclusive

removeIf

inline fun removeIf(predicate: (element) -> Boolean): Unit

Removes all elements in this list for which predicate returns true.

removeRange

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

Removes elements 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: Array<E>): Boolean

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

Returns
Boolean

true if the MutableObjectList has changed.

retainAll

fun retainAll(elements: Collection<E>): Boolean

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

Returns
Boolean

true if the MutableObjectList has changed.

retainAll

fun retainAll(elements: Iterable<E>): Boolean

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

Returns
Boolean

true if the MutableObjectList has changed.

retainAll

fun retainAll(elements: ObjectList<E>): Boolean

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

Returns
Boolean

true if the MutableObjectList has changed.

retainAll

fun retainAll(elements: Sequence<E>): Boolean

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

Returns
Boolean

true if the MutableObjectList has changed.

set

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

Sets the value at index to element.

Returns
E

the previous value set at index

Throws
kotlin.IndexOutOfBoundsException

if index isn't between 0 and lastIndex, inclusive

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 MutableObjectList must grow.

See also
ensureCapacity