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 TypeMethodDescriptionboolean
void
void
(package private) void
void
clear()
(package private) boolean
boolean
element()
getFirst()
getLast()
boolean
isEmpty()
iterator()
(package private) void
Links the element to the front of the deque so that it becomes the first element.(package private) void
Links the element to the back of the deque so that it becomes the last element.void
moveToBack
(E e) Moves the element to the back of the deque so that it becomes the last element.void
moveToFront
(E e) Moves the element to the front of the deque so that it becomes the first element.boolean
boolean
offerFirst
(E e) boolean
peek()
peekLast()
poll()
pollLast()
pop()
void
remove()
(package private) boolean
boolean
boolean
removeAll
(Collection<?> c) boolean
boolean
int
size()
(package private) void
Unlinks the non-null element.(package private) E
Unlinks the non-null first element.(package private) E
Unlinks the non-null last element.Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray, toArray, 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
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:
isEmpty
in interfaceCollection<E extends Linked<E>>
- Overrides:
isEmpty
in 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:
clear
in interfaceCollection<E extends Linked<E>>
- Overrides:
clear
in 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:
offerFirst
in interfaceDeque<E extends Linked<E>>
-
offerLast
-
add
-
addFirst
-
addLast
-
poll
-
pollFirst
-
pollLast
-
remove
-
remove
-
remove
-
removeFirst
- Specified by:
removeFirst
in interfaceDeque<E extends Linked<E>>
-
removeFirstOccurrence
- Specified by:
removeFirstOccurrence
in interfaceDeque<E extends Linked<E>>
-
removeLast
- Specified by:
removeLast
in interfaceDeque<E extends Linked<E>>
-
removeLastOccurrence
- Specified by:
removeLastOccurrence
in interfaceDeque<E extends Linked<E>>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<E extends Linked<E>>
- Overrides:
removeAll
in classAbstractCollection<E extends Linked<E>>
-
push
-
pop
-
iterator
-
descendingIterator
- Specified by:
descendingIterator
in interfaceDeque<E extends Linked<E>>
-