public class CircularFifoQueue<E> extends AbstractCollection<E> implements Queue <E>, BoundedCollection <E>, Serializable
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(Object), remove(), peek(), poll(), offer(Object) operations all perform in constant time. All other operations perform in linear time or worse.
This queue prevents null objects from being added.
| Constructor and Description |
|---|
CircularFifoQueue()
Constructor that creates a queue with the default size of 32.
|
CircularFifoQueue(Collection
Constructor that creates a queue from the specified collection.
|
CircularFifoQueue(int size)
Constructor that creates a queue with the specified size.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E element)
Adds the given element to this queue.
|
void |
clear()
Clears this queue.
|
E |
element()
|
E |
get(int index)
Returns the element at the specified position in this queue.
|
boolean |
isAtFullCapacity()
Returns
true if the capacity limit of this queue has been reached, i.e.
|
boolean |
isEmpty()
Returns true if this queue is empty; false otherwise.
|
boolean |
isFull()
Returns true if this collection is full and no new elements can be added.
|
Iterator |
iterator()
Returns an iterator over this queue's elements.
|
int |
maxSize()
Gets the maximum size of the collection (the bound).
|
boolean |
offer(E element)
Adds the given element to this queue.
|
E |
peek()
|
E |
poll()
|
E |
remove()
|
int |
size()
Returns the number of elements stored in the queue.
|
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddAll, contains, containsAll, equals, hashCode, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArraypublic CircularFifoQueue()
public CircularFifoQueue(int size)
size - the size of the queue (cannot be changed)
IllegalArgumentException - if the size is < 1
public CircularFifoQueue(Collection<? extends E> coll)
coll - the collection to copy into the queue, may not be null
NullPointerException - if the collection is null
public int size()
size in interface
Collection<E>
size in class
AbstractCollection<E>
public boolean isEmpty()
isEmpty in interface
Collection<E>
isEmpty in class
AbstractCollection<E>
public boolean isFull()
A CircularFifoQueue can never be full, thus this returns always false.
isFull in interface
BoundedCollection<E>
false
public boolean isAtFullCapacity()
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.
true if the capacity limit has been reached,
false otherwise
public int maxSize()
maxSize in interface
BoundedCollection<E>
public void clear()
public boolean add(E element)
add in interface
Collection<E>
add in interface
Queue<E>
add in class
AbstractCollection<E>
element - the element to add
NullPointerException - if the given element is null
public E get(int index)
index - the position of the element in the queue
index
NoSuchElementException - if the requested position is outside the range [0, size)
public boolean offer(E element)
offer in interface
Queue<E>
element - the element to add
NullPointerException - if the given element is null
public E poll()
public E element()
public E peek()
public E remove()