java.lang.Object
ch.qos.logback.core.util.COWArrayList<E>
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,List<E>
A GC-free lock-free thread-safe implementation of the
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.
- Since:
- 1.1.10
- Author:
- Ceki Gulcu
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
boolean
addAll
(int index, Collection<? extends E> col) boolean
addAll
(Collection<? extends E> c) void
addIfAbsent
(E e) E[]
Return an array of type E[].void
clear()
boolean
boolean
containsAll
(Collection<?> c) get
(int index) int
boolean
isEmpty()
iterator()
int
listIterator
(int index) remove
(int index) boolean
boolean
removeAll
(Collection<?> col) boolean
retainAll
(Collection<?> col) int
size()
subList
(int fromIndex, int toIndex) Object[]
toArray()
<T> T[]
toArray
(T[] a) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
equals, hashCode, replaceAll, sort, spliterator
-
Constructor Details
-
COWArrayList
-
-
Method Details
-
size
-
isEmpty
-
contains
-
iterator
-
toArray
-
toArray
-
asTypedArray
Return an array of type E[]. The returned array is intended to be iterated over. If the list is modified, subsequent calls to this method will return different/modified array instances.- Returns:
-
addIfAbsent
-
add
-
remove
-
containsAll
- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceList<E>
-
addAll
-
addAll
-
removeAll
-
retainAll
-
clear
-
get
-
set
-
add
-
remove
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOf
in interfaceList<E>
-
listIterator
- Specified by:
listIterator
in interfaceList<E>
-
listIterator
- Specified by:
listIterator
in interfaceList<E>
-
subList
-