E
- element typepublic class BoundedDeque<E> extends AbstractCollection<E> implements Serializable
Note: Like ArrayDeque
, this deque implementation is not thread-safe. Concurrent
access by multiple threads requires explicit synchronization.
Modifier and Type | Class and Description |
---|---|
static class |
BoundedDeque.AccessPolicy
The policy which determines in which order elements are accessed.
|
static class |
BoundedDeque.EvictPolicy
The policy which determines in which order elements are removed if
the maximum capacity is reached.
|
Constructor and Description |
---|
BoundedDeque(BoundedDeque.AccessPolicy accessPolicy)
Constructor.
|
BoundedDeque(int capacity,
BoundedDeque.AccessPolicy accessPolicy,
BoundedDeque.EvictPolicy evictPolicy)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
clear() |
E |
insert(E element)
Inserts an element into the deque, and returns the one that had to be
evicted in case of a capacity violation.
|
boolean |
isBounded()
Retrieves whether capacity restriction is in effect.
|
boolean |
isEmpty() |
Iterator<E> |
iterator() |
E |
peek()
Retrieves, but does not remove the top-most element, i.e., the element that is
either the top of the stack or the head of the queue, depending on the configured
BoundedDeque.AccessPolicy . |
E |
retrieve()
Retrieves and remove the top-most element, i.e., the element that is either
the top of the stack or the head of the queue, depending on the configured
BoundedDeque.AccessPolicy . |
int |
size() |
add, addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
equals, hashCode, parallelStream, removeIf, spliterator, stream
public BoundedDeque(BoundedDeque.AccessPolicy accessPolicy)
accessPolicy
- whether this deque acts as a stack or a queuepublic BoundedDeque(int capacity, BoundedDeque.AccessPolicy accessPolicy, BoundedDeque.EvictPolicy evictPolicy)
capacity
- the maximum capacity of this deque. A value less than or equal to 0
means unboundedaccessPolicy
- whether this deque acts as a stack or a queueevictPolicy
- which elements to remove if the maximum capacity is reached. If the
capacity is unbounded, this parameter has no effectpublic E insert(E element)
element
- the element to insertnull
if the maximum capacity has not been reachedpublic E retrieve()
BoundedDeque.AccessPolicy
.public E peek()
BoundedDeque.AccessPolicy
.public boolean isBounded()
true
if the capacity is restricted, false
otherwisepublic boolean isEmpty()
isEmpty
in interface Collection<E>
isEmpty
in class AbstractCollection<E>
public int size()
size
in interface Collection<E>
size
in class AbstractCollection<E>
public void clear()
clear
in interface Collection<E>
clear
in class AbstractCollection<E>
Copyright © 2015. All rights reserved.