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<? extends E> coll)
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 |
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<E> |
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, toString
public CircularFifoQueue()
public CircularFifoQueue(int size)
size
- the size of the queue (cannot be changed)IllegalArgumentException
- if the size is < 1public CircularFifoQueue(Collection<? extends E> coll)
coll
- the collection to copy into the queue, may not be nullNullPointerException
- if the collection is nullpublic 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 int maxSize()
maxSize
in interface BoundedCollection<E>
public void clear()
clear
in interface Collection<E>
clear
in class AbstractCollection<E>
public boolean add(E element)
add
in interface Collection<E>
add
in interface Queue<E>
add
in class AbstractCollection<E>
element
- the element to addNullPointerException
- if the given element is nullpublic E get(int index)
index
- the position of the element in the queueindex
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 addNullPointerException
- if the given element is nullCopyright © 2001–2013 The Apache Software Foundation. All rights reserved.