MutableObjectList
public final class MutableObjectList<E extends Object> extends ObjectList
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
| See also | |
|---|---|
ObjectList |
|
MutableFloatList |
|
MutableIntList |
Summary
Public constructors |
|---|
<E extends Object> MutableObjectList(int initialCapacity) |
Public methods |
|
|---|---|
final boolean |
Adds |
final void |
Adds |
final boolean |
Adds all |
final boolean |
Adds all |
final boolean |
Adds all |
final boolean |
addAll(@NonNull ObjectList<@NonNull E> elements)Adds all |
final boolean |
addAll(@NonNull ScatterSet<@NonNull E> elements)Adds all |
final boolean |
Adds all |
final boolean |
Adds all |
final boolean |
addAll(@IntRange(from = 0) int index, @NonNull Collection<@NonNull E> elements)Adds all |
final boolean |
addAll(@IntRange(from = 0) int index, @NonNull ObjectList<@NonNull E> elements)Adds all |
@NonNull List<@NonNull E> |
asList()Returns a |
final @NonNull List<@NonNull E> |
Returns a |
final void |
clear()Removes all elements in the |
final void |
ensureCapacity(int capacity)Ensures that there is enough space to store |
final int |
Returns the total number of elements that can be held before the |
final void |
minusAssign(@NonNull E element)
|
final void |
minusAssign(@NonNull E[] elements)Removes all |
final void |
minusAssign(@NonNull Iterable<@NonNull E> elements)Removes all |
final void |
minusAssign(@NonNull List<@NonNull E> elements)Removes all |
final void |
minusAssign(@NonNull ObjectList<@NonNull E> elements)Removes all |
final void |
minusAssign(@NonNull ScatterSet<@NonNull E> elements)Removes all |
final void |
minusAssign(@NonNull Sequence<@NonNull E> elements)Removes all |
final void |
plusAssign(@NonNull E element)
|
final void |
plusAssign(@NonNull E[] elements)Adds all |
final void |
plusAssign(@NonNull Iterable<@NonNull E> elements)Adds all |
final void |
plusAssign(@NonNull List<@NonNull E> elements)Adds all |
final void |
plusAssign(@NonNull ObjectList<@NonNull E> elements)Adds all |
final void |
plusAssign(@NonNull ScatterSet<@NonNull E> elements)Adds all |
final void |
plusAssign(@NonNull Sequence<@NonNull E> elements)Adds all |
final boolean |
Removes |
final boolean |
Removes all |
final boolean |
Removes all |
final boolean |
Removes all |
final boolean |
removeAll(@NonNull ObjectList<@NonNull E> elements)Removes all |
final boolean |
removeAll(@NonNull ScatterSet<@NonNull E> elements)Removes all |
final boolean |
Removes all |
final @NonNull E |
Removes the element at the given |
final void |
Removes all elements in this list for which |
final void |
removeRange(@IntRange(from = 0) int start, @IntRange(from = 0) int end)Removes elements from index |
final boolean |
Keeps only |
final boolean |
retainAll(@NonNull Collection<@NonNull E> elements)Keeps only |
final boolean |
Keeps only |
final boolean |
retainAll(@NonNull ObjectList<@NonNull E> elements)Keeps only |
final boolean |
Keeps only |
final @NonNull E |
|
final void |
trim(int minCapacity)Reduces the internal storage. |
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Public constructors
Public methods
add
public final boolean add(@NonNull E element)
Adds element to the MutableObjectList and returns true.
add
public final void add(@IntRange(from = 0) int index, @NonNull E element)
Adds element to the MutableObjectList at the given index, shifting over any elements at index and after, if any.
addAll
public final boolean addAll(@NonNull E[] elements)
Adds all elements to the end of the MutableObjectList and returns true if the MutableObjectList was changed or false if elements was empty.
addAll
public final boolean addAll(@NonNull Iterable<@NonNull E> elements)
Adds all elements to the end of the MutableObjectList and returns true if the MutableObjectList was changed or false if elements was empty.
addAll
public final boolean addAll(@NonNull List<@NonNull E> elements)
Adds all elements to the end of the MutableObjectList and returns true if the MutableObjectList was changed or false if elements was empty.
addAll
public final boolean addAll(@NonNull ObjectList<@NonNull E> elements)
Adds all elements to the end of the MutableObjectList and returns true if the MutableObjectList was changed or false if elements was empty.
addAll
public final boolean addAll(@NonNull ScatterSet<@NonNull E> elements)
Adds all elements to the end of the MutableObjectList and returns true if the MutableObjectList was changed or false if elements was empty.
addAll
public final boolean addAll(@NonNull Sequence<@NonNull E> elements)
Adds all elements to the end of the MutableObjectList and returns true if the MutableObjectList was changed or false if elements was empty.
addAll
public final boolean addAll(@IntRange(from = 0) int index, @NonNull E[] elements)
Adds all elements to the MutableObjectList at the given index, shifting over any elements at index and after, if any.
| Returns | |
|---|---|
boolean |
|
addAll
public final boolean addAll(@IntRange(from = 0) int index, @NonNull Collection<@NonNull E> elements)
Adds all elements to the MutableObjectList at the given index, shifting over any elements at index and after, if any.
| Returns | |
|---|---|
boolean |
|
addAll
public final boolean addAll(@IntRange(from = 0) int index, @NonNull ObjectList<@NonNull E> elements)
Adds all elements to the MutableObjectList at the given index, shifting over any elements at index and after, if any.
| Returns | |
|---|---|
boolean |
|
asList
public @NonNull List<@NonNull E> asList()
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
public final @NonNull List<@NonNull E> asMutableList()
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
public final void clear()
Removes all elements in the MutableObjectList. The storage isn't released.
| See also | |
|---|---|
trim |
ensureCapacity
public final void ensureCapacity(int capacity)
Ensures that there is enough space to store capacity elements in the MutableObjectList.
| See also | |
|---|---|
trim |
getCapacity
public final int getCapacity()
Returns the total number of elements that can be held before the MutableObjectList must grow.
| See also | |
|---|---|
ensureCapacity |
minusAssign
public final void minusAssign(@NonNull E element)
remove from the MutableObjectList
minusAssign
public final void minusAssign(@NonNull E[] elements)
Removes all elements from the MutableObjectList.
minusAssign
public final void minusAssign(@NonNull Iterable<@NonNull E> elements)
Removes all elements from the MutableObjectList.
minusAssign
public final void minusAssign(@NonNull List<@NonNull E> elements)
Removes all elements from the MutableObjectList.
minusAssign
public final void minusAssign(@NonNull ObjectList<@NonNull E> elements)
Removes all elements from the MutableObjectList.
minusAssign
public final void minusAssign(@NonNull ScatterSet<@NonNull E> elements)
Removes all elements from the MutableObjectList.
minusAssign
public final void minusAssign(@NonNull Sequence<@NonNull E> elements)
Removes all elements from the MutableObjectList.
plusAssign
public final void plusAssign(@NonNull E element)
add to the MutableObjectList.
plusAssign
public final void plusAssign(@NonNull E[] elements)
Adds all elements to the end of the MutableObjectList.
plusAssign
public final void plusAssign(@NonNull Iterable<@NonNull E> elements)
Adds all elements to the end of the MutableObjectList.
plusAssign
public final void plusAssign(@NonNull List<@NonNull E> elements)
Adds all elements to the end of the MutableObjectList.
plusAssign
public final void plusAssign(@NonNull ObjectList<@NonNull E> elements)
Adds all elements to the end of the MutableObjectList.
plusAssign
public final void plusAssign(@NonNull ScatterSet<@NonNull E> elements)
Adds all elements to the end of the MutableObjectList.
plusAssign
public final void plusAssign(@NonNull Sequence<@NonNull E> elements)
Adds all elements to the end of the MutableObjectList.
remove
public final boolean remove(@NonNull E element)
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
public final boolean removeAll(@NonNull E[] elements)
Removes all elements from the MutableObjectList and returns true if anything was removed.
removeAll
public final boolean removeAll(@NonNull Iterable<@NonNull E> elements)
Removes all elements from the MutableObjectList and returns true if anything was removed.
removeAll
public final boolean removeAll(@NonNull List<@NonNull E> elements)
Removes all elements from the MutableObjectList and returns true if anything was removed.
removeAll
public final boolean removeAll(@NonNull ObjectList<@NonNull E> elements)
Removes all elements from the MutableObjectList and returns true if anything was removed.
removeAll
public final boolean removeAll(@NonNull ScatterSet<@NonNull E> elements)
Removes all elements from the MutableObjectList and returns true if anything was removed.
removeAll
public final boolean removeAll(@NonNull Sequence<@NonNull E> elements)
Removes all elements from the MutableObjectList and returns true if anything was removed.
removeAt
public final @NonNull E removeAt(@IntRange(from = 0) int index)
Removes the element at the given index and returns it.
removeIf
public final void removeIf(@NonNull Function1<@NonNull element, @NonNull Boolean> predicate)
Removes all elements in this list for which predicate returns true.
removeRange
public final void removeRange(@IntRange(from = 0) int start, @IntRange(from = 0) int end)
Removes elements from index start (inclusive) to end (exclusive).
retainAll
public final boolean retainAll(@NonNull E[] elements)
Keeps only elements in the MutableObjectList and removes all other values.
| Returns | |
|---|---|
boolean |
|
retainAll
public final boolean retainAll(@NonNull Collection<@NonNull E> elements)
Keeps only elements in the MutableObjectList and removes all other values.
| Returns | |
|---|---|
boolean |
|
retainAll
public final boolean retainAll(@NonNull Iterable<@NonNull E> elements)
Keeps only elements in the MutableObjectList and removes all other values.
| Returns | |
|---|---|
boolean |
|
retainAll
public final boolean retainAll(@NonNull ObjectList<@NonNull E> elements)
Keeps only elements in the MutableObjectList and removes all other values.
| Returns | |
|---|---|
boolean |
|
retainAll
public final boolean retainAll(@NonNull Sequence<@NonNull E> elements)
Keeps only elements in the MutableObjectList and removes all other values.
| Returns | |
|---|---|
boolean |
|
set
public final @NonNull E set(@IntRange(from = 0) int index, @NonNull E element)
trim
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 |