Class 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 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.
    • Constructor Detail

      • ArrayLikeUtil

        private ArrayLikeUtil()
        Fake constructor. Do not instantiate!
    • 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 inspect
        adapter - 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 a double[].
        Parameters:
        array - Array-like
        adapter - Adapter
        Returns:
        primitive double array
      • toPrimitiveDoubleArray

        public static double[] toPrimitiveDoubleArray​(NumberVector obj)
        Convert a number vector to double[].
        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 a float[].
        Parameters:
        array - Array-like
        adapter - Adapter
        Returns:
        primitive float array
      • toPrimitiveFloatArray

        public static float[] toPrimitiveFloatArray​(NumberVector obj)
        Convert a number vector to float[].
        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 a int[].
        Parameters:
        array - Array-like
        adapter - Adapter
        Returns:
        primitive double array
      • toPrimitiveIntegerArray

        public static int[] toPrimitiveIntegerArray​(NumberVector obj)
        Convert a number vector to int[].
        Parameters:
        obj - Object to convert
        Returns:
        primitive double array