Class ConcurrentCASList<E>
- java.lang.Object
-
- org.eclipse.epsilon.common.concurrent.ConcurrentCASList<E>
-
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,List<E>
public class ConcurrentCASList<E> extends Object implements List<E>
A List implementation intended to be used in places where an API requires a List but doesn't actually use the indexes - it just needs ordering. In concurrent environments, Lists are highly inconvenient due to their sequential nature. This class therefore mimics a list when infact it's actually aConcurrentLinkedDeque
.
AS A RESULT, USERS SHOULD NOT RELY ON INDEXES! THIS LIST IS SIMPLY A FACADE FOR POORLY DESIGNED / OVERSPECIFIED APIs WITH NO REGARDS FOR CONCURRENCY.- Since:
- 1.6
- Author:
- Sina Madani
-
-
Field Summary
Fields Modifier and Type Field Description protected AtomicInteger
cachedSize
protected ConcurrentLinkedDeque<E>
deque
-
Constructor Summary
Constructors Constructor Description ConcurrentCASList()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, E element)
boolean
add(E element)
boolean
addAll(int index, Collection<? extends E> col)
boolean
addAll(Collection<? extends E> elements)
void
clear()
boolean
contains(Object element)
boolean
containsAll(Collection<?> elements)
E
get(int index)
int
indexOf(Object element)
boolean
isEmpty()
Iterator<E>
iterator()
int
lastIndexOf(Object element)
ListIterator<E>
listIterator()
ListIterator<E>
listIterator(int index)
E
remove(int index)
boolean
remove(Object element)
boolean
removeAll(Collection<?> elements)
boolean
retainAll(Collection<?> elements)
E
set(int index, E element)
int
size()
List<E>
subList(int from, int to)
Object[]
toArray()
<T> T[]
toArray(T[] arr)
protected boolean
validateIndex(int index)
Checks whether index is 0 or the size of the list.-
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
-
-
-
-
Field Detail
-
deque
protected final ConcurrentLinkedDeque<E> deque
-
cachedSize
protected final AtomicInteger cachedSize
-
-
Method Detail
-
validateIndex
protected final boolean validateIndex(int index)
Checks whether index is 0 or the size of the list.- Returns:
- true means first, false means last.
- Throws:
UnsupportedOperationException
- if index is not 0 or size().
-
size
public int size()
-
addAll
public boolean addAll(int index, Collection<? extends E> col)
-
add
public boolean add(E element)
-
addAll
public boolean addAll(Collection<? extends E> elements)
-
clear
public void clear()
-
contains
public boolean contains(Object element)
-
containsAll
public boolean containsAll(Collection<?> elements)
- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceList<E>
-
isEmpty
public boolean isEmpty()
-
remove
public boolean remove(Object element)
-
removeAll
public boolean removeAll(Collection<?> elements)
-
toArray
public Object[] toArray()
-
toArray
public <T> T[] toArray(T[] arr)
-
retainAll
public boolean retainAll(Collection<?> elements)
-
lastIndexOf
public int lastIndexOf(Object element)
- Specified by:
lastIndexOf
in interfaceList<E>
-
listIterator
public ListIterator<E> listIterator()
- Specified by:
listIterator
in interfaceList<E>
-
listIterator
public ListIterator<E> listIterator(int index)
- Specified by:
listIterator
in interfaceList<E>
-
-