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 AtomicIntegercachedSizeprotected ConcurrentLinkedDeque<E>deque
-
Constructor Summary
Constructors Constructor Description ConcurrentCASList()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, E element)booleanadd(E element)booleanaddAll(int index, Collection<? extends E> col)booleanaddAll(Collection<? extends E> elements)voidclear()booleancontains(Object element)booleancontainsAll(Collection<?> elements)Eget(int index)intindexOf(Object element)booleanisEmpty()Iterator<E>iterator()intlastIndexOf(Object element)ListIterator<E>listIterator()ListIterator<E>listIterator(int index)Eremove(int index)booleanremove(Object element)booleanremoveAll(Collection<?> elements)booleanretainAll(Collection<?> elements)Eset(int index, E element)intsize()List<E>subList(int from, int to)Object[]toArray()<T> T[]toArray(T[] arr)protected booleanvalidateIndex(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:
containsAllin interfaceCollection<E>- Specified by:
containsAllin 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:
lastIndexOfin interfaceList<E>
-
listIterator
public ListIterator<E> listIterator()
- Specified by:
listIteratorin interfaceList<E>
-
listIterator
public ListIterator<E> listIterator(int index)
- Specified by:
listIteratorin interfaceList<E>
-
-