Class CircularFifoQueue<E>
java.lang.Object
java.util.AbstractCollection<E>
org.apache.commons.collections4.queue.CircularFifoQueue<E>
- Type Parameters:
- E- the type of elements in this collection
- All Implemented Interfaces:
- Serializable,- Iterable<E>,- Collection<E>,- Queue<E>,- BoundedCollection<E>
public class CircularFifoQueue<E>
extends AbstractCollection<E>
implements Queue<E>, BoundedCollection<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(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.
- Since:
- 4.0
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionConstructor that creates a queue with the default size of 32.CircularFifoQueue(int size) Constructor that creates a queue with the specified size.CircularFifoQueue(Collection<? extends E> coll) Constructor that creates a queue from the specified collection.
- 
Method SummaryModifier and TypeMethodDescriptionbooleanAdds the given element to this queue.voidclear()Clears this queue.element()get(int index) Gets the element at the specified position in this queue.booleanReturnstrueif the capacity limit of this queue has been reached, i.e. the number of elements stored in the queue equals its maximum size.booleanisEmpty()Returns true if this queue is empty; false otherwise.booleanisFull()Returns true if this collection is full and no new elements can be added.iterator()Returns an iterator over this queue's elements.intmaxSize()Gets the maximum size of the collection (the bound).booleanAdds the given element to this queue.peek()poll()remove()intsize()Returns the number of elements stored in the queue.Methods inherited from class java.util.AbstractCollectionaddAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.CollectionaddAll, contains, containsAll, equals, hashCode, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray
- 
Constructor Details- 
CircularFifoQueuepublic CircularFifoQueue()Constructor that creates a queue with the default size of 32.
- 
CircularFifoQueueConstructor that creates a queue from the specified collection. The collection size also sets the queue size.- Parameters:
- coll- the collection to copy into the queue, may not be null
- Throws:
- NullPointerException- if the collection is null
 
- 
CircularFifoQueueConstructor that creates a queue with the specified size.- Parameters:
- size- the size of the queue (cannot be changed)
- Throws:
- IllegalArgumentException- if the size is < 1
 
 
- 
- 
Method Details- 
addAdds 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.- Specified by:
- addin interface- Collection<E>
- Specified by:
- addin interface- Queue<E>
- Overrides:
- addin class- AbstractCollection<E>
- Parameters:
- element- the element to add
- Returns:
- true, always
- Throws:
- NullPointerException- if the given element is null
 
- 
clearClears this queue.- Specified by:
- clearin interface- Collection<E>
- Overrides:
- clearin class- AbstractCollection<E>
 
- 
element
- 
getGets 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
- Throws:
- NoSuchElementException- if the requested position is outside the range [0, size)
 
- 
isAtFullCapacityReturnstrueif the capacity limit of this queue has been reached, i.e. the number of elements stored in the queue equals its maximum size.- Returns:
- trueif the capacity limit has been reached,- falseotherwise
- Since:
- 4.1
 
- 
isEmptyReturns true if this queue is empty; false otherwise.- Specified by:
- isEmptyin interface- Collection<E>
- Overrides:
- isEmptyin class- AbstractCollection<E>
- Returns:
- true if this queue is empty
 
- 
isFullReturns true if this collection is full and no new elements can be added.A CircularFifoQueuecan never be full, thus this returns alwaysfalse.- Specified by:
- isFullin interface- BoundedCollection<E>
- Returns:
- always returns false
 
- 
iterator
- 
maxSizeGets the maximum size of the collection (the bound).- Specified by:
- maxSizein interface- BoundedCollection<E>
- Returns:
- the maximum number of elements the collection can hold
 
- 
offerAdds 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.- Specified by:
- offerin interface- Queue<E>
- Parameters:
- element- the element to add
- Returns:
- true, always
- Throws:
- NullPointerException- if the given element is null
 
- 
peek
- 
poll
- 
remove
- 
sizeReturns the number of elements stored in the queue.- Specified by:
- sizein interface- Collection<E>
- Specified by:
- sizein class- AbstractCollection<E>
- Returns:
- this queue's size
 
 
-