public class COWArrayList<E> extends Object implements 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:
COWArrayList<Integer> list = 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(Collection<? extends E> c) |
boolean |
addAll(int index,
Collection<? extends E> col) |
void |
addIfAbsent(E e) |
E[] |
asTypedArray()
Return an array of type E[].
|
void |
clear() |
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
E |
get(int index) |
int |
indexOf(Object o) |
boolean |
isEmpty() |
Iterator<E> |
iterator() |
int |
lastIndexOf(Object o) |
ListIterator<E> |
listIterator() |
ListIterator<E> |
listIterator(int index) |
E |
remove(int index) |
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> col) |
boolean |
retainAll(Collection<?> col) |
E |
set(int index,
E element) |
int |
size() |
List<E> |
subList(int fromIndex,
int toIndex) |
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
equals, hashCode, replaceAll, sort, spliterator
parallelStream, removeIf, stream
public COWArrayList(E[] modelArray)
public int size()
public boolean isEmpty()
public boolean contains(Object o)
public Object[] toArray()
public <T> T[] toArray(T[] a)
public E[] asTypedArray()
public void addIfAbsent(E e)
public boolean add(E e)
public boolean remove(Object o)
public boolean containsAll(Collection<?> c)
containsAll
in interface Collection<E>
containsAll
in interface List<E>
public boolean addAll(Collection<? extends E> c)
public boolean addAll(int index, Collection<? extends E> col)
public boolean removeAll(Collection<?> col)
public boolean retainAll(Collection<?> col)
public void clear()
public int lastIndexOf(Object o)
lastIndexOf
in interface List<E>
public ListIterator<E> listIterator()
listIterator
in interface List<E>
public ListIterator<E> listIterator(int index)
listIterator
in interface List<E>
Copyright © 1999–2023 QOS.CH Sarl (Switzerland). All rights reserved.