Package org.elasticsearch.common.collect
Class EvictingQueue<T>
- java.lang.Object
-
- org.elasticsearch.common.collect.EvictingQueue<T>
-
- Type Parameters:
T
- The type of elements in the queue.
- All Implemented Interfaces:
java.lang.Iterable<T>
,java.util.Collection<T>
,java.util.Queue<T>
public class EvictingQueue<T> extends java.lang.Object implements java.util.Queue<T>
AnEvictingQueue
is a non-blocking queue which is limited to a maximum size; when new elements are added to a full queue, elements are evicted from the head of the queue to accommodate the new elements.
-
-
Constructor Summary
Constructors Constructor Description EvictingQueue(int maximumSize)
Construct a newEvictingQueue
that holdsmaximumSize
elements.
-
Method Summary
Modifier and Type Method Description boolean
add(T t)
Add the given element to the queue, possibly forcing an eviction from the head ifremainingCapacity()
is zero.boolean
addAll(java.util.Collection<? extends T> c)
Add the given elements to the queue, possibly forcing evictions from the head ifremainingCapacity()
is zero or becomes zero during the execution of this method.void
clear()
boolean
contains(java.lang.Object o)
boolean
containsAll(java.util.Collection<?> c)
T
element()
boolean
isEmpty()
java.util.Iterator<T>
iterator()
boolean
offer(T t)
T
peek()
T
poll()
int
remainingCapacity()
T
remove()
boolean
remove(java.lang.Object o)
boolean
removeAll(java.util.Collection<?> c)
boolean
retainAll(java.util.Collection<?> c)
int
size()
java.lang.Object[]
toArray()
<T1> T1[]
toArray(T1[] a)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Method Detail
-
remainingCapacity
public int remainingCapacity()
- Returns:
- the number of additional elements that the queue can accommodate before evictions occur
-
add
public boolean add(T t)
Add the given element to the queue, possibly forcing an eviction from the head ifremainingCapacity()
is zero.
-
offer
public boolean offer(T t)
- Specified by:
offer
in interfacejava.util.Queue<T>
- See Also:
add(Object)
-
size
public int size()
- Specified by:
size
in interfacejava.util.Collection<T>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfacejava.util.Collection<T>
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
contains
in interfacejava.util.Collection<T>
-
iterator
public java.util.Iterator<T> iterator()
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArray
in interfacejava.util.Collection<T>
-
toArray
public <T1> T1[] toArray(T1[] a)
- Specified by:
toArray
in interfacejava.util.Collection<T>
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
remove
in interfacejava.util.Collection<T>
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
- Specified by:
containsAll
in interfacejava.util.Collection<T>
-
addAll
public boolean addAll(java.util.Collection<? extends T> c)
Add the given elements to the queue, possibly forcing evictions from the head ifremainingCapacity()
is zero or becomes zero during the execution of this method.- Specified by:
addAll
in interfacejava.util.Collection<T>
- Parameters:
c
- the collection of elements to add- Returns:
- true if any elements were added to the queue
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
- Specified by:
removeAll
in interfacejava.util.Collection<T>
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
- Specified by:
retainAll
in interfacejava.util.Collection<T>
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Collection<T>
-
-