@Beta @GwtCompatible public final class EvictingQueue<E> extends ForwardingQueue<E> implements java.io.Serializable
An evicting queue must be configured with a maximum size. Each time an element is added to a full queue, the queue automatically removes its head element. This is different from conventional bounded queues, which either block or reject new elements when full.
This class is not thread-safe, and does not accept null elements.
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e)
Adds the given element to this queue.
|
boolean |
addAll(java.util.Collection<? extends E> collection)
Adds all of the elements in the specified collection to this collection
(optional operation).
|
boolean |
contains(java.lang.Object object)
Returns true if this collection contains the specified element.
|
static <E> EvictingQueue<E> |
create(int maxSize)
Creates and returns a new evicting queue that will hold up to
maxSize elements. |
protected java.util.Queue<E> |
delegate()
Returns the backing delegate instance that methods are forwarded to.
|
boolean |
offer(E e)
Adds the given element to this queue.
|
int |
remainingCapacity()
Returns the number of additional elements that this queue can accept without evicting; zero if
the queue is currently full.
|
boolean |
remove(java.lang.Object object)
Removes a single instance of the specified element from this
collection, if it is present (optional operation).
|
element, peek, poll, remove, standardOffer, standardPeek, standardPoll
clear, containsAll, isEmpty, iterator, removeAll, retainAll, size, standardAddAll, standardClear, standardContains, standardContainsAll, standardIsEmpty, standardRemove, standardRemoveAll, standardRetainAll, standardToArray, standardToArray, standardToString, toArray, toArray
toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
public static <E> EvictingQueue<E> create(int maxSize)
maxSize
elements.
When maxSize
is zero, elements will be evicted immediately after being added to the
queue.
public int remainingCapacity()
protected java.util.Queue<E> delegate()
ForwardingObject
ForwardingSet.delegate()
. Concrete subclasses override this method to supply the
instance being decorated.delegate
in class ForwardingQueue<E>
@CanIgnoreReturnValue public boolean offer(E e)
offer
in interface java.util.Queue<E>
offer
in class ForwardingQueue<E>
e
- the element to addtrue
always@CanIgnoreReturnValue public boolean add(E e)
add
in interface java.util.Collection<E>
add
in interface java.util.Queue<E>
add
in class ForwardingCollection<E>
e
- element whose presence in this collection is to be ensuredtrue
always@CanIgnoreReturnValue public boolean addAll(java.util.Collection<? extends E> collection)
java.util.Collection
addAll
in interface java.util.Collection<E>
addAll
in class ForwardingCollection<E>
collection
- collection containing elements to be added to this collectionCollection.add(Object)
public boolean contains(java.lang.Object object)
java.util.Collection
contains
in interface java.util.Collection<E>
contains
in class ForwardingCollection<E>
object
- element whose presence in this collection is to be tested@CanIgnoreReturnValue public boolean remove(java.lang.Object object)
java.util.Collection
remove
in interface java.util.Collection<E>
remove
in class ForwardingCollection<E>
object
- element to be removed from this collection, if presentCopyright © 2010–2021. All rights reserved.