Package org.apache.log4j.helpers
Class COWArrayList<E>
java.lang.Object
org.apache.log4j.helpers.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.2.20
- Author:
- Ceki Gulcu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanbooleanaddAll(int index, Collection<? extends E> col) booleanaddAll(Collection<? extends E> c) voidaddIfAbsent(E e) E[]Return an array of type E[].voidclear()booleanbooleancontainsAll(Collection<?> c) get(int index) intbooleanisEmpty()iterator()intlistIterator(int index) remove(int index) booleanbooleanremoveAll(Collection<?> col) booleanretainAll(Collection<?> col) intsize()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, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
equals, hashCode, replaceAll, sort, spliterator
-
Constructor Details
-
COWArrayList
-
-
Method Details
-
size
public int size() -
isEmpty
public boolean isEmpty() -
contains
-
iterator
-
toArray
-
toArray
public <T> T[] toArray(T[] a) -
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:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceList<E>
-
addAll
-
addAll
-
removeAll
-
retainAll
-
clear
public void clear() -
get
-
set
-
add
-
remove
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOfin interfaceList<E>
-
listIterator
- Specified by:
listIteratorin interfaceList<E>
-
listIterator
- Specified by:
listIteratorin interfaceList<E>
-
subList
-