public class COWArrayList<E>
extends java.lang.Object
implements java.util.List<E>
List
interface for use cases where iterations over the list vastly out-number modifications on the list.
Underneath, it wraps an instance of CopyOnWriteArrayList
and exposes a copy of the array used by that instance.
Typical use:
COWArrayListlist = new COWArrayList(new Integer[0]); // modify the list list.add(1); list.add(2); Integer[] intArray = list.asTypedArray(); int sum = 0; // iteration over the array is thread-safe for(int i = 0; i < intArray.length; i++) { sum != intArray[i]; }
If the list is not modified, then repetitive calls to asTypedArray()
, toArray()
and
toArray(Object[])
are guaranteed to be GC-free. Note that iterating over the list using
iterator()
and listIterator()
are not GC-free.
Constructor and Description |
---|
COWArrayList(E[] modelArray) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e) |
void |
add(int index,
E element) |
boolean |
addAll(java.util.Collection<? extends E> c) |
boolean |
addAll(int index,
java.util.Collection<? extends E> col) |
void |
addIfAbsent(E e) |
E[] |
asTypedArray()
Return an array of type E[].
|
void |
clear() |
boolean |
contains(java.lang.Object o) |
boolean |
containsAll(java.util.Collection<?> c) |
E |
get(int index) |
int |
indexOf(java.lang.Object o) |
boolean |
isEmpty() |
java.util.Iterator<E> |
iterator() |
int |
lastIndexOf(java.lang.Object o) |
java.util.ListIterator<E> |
listIterator() |
java.util.ListIterator<E> |
listIterator(int index) |
E |
remove(int index) |
boolean |
remove(java.lang.Object o) |
boolean |
removeAll(java.util.Collection<?> col) |
boolean |
retainAll(java.util.Collection<?> col) |
E |
set(int index,
E element) |
int |
size() |
java.util.List<E> |
subList(int fromIndex,
int toIndex) |
java.lang.Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
public COWArrayList(E[] modelArray)
public int size()
public boolean isEmpty()
public boolean contains(java.lang.Object o)
public java.util.Iterator<E> iterator()
public java.lang.Object[] toArray()
public <T> T[] toArray(T[] a)
public E[] asTypedArray()
public void addIfAbsent(E e)
public boolean add(E e)
public boolean remove(java.lang.Object o)
public boolean containsAll(java.util.Collection<?> c)
public boolean addAll(java.util.Collection<? extends E> c)
public boolean addAll(int index, java.util.Collection<? extends E> col)
addAll
in interface java.util.List<E>
public boolean removeAll(java.util.Collection<?> col)
public boolean retainAll(java.util.Collection<?> col)
public void clear()
public int indexOf(java.lang.Object o)
indexOf
in interface java.util.List<E>
public int lastIndexOf(java.lang.Object o)
lastIndexOf
in interface java.util.List<E>
public java.util.ListIterator<E> listIterator()
listIterator
in interface java.util.List<E>
public java.util.ListIterator<E> listIterator(int index)
listIterator
in interface java.util.List<E>
Copyright © 2010 - 2023 Adobe. All Rights Reserved