com.virtuosotechnologies.lib.ring
Class IntRing

java.lang.Object
  extended bycom.virtuosotechnologies.lib.ring.AbstractRing
      extended bycom.virtuosotechnologies.lib.ring.IntRing

public class IntRing
extends AbstractRing

Circular buffer of ints. This class is not thread-safe.


Constructor Summary
IntRing()
          Constructs an empty buffer with a capacity of 16.
IntRing(int initialCapacity)
          Constructs an empty buffer with the specified initial capacity.
 
Method Summary
protected  Object allocateArray(int capacity)
          Override this method to allocate an array of the desired type.
protected  void clearArrayValues(Object array, int start, int end)
          Override this method to clear the specified values in the array.
protected  int getArrayLength(Object array)
          Override this method to get the length of the array.
 int getInt(int index)
          Gets the value of a particular int
 int[] getRange(int start, int end)
          Gets a range of values as a new array.
 void getRange(int start, int end, int[] destination, int pos)
          Gets a range of values and copies it into the given array.
protected  void initArrayValues(Object array, int start, int end)
          Override this method to initialize the specified values in the array.
 int popBack()
          Pop an int from the back.
 int[] popBack(int size)
          Pop an int array from the back.
 void popBack(int size, int[] buffer, int pos)
          Pop an int array from the back.
 int popFront()
          Pop an int from the front.
 int[] popFront(int size)
          Pop an int array from the front.
 void popFront(int size, int[] buffer, int pos)
          Pop an int array from the front.
 void pushBack(int v)
          Push an int to the back
 void pushBack(int[] array)
          Push an int array to the back
 void pushFront(int v)
          Push an int to the front
 void pushFront(int[] array)
          Push an int array to the front
 void setInt(int index, int value)
          Sets the value of a particular int
 void setRange(int start, int end, int[] source, int pos)
          Sets a range of values from the given array.
 
Methods inherited from class com.virtuosotechnologies.lib.ring.AbstractRing
addBack, addFront, addMiddle, calculateRawIndex, clear, ensureCapacity, getRangeRaw, getRawArray, getSize, removeBack, removeFront, removeMiddle, setRangeRaw, trimToSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IntRing

public IntRing(int initialCapacity)
Constructs an empty buffer with the specified initial capacity.

Parameters:
initialCapacity - the initial capacity of the buffer.
Throws:
IllegalArgumentException - if the specified initial capacity is negative

IntRing

public IntRing()
Constructs an empty buffer with a capacity of 16.

Method Detail

allocateArray

protected Object allocateArray(int capacity)
Override this method to allocate an array of the desired type.

Specified by:
allocateArray in class AbstractRing
Parameters:
capacity - size of the array to allocate
Returns:
the allocated array

getArrayLength

protected int getArrayLength(Object array)
Override this method to get the length of the array.

Specified by:
getArrayLength in class AbstractRing
Parameters:
array - an array object
Returns:
the size of the array

clearArrayValues

protected void clearArrayValues(Object array,
                                int start,
                                int end)
Override this method to clear the specified values in the array.

Specified by:
clearArrayValues in class AbstractRing
Parameters:
array - an array object
start - the index of the first item to clear
end - one more than the index of the last item to clear

initArrayValues

protected void initArrayValues(Object array,
                               int start,
                               int end)
Override this method to initialize the specified values in the array.

Specified by:
initArrayValues in class AbstractRing
Parameters:
array - an array object
start - the index of the first item to initialize
end - one more than the index of the last item to initialize

getInt

public int getInt(int index)
Gets the value of a particular int

Parameters:
index - index to query
Returns:
the byte

setInt

public void setInt(int index,
                   int value)
Sets the value of a particular int

Parameters:
index - index to set
value - the byte

getRange

public void getRange(int start,
                     int end,
                     int[] destination,
                     int pos)
Gets a range of values and copies it into the given array.

Parameters:
start - starting position in the buffer
end - one more than the ending position in the buffer
destination - destination array
pos - starting position in the destination array

getRange

public int[] getRange(int start,
                      int end)
Gets a range of values as a new array.

Parameters:
start - starting position in the buffer
end - one more than the ending position in the buffer
Returns:
copy of the values

setRange

public void setRange(int start,
                     int end,
                     int[] source,
                     int pos)
Sets a range of values from the given array.

Parameters:
start - starting position in the buffer
end - one more than the ending position in the buffer
source - source array
pos - starting position in the source array

pushFront

public void pushFront(int v)
Push an int to the front

Parameters:
v - the int

pushFront

public void pushFront(int[] array)
Push an int array to the front

Parameters:
array - the array

pushBack

public void pushBack(int v)
Push an int to the back

Parameters:
v - the int

pushBack

public void pushBack(int[] array)
Push an int array to the back

Parameters:
array - the array

popBack

public int popBack()
Pop an int from the back.

Returns:
the int
Throws:
NoSuchElementException - ring is empty

popBack

public int[] popBack(int size)
Pop an int array from the back.

Parameters:
size - number of ints to pop.
Returns:
the array
Throws:
NoSuchElementException - ring isn't large enough

popBack

public void popBack(int size,
                    int[] buffer,
                    int pos)
Pop an int array from the back.

Parameters:
size - number of ints to pop.
buffer - the array to populate
pos - position in the buffer
Throws:
NoSuchElementException - ring isn't large enough

popFront

public int popFront()
Pop an int from the front.

Returns:
the int
Throws:
NoSuchElementException - ring is empty

popFront

public int[] popFront(int size)
Pop an int array from the front.

Parameters:
size - number of ints to pop.
Returns:
the array
Throws:
NoSuchElementException - ring isn't large enough

popFront

public void popFront(int size,
                     int[] buffer,
                     int pos)
Pop an int array from the front.

Parameters:
size - number of ints to pop.
buffer - the array to populate
pos - position in the buffer
Throws:
NoSuchElementException - ring isn't large enough