Package com.pnfsoftware.jeb.util.collect
Class ConcurrentList<T>
java.lang.Object
com.pnfsoftware.jeb.util.collect.ConcurrentList<T>
- Type Parameters:
T-
- All Implemented Interfaces:
Iterable<T>,Collection<T>,List<T>,SequencedCollection<T>
A concurrent version of
ArrayList. Unlike CopyOnWriteArrayList, only
iterator-returning operations return defensive copies. Other write operations (addition,
insertion, deletion) do not generate defensive copies. Also contains safe versions of
add/set/get for convenience. Performing much better than CopyOnWriteArrayList if write
operations are frequent; get() operations are slightly slower than
CopyOnWriteArrayList's, so if they make up the majority of the invocations,
CopyOnWriteArrayList remains the best option.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidMay raiseArrayIndexOutOfBoundsExceptionif index is greater than the list's size by the time the lock is acquired.booleanbooleanaddAll(int index, Collection<? extends T> c) May raiseArrayIndexOutOfBoundsExceptionif index is greater than the list's size by the time the lock is acquired.booleanaddAll(Collection<? extends T> c) booleanvoidclear()booleanbooleancontainsAll(Collection<?> c) booleanget(int index) May raiseArrayIndexOutOfBoundsExceptionif index is greater or equals than the list's size by the time the lock is acquired.inthashCode()intbooleanisEmpty()iterator()Returns an iterator that will iterate over a defensive copy.intReturns a list iterator that will iterate over a defensive copy.listIterator(int index) Returns a list iterator that will iterate over a defensive copy.remove(int index) May raiseArrayIndexOutOfBoundsExceptionif index is greater or equals than the list's size by the time the lock is acquired.booleanbooleanremoveAll(Collection<?> c) booleanremoveSafe(int index) booleanretainAll(Collection<?> c) May raiseArrayIndexOutOfBoundsExceptionif index is greater or equals than the list's size by the time the lock is acquired.booleanintsize()subList(int fromIndex, int toIndex) Returns a defensive copy.Object[]toArray()<U> U[]toArray(U[] a) toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addFirst, addLast, getFirst, getLast, removeFirst, removeLast, replaceAll, reversed, sort, spliterator
-
Constructor Details
-
ConcurrentList
public ConcurrentList() -
ConcurrentList
public ConcurrentList(int initialCapacity) -
ConcurrentList
-
-
Method Details
-
isEmpty
public boolean isEmpty() -
size
public int size() -
get
May raiseArrayIndexOutOfBoundsExceptionif index is greater or equals than the list's size by the time the lock is acquired. Safe version:getSafe(int, Object). -
getSafe
-
set
May raiseArrayIndexOutOfBoundsExceptionif index is greater or equals than the list's size by the time the lock is acquired. Safe version:setSafe(int, Object). -
setSafe
-
add
May raiseArrayIndexOutOfBoundsExceptionif index is greater than the list's size by the time the lock is acquired. Safe version:addSafe(int, Object). -
addSafe
-
add
-
addAll
-
addAll
May raiseArrayIndexOutOfBoundsExceptionif index is greater than the list's size by the time the lock is acquired. -
contains
-
containsAll
- Specified by:
containsAllin interfaceCollection<T>- Specified by:
containsAllin interfaceList<T>
-
clear
public void clear() -
remove
-
remove
May raiseArrayIndexOutOfBoundsExceptionif index is greater or equals than the list's size by the time the lock is acquired. Safe version:removeSafe(int). -
removeSafe
public boolean removeSafe(int index) -
removeAll
-
retainAll
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOfin interfaceList<T>
-
toArray
-
toArray
public <U> U[] toArray(U[] a) -
subList
Returns a defensive copy. Modification operations will not impact the original list. -
listIterator
Returns a list iterator that will iterate over a defensive copy. Modification operations will not impact the original list.- Specified by:
listIteratorin interfaceList<T>
-
listIterator
Returns a list iterator that will iterate over a defensive copy. Modification operations will not impact the original list.- Specified by:
listIteratorin interfaceList<T>
-
iterator
Returns an iterator that will iterate over a defensive copy. Modification operations will not impact the original list. -
hashCode
public int hashCode() -
equals
-
toString
-