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:
- Serializable,- Iterable<E>,- Collection<E>,- Queue<E>
@GwtCompatible
public final class EvictingQueue<E>
extends ForwardingQueue<E>
implements Serializable
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. This queue orders elements FIFO
 (first-in-first-out). This data structure is logically equivalent to a circular buffer (i.e.,
 cyclic buffer or ring buffer).
 
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
- Author:
- Kurt Alfred Kluever
- See Also:
- 
Method SummaryModifier and TypeMethodDescriptionbooleanAdds the given element to this queue.booleanaddAll(Collection<? extends E> collection) static <E> EvictingQueue<E> create(int maxSize) Creates and returns a new evicting queue that will hold up tomaxSizeelements.delegate()Returns the backing delegate instance that methods are forwarded to.booleanAdds the given element to this queue.intReturns the number of additional elements that this queue can accept without evicting; zero if the queue is currently full.Object[]toArray()Methods inherited from class com.google.common.collect.ForwardingQueueelement, peek, poll, remove, standardOffer, standardPeek, standardPollMethods inherited from class com.google.common.collect.ForwardingCollectionclear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, standardAddAll, standardClear, standardContains, standardContainsAll, standardIsEmpty, standardRemove, standardRemoveAll, standardRetainAll, standardToArray, standardToArray, standardToString, toArrayMethods inherited from class com.google.common.collect.ForwardingObjecttoStringMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collectionclear, contains, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray
- 
Method Details- 
createCreates and returns a new evicting queue that will hold up tomaxSizeelements.When maxSizeis zero, elements will be evicted immediately after being added to the queue.
- 
remainingCapacitypublic int remainingCapacity()Returns the number of additional elements that this queue can accept without evicting; zero if the queue is currently full.- Since:
- 16.0
 
- 
delegateDescription copied from class:ForwardingObjectReturns the backing delegate instance that methods are forwarded to. Abstract subclasses generally override this method with an abstract method that has a more specific return type, such asForwardingSet.delegate(). Concrete subclasses override this method to supply the instance being decorated.- Specified by:
- delegatein class- ForwardingQueue<E>
 
- 
offerAdds 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.
- 
addAdds 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:
- addin interface- Collection<E>
- Specified by:
- addin interface- Queue<E>
- Overrides:
- addin class- ForwardingCollection<E>
- Returns:
- truealways
 
- 
addAll- Specified by:
- addAllin interface- Collection<E>
- Overrides:
- addAllin class- ForwardingCollection<E>
 
- 
toArray- Specified by:
- toArrayin interface- Collection<E>
- Overrides:
- toArrayin class- ForwardingCollection<E>
 
 
-