|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.math.util.ExpandableDoubleArray
A DoubleArray implementation which automatically expands
an internal double array to handle an array of arbitrary length. This
implementation of DoubleArray is provided to support scenarios in
which the ultimate length of an array is unknown, and the
developer can control the expansion process through the
initialCapacity
and expansionFactor
parameters.
This implementation also allows a developer to:
setNumElements(int)
discardFrontElements(int)
The initialCapacity parameter sets the capacity of the initial storage array, and the expansionFactor is the factor by which the current storage capacity is multiplied each time the internal array needs to be expanded. Please note that the length of the internal storage array has nothing to do with the number of elements currently stored in this array. If one creates an instance of this class with an initialCapacity of "2" and an expansion factor of "2", and then adds 3546 elements to the array, this implementation will need to expand the array 10 times - first from 2 -> 4. then 4 -> 8, 8 -> 16, and so on until we reach 4096 which is sufficient to hold 3546 elements.
Field Summary | |
protected float |
expansionFactor
The expand factor of the array. |
protected int |
initialCapacity
The initial capacity of the array. |
protected double[] |
internalArray
This is the internal storage array. |
protected int |
numElements
Number of elements in the array |
protected int |
startIndex
Keeps track of a starting index |
Constructor Summary | |
ExpandableDoubleArray()
Create an expandable double array with the default initial capactiy of 16 and an expansion factor of 2.00 |
|
ExpandableDoubleArray(int initialCapacity)
Create an expandable double array with the specified initial capacity and the defult expansion factor of 2.00 |
|
ExpandableDoubleArray(int initialCapacity,
float expansionFactor)
Create an expandable double array with the specificed initial capacity and expand factor. |
Method Summary | |
void |
addElement(double value)
Adds an element to the end of this expandable array |
double |
addElementRolling(double value)
Adds an element and moves the window of elements up one. |
void |
clear()
Clear the array, reset the size to the initialCapacity and the number of elements to zero. |
void |
discardFrontElements(int i)
Discards values from the front of the list. |
protected void |
expand()
Expands the internal storage array using the expansion factor |
double |
getElement(int index)
Returns the element at the specified index |
double[] |
getElements()
Returns a double[] of elements |
float |
getExpansionFactor()
The expansion factor controls the size of a new aray when an array needs to be expanded. |
int |
getNumElements()
Returns the number of elements currently in the array. |
double[] |
getValues()
Returns the internal storage array |
void |
setElement(int index,
double value)
Sets the element at the specified index. |
void |
setExpansionFactor(float expansionFactor)
Sets the expansion factor for this expandable double array. |
void |
setInitialCapacity(int initialCapacity)
Sets the initial capacity |
void |
setNumElements(int i)
This function allows you to control the number of elements contained in this array, and can be used to "throw" out the last n values in an array. |
int |
start()
Returns the starting index of the internal array. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected double[] internalArray
protected int numElements
protected int startIndex
protected int initialCapacity
protected float expansionFactor
Constructor Detail |
public ExpandableDoubleArray()
public ExpandableDoubleArray(int initialCapacity)
initialCapacity
- The initial size of the internal storage arraypublic ExpandableDoubleArray(int initialCapacity, float expansionFactor)
initialCapacity
- The initial size of the internal storage arrayexpansionFactor
- the array will be expanded based on this
parameterMethod Detail |
public float getExpansionFactor()
public void setExpansionFactor(float expansionFactor)
expansionFactor
- the expansion factor of this arraypublic void setInitialCapacity(int initialCapacity)
initialCapacity
- of the arraypublic double[] getValues()
public int start()
public int getNumElements()
getNumElements
in interface DoubleArray
public void setNumElements(int i)
i
- a new number of elementspublic double getElement(int index)
getElement
in interface DoubleArray
index
- index to fetch a value from
public void setElement(int index, double value)
setElement
in interface DoubleArray
index
- index to store a value invalue
- value to store at the specified indexprotected void expand()
public void addElement(double value)
addElement
in interface DoubleArray
value
- value to be added to end of arraypublic double addElementRolling(double value)
addElementRolling
in interface DoubleArray
value
- the value to add
public void clear()
clear
in interface DoubleArray
public void discardFrontElements(int i)
i
- number of elements to discard from the front of the array.public double[] getElements()
DoubleArray
getElements
in interface DoubleArray
DoubleArray.getElements()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |