Package com.google.common.collect
Class EvictingQueue<E>
- java.lang.Object
-
- com.google.common.collect.ForwardingObject
-
- com.google.common.collect.ForwardingCollection<E>
-
- com.google.common.collect.ForwardingQueue<E>
-
- com.google.common.collect.EvictingQueue<E>
-
- All Implemented Interfaces:
java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.Queue<E>
@Beta @GwtIncompatible("java.util.ArrayDeque") public final class EvictingQueue<E> extends ForwardingQueue<E>
A non-blocking queue which automatically evicts elements from the head of the queue when attempting to add new elements onto the queue and it is full.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.
- Since:
- 15.0
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(E e)
Adds the given element to this queue.boolean
addAll(java.util.Collection<? extends E> collection)
boolean
contains(java.lang.Object object)
static <E> EvictingQueue<E>
create(int maxSize)
Creates and returns a new evicting queue that will hold up tomaxSize
elements.boolean
offer(E e)
Adds the given element to this queue.boolean
remove(java.lang.Object object)
-
Methods inherited from class com.google.common.collect.ForwardingQueue
element, peek, poll, remove
-
Methods inherited from class com.google.common.collect.ForwardingCollection
clear, containsAll, isEmpty, iterator, removeAll, retainAll, size, toArray, toArray
-
Methods inherited from class com.google.common.collect.ForwardingObject
toString
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Method Detail
-
create
public static <E> EvictingQueue<E> create(int maxSize)
Creates and returns a new evicting queue that will hold up tomaxSize
elements.When
maxSize
is zero, elements will be evicted immediately after being added to the queue.
-
offer
public boolean offer(E e)
Adds the given element to this queue. If the queue is currently full, the element at the head of the queue is evicted to make room.- Specified by:
offer
in interfacejava.util.Queue<E>
- Overrides:
offer
in classForwardingQueue<E>
- Returns:
true
always
-
add
public boolean add(E e)
Adds the given element to this queue. If the queue is currently full, the element at the head of the queue is evicted to make room.- Specified by:
add
in interfacejava.util.Collection<E>
- Specified by:
add
in interfacejava.util.Queue<E>
- Overrides:
add
in classForwardingCollection<E>
- Returns:
true
always
-
addAll
public boolean addAll(java.util.Collection<? extends E> collection)
- Specified by:
addAll
in interfacejava.util.Collection<E>
- Overrides:
addAll
in classForwardingCollection<E>
-
contains
public boolean contains(java.lang.Object object)
- Specified by:
contains
in interfacejava.util.Collection<E>
- Overrides:
contains
in classForwardingCollection<E>
-
remove
public boolean remove(java.lang.Object object)
- Specified by:
remove
in interfacejava.util.Collection<E>
- Overrides:
remove
in classForwardingCollection<E>
-
-