Package org.web3d.util
Class DoubleArray
java.lang.Object
org.web3d.util.DoubleArray
Simple dynamic array structure that holds double primitives.
- Version:
- $Revision: 1.5 $
- Author:
- Justin Couch
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new default array with size 512 itemsDoubleArray
(int initialSize) Create an array with the given initial size -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(double newDouble) Add a new value to the array.void
add
(double[] values) Add an array of values in bulk to the array.void
clear()
Clear the array so that it contains no valuesdouble
get
(int index) Get the value at the given index.double
remove
(int index) Remove the value at the given index.void
set
(int index, double value) Set the value at the given index.int
size()
Get the count of the number of items in the array.double[]
toArray()
Turn the values of this array into a real array.double[]
toArray
(double[] values) Turn the values of this array into a real array by copying them into the given array if possible.
-
Constructor Details
-
DoubleArray
public DoubleArray()Create a new default array with size 512 items -
DoubleArray
public DoubleArray(int initialSize) Create an array with the given initial size- Parameters:
initialSize
- The size to start with
-
-
Method Details
-
size
public int size()Get the count of the number of items in the array.- Returns:
- The number of items in the array
-
clear
public void clear()Clear the array so that it contains no values -
add
public void add(double newDouble) Add a new value to the array. Will resize the array if needed to accommodate new values.- Parameters:
newDouble
- the value to be added
-
add
public void add(double[] values) Add an array of values in bulk to the array. The array should not be null.- Parameters:
values
- The values to be added
-
get
public double get(int index) Get the value at the given index.- Parameters:
index
- The position to get values from- Returns:
- The value at that index
- Throws:
IndexOutOfBoundsException
- The index was not legal
-
set
public void set(int index, double value) Set the value at the given index. If the index is out of the range of the current items, it will generate an index exception.- Parameters:
index
- The position to get values fromvalue
- The new value to set- Throws:
IndexOutOfBoundsException
- The index was not legal
-
remove
public double remove(int index) Remove the value at the given index.- Parameters:
index
- The position to remove the value from- Returns:
- The value at that index
- Throws:
IndexOutOfBoundsException
- The index was not legal
-
toArray
public double[] toArray()Turn the values of this array into a real array. Returns an array with the exact number of items in it. This is a separate copy of the internal array.- Returns:
- The array of values
-
toArray
public double[] toArray(double[] values) Turn the values of this array into a real array by copying them into the given array if possible. If the array is big enough then it will copy the values straight in. If not, it will ignore that array and create it's own copy and return that. If the passed array is used, the return value will be a reference to the passed array, otherwise it will be the new copy.- Parameters:
values
- The array to copy values to- Returns:
- The array of values
-