|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--uk.org.ogsadai.common.FIFOQueue
Array-based implementation of the
uk.org.ogsadai.common.Queue interface, using a
first-in-first-out (FIFO) ordering of elements.
null.java.lang.Integer.MAX_VALUE elements.
DEFAULT_CAPACITY.
Queue| Nested Class Summary | |
protected class |
FIFOQueue.LocalIterator
|
| Field Summary | |
private static java.lang.String |
COPYRIGHT_NOTICE
|
static int |
DEFAULT_CAPACITY
Default fixed capacity. |
protected int |
mCapacity
Capacity of the queue. |
protected java.lang.Object[] |
mData
Array containing elements of the queue. |
private int |
mHeadIndex
|
private long |
mModificationCount
|
private int |
mSize
|
private int |
mTailIndex
|
| Constructor Summary | |
FIFOQueue()
Constructs a queue with a default capacity of DEFAULT_CAPACITY elements. |
|
FIFOQueue(int capacity)
Constructs a queue of given, fixed capacity. |
|
| Method Summary | |
private int |
dec(int index)
Circularly decrease indices into data array |
java.lang.Object |
element()
Retrieves the head of the queue without removing it. |
private int |
inc(int index)
Circularly increase indices into data array. |
java.util.Iterator |
iterator()
Returns an iterator over the elements in this queue. |
boolean |
offer(java.lang.Object obj)
Inserts, if possible, an object into the queue. |
java.lang.Object |
peek()
Retrieves the head of the queue without removing it. |
java.lang.Object |
poll()
Retrieves and removes the head of the queue. |
java.lang.Object |
remove()
Retrieves and removes the head of the queue. |
void |
remove(java.lang.Object item)
Removes the specified item from the queue. |
int |
size()
Returns the number of elements in this queue. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private static final java.lang.String COPYRIGHT_NOTICE
public static final int DEFAULT_CAPACITY
protected final java.lang.Object[] mData
protected int mCapacity
private int mSize
private int mHeadIndex
private int mTailIndex
private long mModificationCount
| Constructor Detail |
public FIFOQueue(int capacity)
throws java.lang.IllegalArgumentException
capacity - The desired capacity, which must be greater than 1.
java.lang.IllegalArgumentException - If the supplied capacity argument is less than 1.public FIFOQueue()
DEFAULT_CAPACITY elements.
| Method Detail |
public boolean offer(java.lang.Object obj)
throws java.lang.IllegalArgumentException
Queue
offer in interface Queueobj - The item to insert. Must not be null.
true if it was possible to add the element
to this queue, otherwise false.
java.lang.IllegalArgumentExceptionpublic java.lang.Object poll()
Queue
poll in interface Queuenull if the
queue is empty.
public java.lang.Object remove()
throws java.util.NoSuchElementException
Queuepoll, which performs a similar task, this method
throws an exception if called on an empty queue.
remove in interface Queuejava.util.NoSuchElementException - if this queue is empty.
public void remove(java.lang.Object item)
throws java.util.NoSuchElementException
Queue
remove in interface Queueitem - The item to remove.
java.util.NoSuchElementException - if this queue is empty.public java.lang.Object peek()
Queue
peek in interface Queuenull if the
queue is empty.
public java.lang.Object element()
throws java.util.NoSuchElementException
Queuepeek, which performs a similar task, this method
throws an exception if called on an empty queue.
element in interface Queuejava.util.NoSuchElementException - if this queue is empty.public int size()
Queue
size in interface Queuepublic java.util.Iterator iterator()
Queue
iterator in interface Queueprivate final int inc(int index)
index - Update index. If it reaches capacity then circle back to
the beginning of the queue.
private final int dec(int index)
index - Update index. If it reaches 0 then circle on to the
end of the queue.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||