Class ArrayLikeUtil
- java.lang.Object
-
- elki.utilities.datastructures.arraylike.ArrayLikeUtil
-
public final class ArrayLikeUtil extends java.lang.Object
Utility class that allows plug-in use of various "array-like" types such as lists in APIs that can take any kind of array to safe the cost of reorganizing the objects into a real array.- Since:
- 0.5.0
- Author:
- Erich Schubert
-
-
Field Summary
Fields Modifier and Type Field Description static NumberArrayAdapter<java.lang.Double,double[]>
DOUBLEARRAYADAPTER
Use a double array in the array API.static FeatureVectorAdapter<?>
FEATUREVECTORADAPTER
Static instance.static NumberArrayAdapter<java.lang.Float,float[]>
FLOATARRAYADAPTER
Use a float array in the array API.static NumberVectorAdapter
NUMBERVECTORADAPTER
Use a number vector in the array API.
-
Constructor Summary
Constructors Modifier Constructor Description private
ArrayLikeUtil()
Fake constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <F> FeatureVectorAdapter<F>
featureVectorAdapter(FeatureVector<F> prototype)
Get the static instance.static int
getIndexOfMaximum(double[] array)
Returns the index of the maximum of the given values.static <A> int
getIndexOfMaximum(A array, NumberArrayAdapter<?,A> adapter)
Returns the index of the maximum of the given values.static <A> double[]
toPrimitiveDoubleArray(A array, NumberArrayAdapter<?,? super A> adapter)
Convert a numeric array-like to adouble[]
.static double[]
toPrimitiveDoubleArray(NumberVector obj)
Convert a number vector todouble[]
.static <A> float[]
toPrimitiveFloatArray(A array, NumberArrayAdapter<?,? super A> adapter)
Convert a numeric array-like to afloat[]
.static float[]
toPrimitiveFloatArray(NumberVector obj)
Convert a number vector tofloat[]
.static <A> int[]
toPrimitiveIntegerArray(A array, NumberArrayAdapter<?,? super A> adapter)
Convert a numeric array-like to aint[]
.static int[]
toPrimitiveIntegerArray(NumberVector obj)
Convert a number vector toint[]
.
-
-
-
Field Detail
-
FEATUREVECTORADAPTER
public static final FeatureVectorAdapter<?> FEATUREVECTORADAPTER
Static instance.
-
NUMBERVECTORADAPTER
public static final NumberVectorAdapter NUMBERVECTORADAPTER
Use a number vector in the array API.
-
DOUBLEARRAYADAPTER
public static final NumberArrayAdapter<java.lang.Double,double[]> DOUBLEARRAYADAPTER
Use a double array in the array API.
-
FLOATARRAYADAPTER
public static final NumberArrayAdapter<java.lang.Float,float[]> FLOATARRAYADAPTER
Use a float array in the array API.
-
-
Method Detail
-
featureVectorAdapter
public static <F> FeatureVectorAdapter<F> featureVectorAdapter(FeatureVector<F> prototype)
Get the static instance.- Parameters:
prototype
- Prototype value, for type inference- Returns:
- Instance
-
getIndexOfMaximum
public static <A> int getIndexOfMaximum(A array, NumberArrayAdapter<?,A> adapter) throws java.lang.IndexOutOfBoundsException
Returns the index of the maximum of the given values. If no value is bigger than the first, the index of the first entry is returned.- Type Parameters:
A
- array type- Parameters:
array
- Array to inspectadapter
- API adapter class- Returns:
- the index of the maximum in the given values
- Throws:
java.lang.IndexOutOfBoundsException
- if the length of the array is 0.
-
getIndexOfMaximum
public static int getIndexOfMaximum(double[] array) throws java.lang.IndexOutOfBoundsException
Returns the index of the maximum of the given values. If no value is bigger than the first, the index of the first entry is returned.- Parameters:
array
- Array to inspect- Returns:
- the index of the maximum in the given values
- Throws:
java.lang.IndexOutOfBoundsException
- if the length of the array is 0.
-
toPrimitiveDoubleArray
public static <A> double[] toPrimitiveDoubleArray(A array, NumberArrayAdapter<?,? super A> adapter)
Convert a numeric array-like to adouble[]
.- Parameters:
array
- Array-likeadapter
- Adapter- Returns:
- primitive double array
-
toPrimitiveDoubleArray
public static double[] toPrimitiveDoubleArray(NumberVector obj)
Convert a number vector todouble[]
.- Parameters:
obj
- Object to convert- Returns:
- primitive double array
-
toPrimitiveFloatArray
public static <A> float[] toPrimitiveFloatArray(A array, NumberArrayAdapter<?,? super A> adapter)
Convert a numeric array-like to afloat[]
.- Parameters:
array
- Array-likeadapter
- Adapter- Returns:
- primitive float array
-
toPrimitiveFloatArray
public static float[] toPrimitiveFloatArray(NumberVector obj)
Convert a number vector tofloat[]
.- Parameters:
obj
- Object to convert- Returns:
- primitive float array
-
toPrimitiveIntegerArray
public static <A> int[] toPrimitiveIntegerArray(A array, NumberArrayAdapter<?,? super A> adapter)
Convert a numeric array-like to aint[]
.- Parameters:
array
- Array-likeadapter
- Adapter- Returns:
- primitive double array
-
toPrimitiveIntegerArray
public static int[] toPrimitiveIntegerArray(NumberVector obj)
Convert a number vector toint[]
.- Parameters:
obj
- Object to convert- Returns:
- primitive double array
-
-