com.sosnoski.util.queue
Class IntQueue

java.lang.Object
  |
  +--com.sosnoski.util.GrowableBase
        |
        +--com.sosnoski.util.queue.QueueBase
              |
              +--com.sosnoski.util.queue.IntQueue

public class IntQueue
extends QueueBase

Growable circular queue of ints. This implementation is unsynchronized in order to provide the best possible performance for typical usage scenarios, so explicit synchronization must be implemented by a wrapper class or directly by the application in cases where instances are modified in a multithreaded environment. See the base classes for other details of the implementation.

Version:
1.0
Author:
Dennis M. Sosnoski

Field Summary
protected  int[] m_baseArray
          The underlying array used for storing the data.
 
Fields inherited from class com.sosnoski.util.queue.QueueBase
m_emptyOffset, m_fillOffset
 
Fields inherited from class com.sosnoski.util.GrowableBase
DEFAULT_SIZE, m_countLimit, m_maximumGrowth
 
Constructor Summary
IntQueue()
          Default constructor.
IntQueue(int size)
          Constructor with partial specification.
IntQueue(int size, int growth)
          Constructor with full specification.
IntQueue(IntQueue base)
          Copy (clone) constructor.
 
Method Summary
 void add(int item)
          Add an item at the end of the queue.
 java.lang.Object clone()
          Duplicates the object with the generic call.
protected  java.lang.Object getArray()
          Get the backing array.
 int remove()
          Remove an item from the start of the queue.
protected  void setArray(java.lang.Object array)
          Set the backing array.
 int[] toArray()
          Constructs and returns a simple array containing the same data as held in this growable array.
 
Methods inherited from class com.sosnoski.util.queue.QueueBase
buildArray, clear, discard, getAddIndex, getRemoveIndex, isEmpty, resizeCopy, size
 
Methods inherited from class com.sosnoski.util.GrowableBase
buildArray, discardValues, ensureCapacity, growArray
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_baseArray

protected int[] m_baseArray
The underlying array used for storing the data.
Constructor Detail

IntQueue

public IntQueue(int size,
                int growth)
Constructor with full specification.
Parameters:
size - number of elements initially allowed in queue
growth - maximum size increment for growing queue

IntQueue

public IntQueue(int size)
Constructor with partial specification.
Parameters:
size - number of elements initially allowed in queue

IntQueue

public IntQueue()
Default constructor.

IntQueue

public IntQueue(IntQueue base)
Copy (clone) constructor.
Parameters:
base - instance being copied
Method Detail

getArray

protected java.lang.Object getArray()
Get the backing array. This method is used by the type-agnostic base class code to access the array used for type-specific storage.
Overrides:
getArray in class GrowableBase
Returns:
backing array object

setArray

protected void setArray(java.lang.Object array)
Set the backing array. This method is used by the type-agnostic base class code to set the array used for type-specific storage.
Overrides:
setArray in class GrowableBase
Parameters:
backing - array object

add

public void add(int item)
Add an item at the end of the queue. If necessary, the array used for storing the queue data is grown before storing the added item.
Parameters:
item - item to be added

remove

public int remove()
Remove an item from the start of the queue.
Returns:
item removed from queue
Throws:
IllegalStateException - on attempt to remove an item from an empty queue

toArray

public int[] toArray()
Constructs and returns a simple array containing the same data as held in this growable array.
Returns:
array containing a copy of the data

clone

public java.lang.Object clone()
Duplicates the object with the generic call.
Overrides:
clone in class java.lang.Object
Returns:
a copy of the object


Company Web Site

XML Benchmark Home