|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.zig_project.gpl.common.queue.LinearQueueBase
net.sf.zig_project.gpl.common.queue.ArrayQueue
Provides an array backed Queue. This Queue stores elements in an array, in a fashion
that ensures all Queue operations operate in O(1) time. This includes all methods
defined by LinearQueue
. It can also retrieve arbitary indexies in O(1) time.
However, inserations and removals to arbitrary indexies may require O(n) time.
Direct instansiations of this class are fixed length. For arbitrary length
Queues, a subclass should be used, such as DynamicArrayQueue
.
The documentation here makes reference to physical and relative
indices. Users of this class need only concern themselves with relative
indices, which are in the range of 0 to size()
. Subclasses may
need to consider physical indices, which specify a specific index within
the backing array itself.
Nested Class Summary | |
protected static class |
ArrayQueue.ArraySequencer
An Enumerable interface for ArrayQueue. |
Field Summary | |
protected int |
begin
|
protected int |
end
|
protected Object[] |
entries
|
Constructor Summary | |
ArrayQueue(int size)
Constructs a Queue with the specified size |
Method Summary | |
void |
addFirst(Object o)
Inserts the provided Object into the beginning of the queue, so that it is the new first element. |
void |
addLast(Object o)
Adds an Object to the end of the Queue. |
void |
addSet(Enumeration e)
Adds an enumerable set of elements to the end of the queue. |
int |
availableRoom()
Returns the amount of room available in this queue for elements to be added. |
protected void |
bulkMoveTest(LinearQueue q)
|
void |
clear()
Empties the Queue. |
boolean |
contains(Object o)
Determines if this Queue contains a copy of o. |
protected int |
decIndex(int idx)
Decrements a physical index within the queue wrapping it if necessary. |
Enumeration |
elements()
Retrieves a list of the elements currently in the queue in a form suitable to enumerate over. |
void |
ensureRoom(int rm)
|
protected int |
firstIndexOf(Object o)
Searches the queue for the first copy of o. |
protected int |
incIndex(int idx)
Increments a physical index within the queue wrapping it if necessary. |
void |
insert(Object o,
int index)
Inserts the specified object into the queue at the new relative index. |
boolean |
isEmpty()
Determines if the Queue is empty. |
protected void |
overflow(int rm)
This method is called when the queue is too full to continue an add operation. |
Object |
peek(int index)
Retrieves the Object located within the queue at the specified relative index. |
Object |
peekFirst()
Retrieves the first Object in the Queue. |
Object |
peekLast()
Retrieves the last Object in the Queue. |
protected int |
physicalIndex(int relative)
Retrieves the physical index for a given relative index. |
Object |
remove(int relative_index)
Removes an Object from the queue located at the specified relative index. |
Object |
remove(Object o)
Removes the first relative copy of o from the queue. |
Object |
removeFirst()
Removes the first element in the Queue. |
protected Object |
removeIndex(int idx)
Removes an Object from the queue located at the specified physical index. |
Object |
removeLast()
Removes the last element in the Queue. |
void |
replace(Object o,
int idx)
Replaces the Object in the queue at the provided relative index with the new Object. |
int |
size()
The current size of the queue. |
String |
toString()
Makes a String representation of all the current contents of the queue. |
String |
toString(String ele_sep)
Makes a String representation of all the current contents of the queue. |
Methods inherited from class net.sf.zig_project.gpl.common.queue.LinearQueueBase |
add, appendFlat, appendFlat, appendUnrolled, appendUnrolled, prependFlat, prependFlat, prependUnrolled, prependUnrolled, transferTo |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected Object[] entries
protected int begin
protected int end
Constructor Detail |
public ArrayQueue(int size)
size
- the size of the array of the queueMethod Detail |
public boolean isEmpty()
Queue
public void clear()
Queue
protected void bulkMoveTest(LinearQueue q)
bulkMoveTest
in class LinearQueueBase
public void ensureRoom(int rm)
public void addLast(Object o)
LinearQueue
o
- the Object to addpublic void addSet(Enumeration e)
addSet
in class LinearQueueBase
protected void overflow(int rm)
rm
- the amount of additional room requiredpublic int availableRoom()
public int size()
protected final int incIndex(int idx)
idx
- index to increment
protected final int decIndex(int idx)
idx
- index to decrement
protected int firstIndexOf(Object o)
o
- a copy of the Object to search for
public Object removeFirst()
addLast(java.lang.Object)
to emulate a FIFO queue.
public Object removeLast()
addLast(java.lang.Object)
to emulate a LIFO queue.
public Object peek(int index)
index
- the relative index to look up
IndexOutOfBoundsException
- if the index is
not a legal relative indexpublic Object peekFirst()
LinearQueue
public Object peekLast()
LinearQueue
public boolean contains(Object o)
o
- an Object to look for copies of
public Object remove(Object o)
o
- a copy of the Object to be removed
public Object remove(int relative_index)
relative_index
- the relative index to remove
from the queue
IndexOutOfBoundsException
- if the index is
not a legal relative indexprotected Object removeIndex(int idx)
idx
- the physical index to remove from the queue
public void replace(Object o, int idx)
o
- the new Object to place into the queueidx
- the relative index of the object to be replacedprotected int physicalIndex(int relative)
relative
- the relative index to convert
IndexOutOfBoundsException
- if the relative index
is not contained within this queuepublic void addFirst(Object o)
o
- the Object to be insertedpublic void insert(Object o, int index)
o
- the Object be inserted into the queueindex
- the relative index at which to insert the
Objectpublic Enumeration elements()
Queue
public String toString()
toString
in class LinearQueueBase
public String toString(String ele_sep)
ele_sep
- the seperator to use between each
element in the list
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |