Class CircularFifoQueue
-
- All Implemented Interfaces:
-
java.io.Serializable,java.util.Queue,kotlin.collections.Collection,kotlin.collections.Iterable,kotlin.collections.MutableCollection,kotlin.collections.MutableIterable
public final class CircularFifoQueue<E extends Object> extends AbstractMutableCollection<E> implements Queue<E>, Serializable
CircularFifoQueue is a first-in first-out queue with a fixed size that replaces its oldest element if full.
The removal order of a CircularFifoQueue is based on the insertion order; elements are removed in the same order in which they were added. The iteration order is the same as the removal order.
The add, remove, peek, poll, offer operations all perform in constant time. All other operations perform in linear time or worse.
This queue prevents null objects from being added.
-
-
Constructor Summary
Constructors Constructor Description CircularFifoQueue(Collection<E> coll)CircularFifoQueue(Integer size)CircularFifoQueue()
-
Method Summary
Modifier and Type Method Description IntegergetSize()Returns the number of elements stored in the queue. BooleanisEmpty()Returns true if this queue is empty; false otherwise. final BooleanisFull()A CircularFifoQueue can never be full, thus this returns always false. final BooleanisAtFullCapacity()Returns true if the capacity limit of this queue has been reached, i.e. final IntegermaxSize()Gets the maximum size of the collection (the bound). Unitclear()Clears this queue. Booleanadd(E element)Adds the given element to this queue. final Eget(Integer index)Returns the element at the specified position in this queue. Booleanoffer(E e)Adds the given element to this queue. Epoll()Eelement()Epeek()Eremove()Iterator<E>iterator()Returns an iterator over this queue's elements. -
-
Constructor Detail
-
CircularFifoQueue
CircularFifoQueue(Collection<E> coll)
-
CircularFifoQueue
CircularFifoQueue(Integer size)
-
CircularFifoQueue
CircularFifoQueue()
-
-
Method Detail
-
isEmpty
Boolean isEmpty()
Returns true if this queue is empty; false otherwise.
- Returns:
true if this queue is empty
-
isFull
final Boolean isFull()
A CircularFifoQueue can never be full, thus this returns always false.
- Returns:
always returns false
-
isAtFullCapacity
final Boolean isAtFullCapacity()
Returns true if the capacity limit of this queue has been reached, i.e. the number of elements stored in the queue equals its maximum size.
- Returns:
true if the capacity limit has been reached, false otherwise
-
maxSize
final Integer maxSize()
Gets the maximum size of the collection (the bound).
- Returns:
the maximum number of elements the collection can hold
-
add
Boolean add(E element)
Adds the given element to this queue. If the queue is full, the least recently added element is discarded so that a new element can be inserted.
- Parameters:
element- the element to add- Returns:
true, always
-
get
final E get(Integer index)
Returns the element at the specified position in this queue.
- Parameters:
index- the position of the element in the queue- Returns:
the element at position index
-
offer
Boolean offer(E e)
Adds the given element to this queue. If the queue is full, the least recently added element is discarded so that a new element can be inserted.
- Parameters:
e- the element to add- Returns:
true, always
-
-
-
-