|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectch.javasoft.util.DoubleArray
public class DoubleArray
The DoubleArray is an dynamic size array for doubles. Values can be
added causing the array to grow dynamically.
| Constructor Summary | |
|---|---|
DoubleArray()
Constructor for DoubleArray with default capacity |
|
DoubleArray(double[] initialValues)
Constructor for DoubleArray with specified values. |
|
DoubleArray(double[] original,
int from,
int to)
Constructor for DoubleArray with specified values. |
|
DoubleArray(int capacity)
Constructor for DoubleArray with default capacity |
|
| Method Summary | |
|---|---|
void |
add(double value)
Adds the specified value to the end of this double array |
boolean |
add(int index,
double value)
Adds the specified value at the given position of the array. |
void |
addAll(double... values)
Adds the specified values to the end of this double array |
void |
addAll(DoubleArray array)
Adds the values from array to the end of this double array |
void |
addAll(int from,
int to,
double... values)
Adds the specified values to the end of this double array |
void |
addAll(int from,
int to,
DoubleArray array)
Adds the values from array to the end of this int array |
int |
addToSorted(double value)
Adds the given value at the position where the value fits according to binarySearch(double). |
int |
binarySearch(double key)
Searches this int array for the specified value using the binary search algorithm. |
int |
binarySearch(double key,
int fromIndex,
int toIndex)
Searches this int array for the specified value using the binary search algorithm. |
void |
clear()
Removes all elements, but does not shrink the underlying array (that is, the capacity is kept as it is). |
DoubleArray |
clone()
Returns a clone of this double array |
static double[][] |
clone(double[][] arr)
Returns a deep clone of the given array |
protected void |
ensureCapacity(int size)
Internal method, called to ensure capacity size |
boolean |
equals(Object obj)
|
double |
first()
Returns the first element, or throws an IndexOutOfBoundsException
if the array is empty |
double |
get(int index)
Returns the value at the specified position |
int |
hashCode()
|
int |
indexOf(double value)
Returns the first index containing a value equal to the specified value. |
int |
indexOf(int fromIndex,
double value)
Returns the first index containing a value equal to the specified value starting at position fromIndex. |
protected double |
initialValue()
This method can be overriden to define an alternate initial value. |
boolean |
isEmpty()
Returns true if the array length is zero |
Iterator<Double> |
iterator()
Returns an immutable iterator with the double values of this array |
double |
last()
Returns the last element, or throws an IndexOutOfBoundsException
if the array is empty |
int |
length()
Returns the current length of this array, that is, the number of elements in the array. |
double |
remove(int index)
Removes the specified value and moves all values on the right one position leftwards. |
double |
removeLast()
Removes the last value, or throws an IndexOutOfBoundsException if
the array is empty. |
double |
set(int index,
double value)
Sets the value at the specified position. |
void |
sort(boolean ascending)
Sort the array ascending or descending. |
void |
sort(boolean ascending,
int start,
int end)
Sort the specified array range ascending or descending. |
DoubleArray |
subRange(int from)
Returns a new array instance containing a copy of a range of this array. |
DoubleArray |
subRange(int from,
int to)
Returns a new array instance containing a copy of a range of this array. |
static void |
swap(double[] arr,
int indexA,
int indexB)
Interchange the values at the specified array positions |
void |
swap(int indexA,
int indexB)
Interchange the values at the specified positions |
double[] |
toArray()
Clones the underlying array (trimmed to length) and returns it |
static double[][] |
toMatrix(Collection<double[]> mx,
boolean cloneArrays)
Converts the given collection of double arrays to a two dimensional double array. |
static double[][] |
toMatrix(Collection<DoubleArray> mx)
Converts the given collection of DoubleArray instances to a
two dimensional double array |
static double[][] |
toMatrix(DoubleArray[] mx)
Converts the given array of DoubleArray instances to a two
dimensional double array |
String |
toString()
Returns a string representation of the contents of this array. |
void |
trimToLength()
Fixes the capacity of the underlying array to the current length of this array. |
double[] |
yieldArray()
Returns the internal array after trimming it to the current length and returns it. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public DoubleArray()
DoubleArray with default capacity
public DoubleArray(int capacity)
DoubleArray with default capacity
public DoubleArray(double[] initialValues)
DoubleArray with specified values. The given
array is not cloned, thus, changes to the array are also reflected in
the state this DoubleArray.
public DoubleArray(double[] original,
int from,
int to)
DoubleArray with specified values. The given
array is cloned.
Copies the specified range of the specified array into this new array. The initial index of the range (from) must lie between zero and original.length, inclusive. The value at original[from] is placed into the initial element of the copy (unless from == original.length or from == to). Values from subsequent elements in the original array are placed into subsequent elements in the copy. The final index of the range (to), which must be greater than or equal to from, may be greater than original.length, in which case 0d is placed in all elements of the copy whose index is greater than or equal to original.length - from. The length of the this array will be to - from.
original - the array from which a range is to be copiedfrom - the initial index of the range to be copied, inclusiveto - the final index of the range to be copied, exclusive.
(This index may lie outside the array.)| Method Detail |
|---|
public int length()
public boolean isEmpty()
length is zero
public double get(int index)
throws IndexOutOfBoundsException
IndexOutOfBoundsExceptionpublic int indexOf(double value)
value. If no such value is found, -1 is
returned.
value - the value to search for
value, or
-1 if no such value is found
public int indexOf(int fromIndex,
double value)
value starting at position fromIndex. If no
such value is found, -1 is returned.
fromIndex - the index (inclusive) at which the search is startedvalue - the value to search for
value, or
-1 if no such value is found
public double set(int index,
double value)
throws IndexOutOfBoundsException
index is
smaller than the current length(), the value at the specified
position is replaced by value. If index equal
to the length of this array, the value is appended. If it
is larger than length, it is also appended after filling the
gap positions with initial values.
index - the index at which value will be storedvalue - the new value to be set
IndexOutOfBoundsExceptionpublic void add(double value)
public void addAll(DoubleArray array)
array to the end of this double array
public void addAll(int from,
int to,
DoubleArray array)
array to the end of this int array
public void addAll(double... values)
public void addAll(int from,
int to,
double... values)
public boolean add(int index,
double value)
index is negative or larger than the current
length of this array, an
IndexOutOfBoundsException is thrown.
public double removeLast()
IndexOutOfBoundsException if
the array is empty.
public double remove(int index)
IndexOutOfBoundsException - if index is negative or
larger or equal to
lengthpublic void clear()
public double first()
IndexOutOfBoundsException
if the array is empty
public double last()
IndexOutOfBoundsException
if the array is empty
public void swap(int indexA,
int indexB)
protected void ensureCapacity(int size)
size
size - the desired capacityprotected double initialValue()
set(int, double) is used with an index
larger than the length of the array.
Default initial value is 0
public double[] toArray()
public double[] yieldArray()
DoubleArray will be empty after this
operation.
public DoubleArray clone()
clone in class Objectpublic DoubleArray subRange(int from)
from (inclusive) to the end of this
array.
from - the start index of the range, inclusive
public DoubleArray subRange(int from,
int to)
from (inclusive) to to
(exclusive).
from - the start index of the range, inclusiveto - the end index of the range, exclusive
public Iterator<Double> iterator()
iterator in interface Iterable<Double>public static double[][] toMatrix(DoubleArray[] mx)
DoubleArray instances to a two
dimensional double array
mx - the array of DoubleArray instances to convert to
a 2-dim array
public static double[][] toMatrix(Collection<DoubleArray> mx)
DoubleArray instances to a
two dimensional double array
mx - the collection of arrays to convert to a 2-dim array
public static double[][] toMatrix(Collection<double[]> mx,
boolean cloneArrays)
mx - the collection of arrays to convert to a 2-dim arraycloneArrays - if true, the source arrays are cloned
public static void swap(double[] arr,
int indexA,
int indexB)
public static double[][] clone(double[][] arr)
public void trimToLength()
length of this array. Note that this operation might
be expensive due to array copying.
public int binarySearch(double key)
throws IllegalStateException
sort(boolean) method) prior to making this
call. If it is not sorted, the results are undefined. If the array
contains multiple elements with the specified value, there is no
guarantee which one will be found.
key - the value to be searched for.
IllegalStateExceptionArrays.binarySearch(int[], int, int, int)
public int binarySearch(double key,
int fromIndex,
int toIndex)
throws IllegalStateException
sort(boolean) method) prior to making this
call. If it is not sorted, the results are undefined. If the array
contains multiple elements with the specified value, there is no
guarantee which one will be found.
key - the value to be searched for.fromIndex - the index of the first element (inclusive) to be
searchedtoIndex - the index of the last element (exclusive) to be searched
IllegalStateExceptionArrays.binarySearch(int[], int, int, int)public int addToSorted(double value)
binarySearch(double). If this int array is not sorted
ascending, the result is undefined.
value - the value to insert
public void sort(boolean ascending)
binarySearch(double) and
addToSorted(double) methods can be used
ascending - true for ascending sort order
public void sort(boolean ascending,
int start,
int end)
binarySearch(double) and
addToSorted(double) methods can be used.
This method should only be used if one knows that only the defined
interval needs sorting. Otherwise, sort(boolean) should be used
instead.
ascending - true for ascending sort orderstart - the index where the sorting starts (inclusive)end - the index where the sorting ends (exclusive)public int hashCode()
hashCode in class Objectpublic boolean equals(Object obj)
equals in class Objectpublic String toString()
toString in class ObjectArrays.toString(double[])
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||