|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.domains.sdf.kernel.ArrayFIFOQueue
public final class ArrayFIFOQueue
A first-in, first-out (FIFO) queue with variable capacity and optional history. Objects are appended to the queue with the put() method, and removed from the queue with the take() method. The object removed is the oldest one in the queue. By default, the capacity is infinite, but it can be set to any nonnegative size. If the history capacity is greater than zero (or infinite, by setting the capacity to INFINITE_CAPACITY), then objects removed from the queue are transferred to a history queue rather than simply removed. By default, the history capacity is zero.
This queue is implemented as a circular array. When the array becomes full, it is transparently doubled in size.
Yellow (johnr) |
Yellow (neuendor) |
Field Summary | |
---|---|
private Nameable |
_container
The container, if there is one. |
private int |
_historyCapacity
The capacity of the history queue, defaulting to zero. |
private java.util.LinkedList |
_historyList
The list of objects recently removed from the queue. |
private java.lang.Object[] |
_queueArray
The list of objects currently in the queue. |
private int |
_queueBack
The location of the next place to remove from _queueArray. |
private int |
_queueFront
The location of the next place to insert in _queueArray. |
private int |
_queueMaxCapacity
The maximum capacity of the queue. |
private int |
_queueSize
The number of elements in the queue. |
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 Summary | |
---|---|
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. |
Method Summary | |
---|---|
private void |
_resizeArray(int newSize)
Resize the internal circular array to have the given size. |
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. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
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
private Nameable _container
private int _queueMaxCapacity
private java.lang.Object[] _queueArray
private int _queueFront
private int _queueBack
private int _queueSize
private int _historyCapacity
private java.util.LinkedList _historyList
Constructor Detail |
---|
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.Method Detail |
---|
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.private void _resizeArray(int newSize)
InternalErrorException
- If the proposed size is greater than
the declared maximum size, or if the queue contains more
objects than the proposed size or the proposed size
is illegal.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |