public final class ArrayFIFOQueue
extends java.lang.Object
implements java.lang.Cloneable
This queue is implemented as a circular array. When the array becomes full, it is transparently doubled in size.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_CAPACITY
The default capacity of the queue.
|
static int |
DEFAULT_HISTORY_CAPACITY
The default capacity of the history queue.
|
static int |
INFINITE_CAPACITY
Used to indicate that the size of the queue or the history
queue is infinite.
|
static int |
STARTING_ARRAYSIZE
The starting size of the circular buffer, if the capacity is
infinite.
|
Constructor and Description |
---|
ArrayFIFOQueue()
Construct an empty queue with no container, and an infinite capacity.
|
ArrayFIFOQueue(ArrayFIFOQueue model)
Copy constructor.
|
ArrayFIFOQueue(int size)
Construct an empty queue with no container and the given capacity.
|
ArrayFIFOQueue(Nameable container)
Construct an empty queue with the specified container.
|
ArrayFIFOQueue(Nameable container,
int size)
Construct an empty queue with the specified container and the
given size.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear this queue of any contained objects.
|
java.lang.Object |
clone()
Clone this queue.
|
java.util.List |
elementList()
Return a list containing all the elements in the queue, beginning
with the oldest.
|
java.util.Enumeration |
elements()
Enumerate the objects in the queue, beginning with the oldest.
|
java.lang.Object |
get(int offset)
Return an object in the queue or history.
|
int |
getCapacity()
Return the queue capacity.
|
Nameable |
getContainer()
Return the container of the queue, or null if there is none.
|
int |
getHistoryCapacity()
Return the capacity of the history queue.
|
java.util.Enumeration |
historyElements()
Enumerate the objects in the history, which are the N most recent
objects taken from the queue, beginning with the oldest, where
N is less than or equal to the history capacity.
|
int |
historySize()
Return the number of objects in the history.
|
boolean |
isEmpty()
Return true if the number of objects in the queue is zero.
|
boolean |
isFull()
Return true if the number of objects in the queue equals the
queue capacity.
|
boolean |
put(java.lang.Object element)
Put an object in the queue and return true if this will not
cause the capacity to be exceeded.
|
boolean |
putArray(java.lang.Object[] element)
Put an array of objects in the queue and return true if this will not
cause the capacity to be exceeded.
|
boolean |
putArray(java.lang.Object[] element,
int count)
Put an array of objects in the queue and return true if this will not
cause the capacity to be exceeded.
|
void |
setCapacity(int capacity)
Set queue capacity.
|
void |
setContainer(Nameable container)
Set the container of the queue.
|
void |
setHistoryCapacity(int capacity)
Set the capacity of the history queue.
|
int |
size()
Return the number of objects in the queue.
|
java.lang.Object |
take()
Remove the oldest object from the queue and return it.
|
void |
takeArray(java.lang.Object[] objects)
Remove the count oldest objects from the queue and return them.
|
void |
takeArray(java.lang.Object[] objects,
int count)
Remove the count oldest objects from the queue and return them.
|
public static final int INFINITE_CAPACITY
public static final int DEFAULT_CAPACITY
public static final int STARTING_ARRAYSIZE
public static final int DEFAULT_HISTORY_CAPACITY
public ArrayFIFOQueue()
public ArrayFIFOQueue(int size)
size
- The size of the queue.public ArrayFIFOQueue(Nameable container)
container
- The container of the queue.public ArrayFIFOQueue(Nameable container, int size)
container
- The container of the queue.size
- The size of the queue.public ArrayFIFOQueue(ArrayFIFOQueue model)
model
- The queue to be copied.public void clear()
public java.lang.Object clone()
clone
in class java.lang.Object
public java.util.Enumeration elements()
public java.util.List elementList()
public java.lang.Object get(int offset) throws java.util.NoSuchElementException
offset
- The position of the desired object.java.util.NoSuchElementException
- If the offset is out of range.public int getCapacity()
setCapacity(int)
public Nameable getContainer()
setContainer(Nameable)
public int getHistoryCapacity()
setHistoryCapacity(int)
public java.util.Enumeration historyElements()
public int historySize()
public boolean isEmpty()
public boolean isFull()
public boolean put(java.lang.Object element)
element
- An object to be put in the queue.public boolean putArray(java.lang.Object[] element)
element
- An array of objects to be put in the queue.public boolean putArray(java.lang.Object[] element, int count)
element
- An array of objects to be put in the queue.count
- The number of objects to be put in the queue.public void setCapacity(int capacity) throws IllegalActionException
capacity
- The desired capacity.IllegalActionException
- If the queue contains more
objects than the proposed capacity or the proposed capacity
is illegal.getCapacity()
public void setContainer(Nameable container)
container
- The container of this queue.getContainer()
public void setHistoryCapacity(int capacity) throws IllegalActionException
capacity
- The desired capacity of the history queue.IllegalActionException
- If the desired capacity
is illegal.getHistoryCapacity()
public int size()
public java.lang.Object take()
java.util.NoSuchElementException
- If the queue is empty.public void takeArray(java.lang.Object[] objects) throws java.util.NoSuchElementException
objects
- An array of objects from the queue.java.util.NoSuchElementException
- If the queue is empty.public void takeArray(java.lang.Object[] objects, int count) throws java.util.NoSuchElementException
objects
- An array of objects from the queue.count
- The number of objects to return.java.util.NoSuchElementException
- If the queue is empty.