Class LinkedDeque<E extends Linked<E>>
java.lang.Object
java.util.AbstractCollection<E>
com.googlecode.concurrentlinkedhashmap.LinkedDeque<E>
- Type Parameters:
E- the type of elements held in this collection
- All Implemented Interfaces:
Iterable<E>,Collection<E>,Deque<E>,Queue<E>
@NotThreadSafe
final class LinkedDeque<E extends Linked<E>>
extends AbstractCollection<E>
implements Deque<E>
Linked list implementation of the
Deque interface where the link
pointers are tightly integrated with the element. Linked deques have no
capacity restrictions; they grow as necessary to support usage. They are not
thread-safe; in the absence of external synchronization, they do not support
concurrent access by multiple threads. Null elements are prohibited.
Most LinkedDeque operations run in constant time by assuming that
the Linked parameter is associated with the deque instance. Any usage
that violates this assumption will result in non-deterministic behavior.
The iterators returned by this class are not fail-fast: If the deque is modified at any time after the iterator is created, the iterator will be in an unknown state. Thus, in the face of concurrent modification, the iterator risks arbitrary, non-deterministic behavior at an undetermined time in the future.
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidvoid(package private) voidvoidclear()(package private) booleanbooleanelement()getFirst()getLast()booleanisEmpty()iterator()(package private) voidLinks the element to the front of the deque so that it becomes the first element.(package private) voidLinks the element to the back of the deque so that it becomes the last element.voidmoveToBack(E e) Moves the element to the back of the deque so that it becomes the last element.voidmoveToFront(E e) Moves the element to the front of the deque so that it becomes the first element.booleanbooleanofferFirst(E e) booleanpeek()peekLast()poll()pollLast()pop()voidremove()(package private) booleanbooleanbooleanremoveAll(Collection<?> c) booleanbooleanintsize()(package private) voidUnlinks the non-null element.(package private) EUnlinks the non-null first element.(package private) EUnlinks the non-null last element.Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
addAll, containsAll, equals, hashCode, parallelStream, removeIf, retainAll, spliterator, stream, toArray, toArray
-
Field Details
-
first
Pointer to first node. Invariant: (first == null invalid input: '&'invalid input: '&' last == null) || (first.prev == null) -
last
Pointer to last node. Invariant: (first == null invalid input: '&'invalid input: '&' last == null) || (last.next == null)
-
-
Constructor Details
-
LinkedDeque
LinkedDeque()
-
-
Method Details
-
linkFirst
Links the element to the front of the deque so that it becomes the first element.- Parameters:
e- the unlinked element
-
linkLast
Links the element to the back of the deque so that it becomes the last element.- Parameters:
e- the unlinked element
-
unlinkFirst
E unlinkFirst()Unlinks the non-null first element. -
unlinkLast
E unlinkLast()Unlinks the non-null last element. -
unlink
Unlinks the non-null element. -
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<E extends Linked<E>>- Overrides:
isEmptyin classAbstractCollection<E extends Linked<E>>
-
checkNotEmpty
void checkNotEmpty() -
size
public int size()Beware that, unlike in most collections, this method is NOT a constant-time operation.
-
clear
public void clear()- Specified by:
clearin interfaceCollection<E extends Linked<E>>- Overrides:
clearin classAbstractCollection<E extends Linked<E>>
-
contains
-
contains
-
moveToFront
Moves the element to the front of the deque so that it becomes the first element.- Parameters:
e- the linked element
-
moveToBack
Moves the element to the back of the deque so that it becomes the last element.- Parameters:
e- the linked element
-
peek
-
peekFirst
-
peekLast
-
getFirst
-
getLast
-
element
-
offer
-
offerFirst
- Specified by:
offerFirstin interfaceDeque<E extends Linked<E>>
-
offerLast
-
add
-
addFirst
-
addLast
-
poll
-
pollFirst
-
pollLast
-
remove
-
remove
-
remove
-
removeFirst
- Specified by:
removeFirstin interfaceDeque<E extends Linked<E>>
-
removeFirstOccurrence
- Specified by:
removeFirstOccurrencein interfaceDeque<E extends Linked<E>>
-
removeLast
- Specified by:
removeLastin interfaceDeque<E extends Linked<E>>
-
removeLastOccurrence
- Specified by:
removeLastOccurrencein interfaceDeque<E extends Linked<E>>
-
removeAll
- Specified by:
removeAllin interfaceCollection<E extends Linked<E>>- Overrides:
removeAllin classAbstractCollection<E extends Linked<E>>
-
push
-
pop
-
iterator
-
descendingIterator
- Specified by:
descendingIteratorin interfaceDeque<E extends Linked<E>>
-