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>
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 TypeMethodDescriptionvoid
May raiseArrayIndexOutOfBoundsException
if index is greater than the list's size by the time the lock is acquired.boolean
boolean
addAll
(int index, Collection<? extends T> c) May raiseArrayIndexOutOfBoundsException
if index is greater than the list's size by the time the lock is acquired.boolean
addAll
(Collection<? extends T> c) boolean
void
clear()
boolean
boolean
containsAll
(Collection<?> c) boolean
get
(int index) May raiseArrayIndexOutOfBoundsException
if index is greater or equals than the list's size by the time the lock is acquired.int
hashCode()
int
boolean
isEmpty()
iterator()
Returns an iterator that will iterate over a defensive copy.int
Returns 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 raiseArrayIndexOutOfBoundsException
if index is greater or equals than the list's size by the time the lock is acquired.boolean
boolean
removeAll
(Collection<?> c) boolean
removeSafe
(int index) boolean
retainAll
(Collection<?> c) May raiseArrayIndexOutOfBoundsException
if index is greater or equals than the list's size by the time the lock is acquired.boolean
int
size()
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, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
replaceAll, 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 raiseArrayIndexOutOfBoundsException
if 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 raiseArrayIndexOutOfBoundsException
if 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 raiseArrayIndexOutOfBoundsException
if 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 raiseArrayIndexOutOfBoundsException
if index is greater than the list's size by the time the lock is acquired. -
contains
-
containsAll
- Specified by:
containsAll
in interfaceCollection<T>
- Specified by:
containsAll
in interfaceList<T>
-
clear
public void clear() -
remove
-
remove
May raiseArrayIndexOutOfBoundsException
if 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:
lastIndexOf
in 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:
listIterator
in interfaceList<T>
-
listIterator
Returns a list iterator that will iterate over a defensive copy. Modification operations will not impact the original list.- Specified by:
listIterator
in 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
-