java.lang.Object
ij.util.FloatArray
This class implements an expandable float array similar
to an ArrayList or Vector but more efficient.
Calls to this class are not synchronized.
- Author:
- Michael Schmid
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new expandable array with an initial capacity of 100.FloatArray(int initialCapacity) Creates a new expandable array with specified initial capacity. -
Method Summary
Modifier and TypeMethodDescriptionintadd(float value) Appends the specified value to the end of this FloatArray.intadd(float[] a, int n) Appends the first n values from the specified array to this FloatArray.voidclear()Removes all elements form this FloatArray.floatget(int index) Returns the element at the specified position in this FloatArray.floatgetLast()Returns the last element of this FloatArray.voidremoveLast(int n) Deletes the lastnelement from this FloatArray.floatset(int index, float value) Replaces the element at the specified position with the value given.intsize()Returns the number of elements in the array.float[]toArray()Returns a float array containing all elements of this FloatArray.voidTrims the capacity of this FloatArray instance to be its current size, minimizing the storage of the FloatArray instance.
-
Constructor Details
-
FloatArray
public FloatArray()Creates a new expandable array with an initial capacity of 100. -
FloatArray
public FloatArray(int initialCapacity) Creates a new expandable array with specified initial capacity.- Throws:
IllegalArgumentException- if the specified initial capacity is less than zero
-
-
Method Details
-
size
public int size()Returns the number of elements in the array. -
clear
public void clear()Removes all elements form this FloatArray. -
toArray
public float[] toArray()Returns a float array containing all elements of this FloatArray. -
get
public float get(int index) Returns the element at the specified position in this FloatArray.- Throws:
IndexOutOfBoundsException- - if index is out of range (index invalid input: '<' 0 || index >= size()).
-
getLast
public float getLast()Returns the last element of this FloatArray.- Throws:
IndexOutOfBoundsException- - if this FloatArray is empty
-
set
public float set(int index, float value) Replaces the element at the specified position with the value given.- Returns:
- the value previously at the specified position.
- Throws:
IndexOutOfBoundsException- - if index is out of range (index invalid input: '<' 0 || index >= size()).
-
add
public int add(float value) Appends the specified value to the end of this FloatArray. Returns the number of elements after adding. -
add
public int add(float[] a, int n) Appends the first n values from the specified array to this FloatArray. Returns the number of elements after adding. -
removeLast
public void removeLast(int n) Deletes the lastnelement from this FloatArray.nmay be larger than the number of elements; in that case, all elements are removed. -
trimToSize
public void trimToSize()Trims the capacity of this FloatArray instance to be its current size, minimizing the storage of the FloatArray instance.
-