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.
| Modifier and Type | Field and Description |
|---|---|
| private transient E[] | elements
Underlying storage array. |
| private transient int | end
Index mod maxElements of the array position following the last queue element. |
| private transient boolean | full
Flag to indicate if the queue is currently full. |
| private final int | maxElements
Capacity of the queue. |
| private static final long | serialVersionUID
Serialization version. |
| private transient int | start
Array index of first (oldest) queue element. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | CircularFifoQueue(final int
the size of the queue (cannot be changed) size)Constructor that creates a queue with the specified size. |
| public | CircularFifoQueue(final Collection<? extends E>
the collection to copy into the queue, may not be null coll)Constructor that creates a queue from the specified collection. |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | Returns: true, alwaysthe element to add element)Overrides java. Implements java. |
| public void | clear()
Overrides java. Implements java. |
| private int | |
| public E | element()
Implements java. |
| public E | Returns: the element at positionindexthe position of the element in the queue index)Returns the element at the specified position in this queue. |
| private int | |
| public boolean | Returns: true if the capacity limit has been reached, false otherwiseReturns |
| public boolean | Returns: true if this queue is emptyOverrides java. Implements java. |
| public boolean | Returns: always returnsfalseImplements org. |
| public Iterator | Returns: an iterator over this queue's elementsImplements abstract java. Implements java. |
| public int | Returns: the maximum number of elements the collection can holdImplements org. |
| public boolean | Returns: true, alwaysthe element to add element)Implements java. |
| public E | peek()
Implements java. null if this queue is empty.
|
| public E | poll()
Implements java. null if this queue is empty.
|
| private void | |
| public E | |
| public int | Returns: this queue's sizeImplements abstract java. Implements java. |
| private void | writeObject(final ObjectOutputStream
the output stream out)Write the queue out using a custom routine. |
| elements | back to summary |
|---|---|
| private transient E[] elements Underlying storage array. | |
| end | back to summary |
|---|---|
| private transient int end Index mod maxElements of the array position following the last queue element. Queue elements start at elements[start] and "wrap around" elements[maxElements-1], ending at elements[decrement(end)]. For example, elements = {c,a,b}, start=1, end=1 corresponds to the queue [a,b,c]. | |
| full | back to summary |
|---|---|
| private transient boolean full Flag to indicate if the queue is currently full. | |
| maxElements | back to summary |
|---|---|
| private final int maxElements Capacity of the queue. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serialization version. | |
| start | back to summary |
|---|---|
| private transient int start Array index of first (oldest) queue element. | |
| CircularFifoQueue | back to summary |
|---|---|
| public CircularFifoQueue() Constructor that creates a queue with the default size of 32. | |
| CircularFifoQueue | back to summary |
|---|---|
| public CircularFifoQueue(final int size) Constructor that creates a queue with the specified size.
| |
| CircularFifoQueue | back to summary |
|---|---|
| public CircularFifoQueue(final Collection<? extends E> coll) Constructor that creates a queue from the specified collection. The collection size also sets the queue size.
| |
| add | back to summary |
|---|---|
| public boolean add(final E element) Overrides java. Implements java. 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.
| |
| clear | back to summary |
|---|---|
| public void clear() Overrides java. Implements java. Clears this queue.
| |
| decrement | back to summary |
|---|---|
| private int decrement(int index) Decrements the internal index.
| |
| element | back to summary |
|---|---|
| public E element() Implements java. Doc from java. Retrieves, but does not remove, the head of this queue. This method
differs from
| |
| get | back to summary |
|---|---|
| public E get(final int index) Returns the element at the specified position in this queue.
| |
| increment | back to summary |
|---|---|
| private int increment(int index) Increments the internal index.
| |
| isAtFullCapacity | back to summary |
|---|---|
| public boolean isAtFullCapacity() Returns
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Overrides java. Implements java. Returns true if this queue is empty; false otherwise.
| |
| isFull | back to summary |
|---|---|
| public boolean isFull() Implements org. Doc from org. Returns true if this collection is full and no new elements can be added.
A
| |
| iterator | back to summary |
|---|---|
| public Iterator Implements abstract java. Implements java. Returns an iterator over this queue's elements. | |
| maxSize | back to summary |
|---|---|
| public int maxSize() Implements org. Gets the maximum size of the collection (the bound).
| |
| offer | back to summary |
|---|---|
| public boolean offer(final E element) Implements java. 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.
| |
| peek | back to summary |
|---|---|
| public E peek() Implements java. Doc from java. Retrieves, but does not remove, the head of this queue,
or returns
| |
| poll | back to summary |
|---|---|
| public E poll() Implements java. Doc from java. Retrieves and removes the head of this queue,
or returns
| |
| readObject | back to summary |
|---|---|
| private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException Read the queue in using a custom routine.
| |
| remove | back to summary |
|---|---|
| public E remove() Implements java. Doc from java. Retrieves and removes the head of this queue. This method differs
from
| |
| size | back to summary |
|---|---|
| public int size() Implements abstract java. Implements java. Returns the number of elements stored in the queue.
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(final ObjectOutputStream out) throws IOException Write the queue out using a custom routine.
| |