Package org.hortonmachine.gears.utils
Class DynamicDoubleArray
- java.lang.Object
-
- org.hortonmachine.gears.utils.DynamicDoubleArray
-
public class DynamicDoubleArray extends Object
A wrapper for a dynamic growing array.- Since:
- 0.7.3
- Author:
- Andrea Antonello (www.hydrologis.com)
-
-
Constructor Summary
Constructors Constructor Description DynamicDoubleArray(int initalSize)Create the array with an initial size.DynamicDoubleArray(int initalSize, int growingSize)Create the array with an initial size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddValue(double value)Add a value at the end of the array.double[]getInternalArray()Get the internal array.intgetLastIndex()Get the last used index.double[]getTrimmedInternalArray()Get a trimmed version of the array, i.e.doublegetValue(int position)Get the value in a certain position of the array.voidsetValue(int position, double value)Safe set the value in a certain position.
-
-
-
Constructor Detail
-
DynamicDoubleArray
public DynamicDoubleArray(int initalSize)
Create the array with an initial size.- Parameters:
initalSize- the initial size.
-
DynamicDoubleArray
public DynamicDoubleArray(int initalSize, int growingSize)Create the array with an initial size.- Parameters:
initalSize- the initial size.growingSize- the size to grow the array additionally, if the array was too small.
-
-
Method Detail
-
setValue
public void setValue(int position, double value)Safe set the value in a certain position.If the array is smaller than the position, the array is extended and substituted.
- Parameters:
position- the index in which to set the value.value- the value to set.
-
addValue
public void addValue(double value)
Add a value at the end of the array.- Parameters:
value- the value to add.
-
getValue
public double getValue(int position)
Get the value in a certain position of the array.- Parameters:
position- the position.- Returns:
- the value.
-
getLastIndex
public int getLastIndex()
Get the last used index.- Returns:
- the last used index.
-
getInternalArray
public double[] getInternalArray()
Get the internal array.- Returns:
- the array.
-
getTrimmedInternalArray
public double[] getTrimmedInternalArray()
Get a trimmed version of the array, i.e. without ending unset positions.- Returns:
- the trimmed array.
-
-