|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractCollection<E>
org.zilonis.util.concurrent.ConcurrentDoublyLinkedList<E>
E - the type of elements held in this collectionpublic class ConcurrentDoublyLinkedList<E>
A concurrent linked-list implementation of a Deque (double-ended
queue). Concurrent insertion, removal, and access operations execute safely
across multiple threads. Iterators are weakly consistent, returning
elements reflecting the state of the deque at some point at or since the
creation of the iterator. They do not throw ConcurrentModificationException, and may proceed concurrently with other
operations.
This class and its iterators implement all of the optional methods
of the Collection and Iterator interfaces. Like most other
concurrent collection implementations, this class does not permit the use of
null elements. because some null arguments and return values
cannot be reliably distinguished from the absence of elements. Arbitrarily,
the Collection.remove(java.lang.Object) method is mapped to
removeFirstOccurrence, and Collection.add(E) is mapped to
addLast.
Beware that, unlike in most collections, the size method is NOT a constant-time operation. Because of the asynchronous nature of these deques, determining the current number of elements requires a traversal of the elements.
This class is Serializable, but relies on default serialization mechanisms. Usually, it is a better idea for any serializable class using a ConcurrentLinkedDeque to instead serialize a snapshot of the elements obtained by method toArray.
| Constructor Summary | |
|---|---|
ConcurrentDoublyLinkedList()
Constructs an empty deque. |
|
ConcurrentDoublyLinkedList(java.util.Collection<? extends E> c)
Constructs a deque containing the elements of the specified collection, in the order they are returned by the collection's iterator. |
|
| Method Summary | ||
|---|---|---|
boolean |
add(E e)
|
|
boolean |
addAll(java.util.Collection<? extends E> c)
Appends all of the elements in the specified collection to the end of this deque, in the order that they are returned by the specified collection's iterator. |
|
void |
addFirst(E o)
Prepends the given element at the beginning of this deque. |
|
void |
addLast(E o)
Appends the given element to the end of this deque. |
|
void |
clear()
Removes all of the elements from this deque. |
|
boolean |
contains(java.lang.Object o)
Returns true if this deque contains at least one element e such that o.equals(e). |
|
E |
element()
|
|
E |
getFirst()
Returns the first element in this deque. |
|
E |
getLast()
Returns the last element in this deque. |
|
boolean |
isEmpty()
Returns true if this collection contains no elements. |
|
java.util.Iterator<E> |
iterator()
Returns a weakly consistent iterator over the elements in this deque, in first-to-last order. |
|
boolean |
offer(E e)
|
|
boolean |
offerFirst(E o)
Prepends the given element at the beginning of this deque. |
|
boolean |
offerLast(E o)
Appends the given element to the end of this deque. |
|
E |
peek()
|
|
E |
peekFirst()
Retrieves, but does not remove, the first element of this deque, or returns null if this deque is empty. |
|
E |
peekLast()
Retrieves, but does not remove, the last element of this deque, or returns null if this deque is empty. |
|
E |
poll()
|
|
E |
pollFirst()
Retrieves and removes the first element of this deque, or returns null if this deque is empty. |
|
E |
pollLast()
Retrieves and removes the last element of this deque, or returns null if this deque is empty. |
|
E |
pop()
|
|
void |
push(E e)
|
|
E |
remove()
|
|
boolean |
remove(java.lang.Object o)
Removes the first element e such that o.equals(e), if such an element exists in this deque. |
|
E |
removeFirst()
Removes and returns the first element from this deque. |
|
boolean |
removeFirstOccurrence(java.lang.Object o)
Removes the first element e such that o.equals(e), if such an element exists in this deque. |
|
E |
removeLast()
Removes and returns the last element from this deque. |
|
boolean |
removeLastOccurrence(java.lang.Object o)
Removes the last element e such that o.equals(e), if such an element exists in this deque. |
|
int |
size()
Returns the number of elements in this deque. |
|
java.lang.Object[] |
toArray()
Returns an array containing all of the elements in this deque in the correct order. |
|
|
toArray(T[] a)
Returns an array containing all of the elements in this deque in the correct order; the runtime type of the returned array is that of the specified array. |
|
| Methods inherited from class java.util.AbstractCollection |
|---|
containsAll, removeAll, retainAll, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Collection |
|---|
equals, hashCode |
| Constructor Detail |
|---|
public ConcurrentDoublyLinkedList()
public ConcurrentDoublyLinkedList(java.util.Collection<? extends E> c)
c - the collection whose elements are to be placed into this
deque.
java.lang.NullPointerException - if c or any element within it is null| Method Detail |
|---|
public void addFirst(E o)
o - the element to be inserted at the beginning of this deque.
java.lang.NullPointerException - if the specified element is nullpublic void addLast(E o)
o - the element to be inserted at the end of this deque.
java.lang.NullPointerException - if the specified element is nullpublic boolean offerFirst(E o)
o - the element to be inserted at the beginning of this deque.
java.lang.NullPointerException - if the specified element is nullpublic boolean offerLast(E o)
o - the element to be inserted at the end of this deque.
java.lang.NullPointerException - if the specified element is nullpublic E peekFirst()
public E peekLast()
public E getFirst()
java.util.NoSuchElementException - if this deque is empty.public E getLast()
java.util.NoSuchElementException - if this deque is empty.public E pollFirst()
public E pollLast()
public E removeFirst()
java.util.NoSuchElementException - if this deque is empty.public E removeLast()
java.util.NoSuchElementException - if this deque is empty.public boolean offer(E e)
public boolean add(E e)
add in interface java.util.Collection<E>add in class java.util.AbstractCollection<E>public E poll()
public E remove()
public E peek()
public E element()
public void push(E e)
public E pop()
public boolean removeFirstOccurrence(java.lang.Object o)
o - element to be removed from this deque, if present.
java.lang.NullPointerException - if the specified element is nullpublic boolean removeLastOccurrence(java.lang.Object o)
o - element to be removed from this deque, if present.
java.lang.NullPointerException - if the specified element is nullpublic boolean contains(java.lang.Object o)
contains in interface java.util.Collection<E>contains in class java.util.AbstractCollection<E>o - element whose presence in this deque is to be tested.
public boolean isEmpty()
isEmpty in interface java.util.Collection<E>isEmpty in class java.util.AbstractCollection<E>public int size()
Beware that, unlike in most collections, this method is NOT a constant-time operation. Because of the asynchronous nature of these deques, determining the current number of elements requires traversing them all to count them. Additionally, it is possible for the size to change during execution of this method, in which case the returned result will be inaccurate. Thus, this method is typically not very useful in concurrent applications.
size in interface java.util.Collection<E>size in class java.util.AbstractCollection<E>public boolean remove(java.lang.Object o)
remove in interface java.util.Collection<E>remove in class java.util.AbstractCollection<E>o - element to be removed from this deque, if present.
java.lang.NullPointerException - if the specified element is nullpublic boolean addAll(java.util.Collection<? extends E> c)
addAll in interface java.util.Collection<E>addAll in class java.util.AbstractCollection<E>c - the elements to be inserted into this deque.
java.lang.NullPointerException - if c or any element within it is nullpublic void clear()
clear in interface java.util.Collection<E>clear in class java.util.AbstractCollection<E>public java.lang.Object[] toArray()
toArray in interface java.util.Collection<E>toArray in class java.util.AbstractCollection<E>public <T> T[] toArray(T[] a)
If the deque fits in the specified array with room to spare (i.e., the array has more elements than the deque), the element in the array immediately following the end of the collection is set to null. This is useful in determining the length of the deque only if the caller knows that the deque does not contain any null elements.
toArray in interface java.util.Collection<E>toArray in class java.util.AbstractCollection<E>a - the array into which the elements of the deque are to be
stored, if it is big enough; otherwise, a new array of the
same runtime type is allocated for this purpose.
java.lang.ArrayStoreException - if the runtime type of a is not a supertype of the runtime
type of every element in this deque.
java.lang.NullPointerException - if the specified array is null.public java.util.Iterator<E> iterator()
ConcurrentModificationException, and may proceed concurrently
with other operations.
iterator in interface java.lang.Iterable<E>iterator in interface java.util.Collection<E>iterator in class java.util.AbstractCollection<E>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||