Package com.noleme.commons.container
Class EvictingQueue<T>
java.lang.Object
com.noleme.commons.container.EvictingQueue<T>
- All Implemented Interfaces:
Serializable
,Iterable<T>
,Collection<T>
,Queue<T>
public final class EvictingQueue<T> extends Object implements Queue<T>, Serializable
Adaptation of Guava's EvictingQueue, without the ties to other Guava components.
- Author:
- Pierre LECERF ([email protected]) Created on 21/12/2019
- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description EvictingQueue(int maxSize)
Creates and returns a new evicting queue that will hold up tomaxSize
elements. -
Method Summary
Modifier and Type Method Description boolean
add(T e)
Adds the given element to this queue.boolean
addAll(Collection<? extends T> collection)
void
clear()
boolean
contains(Object object)
boolean
containsAll(Collection<?> c)
protected Queue<T>
delegate()
T
element()
boolean
isEmpty()
Iterator<T>
iterator()
boolean
offer(T e)
Adds the given element to this queue.T
peek()
T
poll()
int
remainingCapacity()
Returns the number of additional elements that this queue can accept without evicting; zero if the queue is currently full.T
remove()
boolean
remove(Object object)
boolean
removeAll(Collection<?> c)
boolean
retainAll(Collection<?> c)
int
size()
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
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream
-
Constructor Details
-
EvictingQueue
public EvictingQueue(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.- Parameters:
maxSize
-
-
-
Method Details
-
remainingCapacity
public int remainingCapacity()Returns the number of additional elements that this queue can accept without evicting; zero if the queue is currently full. -
delegate
-
offer
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. -
remove
-
poll
-
element
-
peek
-
add
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. -
addAll
- Specified by:
addAll
in interfaceCollection<T>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<T>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<T>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<T>
-
size
public int size()- Specified by:
size
in interfaceCollection<T>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<T>
-
contains
- Specified by:
contains
in interfaceCollection<T>
-
iterator
-
toArray
- Specified by:
toArray
in interfaceCollection<T>
-
toArray
public <T1> T1[] toArray(T1[] a)- Specified by:
toArray
in interfaceCollection<T>
-
remove
- Specified by:
remove
in interfaceCollection<T>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<T>
-