|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.virtuosotechnologies.lib.ring.AbstractRing
Circular buffer abstract base class. This class is not thread-safe.
| Constructor Summary | |
protected |
AbstractRing(int initialCapacity)
Constructs an empty buffer with the specified initial capacity. |
| Method Summary | |
void |
addBack(int num)
Extends the size of the buffer to the back. |
void |
addFront(int num)
Extends the size of the buffer to the front. |
void |
addMiddle(int index,
int num)
Inserts elements into the middle of the buffer. |
protected abstract Object |
allocateArray(int capacity)
Override this method to allocate an array of the desired type. |
protected int |
calculateRawIndex(int index)
Calculates the real index into the array given the buffer index. |
void |
clear()
Clears the buffer, setting its size to 0. |
protected abstract void |
clearArrayValues(Object array,
int start,
int end)
Override this method to clear the specified values in the array. |
void |
ensureCapacity(int minCapacity)
Increases the capacity of this ring, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument. |
protected abstract int |
getArrayLength(Object array)
Override this method to get the length of the array. |
protected void |
getRangeRaw(int start,
int end,
Object destination,
int pos)
Gets a range of values and copies it into the given array. |
protected Object |
getRawArray()
Gets the current array object. |
int |
getSize()
Returns the number of elements in this ring. |
protected abstract void |
initArrayValues(Object array,
int start,
int end)
Override this method to initialize the specified values in the array. |
void |
removeBack(int num)
Truncates the size of the buffer to the back. |
void |
removeFront(int num)
Truncates the size of the buffer to the front. |
void |
removeMiddle(int fromIndex,
int toIndex)
Removes elements from the middle of the buffer. |
protected void |
setRangeRaw(int start,
int end,
Object source,
int pos)
Sets a range of values from the given array. |
void |
trimToSize()
Trims the capacity of this ring to be the buffer's current size. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
protected AbstractRing(int initialCapacity)
initialCapacity - the initial capacity of the buffer.
IllegalArgumentException - if the specified initial capacity
is negative| Method Detail |
protected abstract Object allocateArray(int capacity)
capacity - size of the array to allocate
protected abstract int getArrayLength(Object array)
array - an array object
protected abstract void clearArrayValues(Object array,
int start,
int end)
array - an array objectstart - the index of the first item to clearend - one more than the index of the last item to clear
protected abstract void initArrayValues(Object array,
int start,
int end)
array - an array objectstart - the index of the first item to initializeend - one more than the index of the last item to initializeprotected final Object getRawArray()
protected final int calculateRawIndex(int index)
index - index into the buffer
protected final void getRangeRaw(int start,
int end,
Object destination,
int pos)
start - starting position in the bufferend - one more than the ending position in the bufferdestination - destination arraypos - starting position in the destination array
protected final void setRangeRaw(int start,
int end,
Object source,
int pos)
start - starting position in the bufferend - one more than the ending position in the buffersource - source arraypos - starting position in the source arraypublic void trimToSize()
public void ensureCapacity(int minCapacity)
minCapacity - the desired minimum capacity.public int getSize()
public void addFront(int num)
num - number of elements to addpublic void removeFront(int num)
num - number of elements to removepublic void addBack(int num)
num - number of elements to addpublic void removeBack(int num)
num - number of elements to removepublic void clear()
public void addMiddle(int index,
int num)
index - index at which to begin inserting elementsnum - number of elements to insert
IndexOutOfBoundsException - if index out of range
public void removeMiddle(int fromIndex,
int toIndex)
fromIndex - first indextoIndex - one more than last index
IndexOutOfBoundsException - if index out of range
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||