Type-specific queue collection classes. The classes in this package implement type-specific circular queues based on growable arrays. They support a subset of the normal collection methods, as well as appropriate queue methods. The standard public access methods in these classes are as follows:
Method Signature | From |
void add(type) | implementation class |
void clear() | {@link com.sosnoski.util.queue.QueueBase} |
Object clone() | implementation class |
void discard(int) | {@link com.sosnoski.util.queue.QueueBase} |
void ensureCapacity(int) | {@link com.sosnoski.util.GrowableBase} |
boolean isEmpty() | {@link com.sosnoski.util.queue.QueueBase} |
type remove() | implementation class |
int size() | {@link com.sosnoski.util.queue.QueueBase} |
type[] toArray() | implementation class |
The access methods are unsynchronized for best performance. The user program must implement appropriate locking if multiple threads need to access an instance of these classes while that instance may be modified.
Collections of a primitive type and of a specific object type are both supported. All variations derive directly from the {@link com.sosnoski.util.queue.QueueBase} base class. To define a circular queue of a new type, generally you can use one of the existing classes as a base and do a text substitution of the type names.
For instance, to define a circular queue of instances of
Thread
just copy StringQueue.java
to a new file named ThreadQueue.java
, then do a global
text substitution of "Thread" for "String" in the
new file.
Primitive types are only slightly more complicated. To implement a
circular queue of a primitive type other than the included int
,
you're best off basing it on StringQueue.java
. If you're doing
this for double
, for instance, you'd need to first substitute
"DoubleQueue" for "StringQueue", then "double" for "String". The last step is deleting the
"m_baseArray[index] = null;" line within the remove
method, which is not needed for primitive types.