Class ArrayCopyUtilities


  • public abstract class ArrayCopyUtilities
    extends java.lang.Object

    A class of static methods for copying data between arrays of different types, expanding arrays, and comparing them, and removing padding from strings.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean arraysAreEqual​(double[] a1, double[] a2)
      Compare two double arrays and return true if both not null, and are of equal length and contain equal values.
      static double[] copyFloatToDoubleArray​(float[] src)
      Copy an array of float values into an array of double.
      static double[] copySignedIntToDoubleArray​(int[] src)
      Copy an array of signed values in int, into an array of double.
      static float[] copySignedIntToFloatArray​(int[] src)
      Copy an array of signed values in int, into an array of float.
      static long[] copySignedIntToLongArray​(int[] src)
      Copy an array of signed values in int, into an array of long.
      static short[] copySignedIntToShortArray​(int[] src)
      Copy an array of signed values in int, into an array of short.
      static double[] copySignedLongToDoubleArray​(long[] src)
      Copy an array of signed values in long, into an array of double.
      static float[] copySignedLongToFloatArray​(long[] src)
      Copy an array of signed values in long, into an array of float.
      static int[] copySignedLongToIntArray​(long[] src)
      Copy an array of signed values in long, into an array of int.
      static short[] copySignedLongToShortArray​(long[] src)
      Copy an array of signed values in long, into an array of short.
      static double[] copySignedShortToDoubleArray​(short[] src)
      Copy an array of signed values in short, into an array of double.
      static float[] copySignedShortToFloatArray​(short[] src)
      Copy an array of signed values in short, into an array of float.
      static int[] copySignedShortToIntArray​(short[] src)
      Copy an array of signed values in short, into an array of int.
      static long[] copySignedShortToLongArray​(short[] src)
      Copy an array of signed values in short, into an array of long.
      static java.lang.String[] copyStringArrayRemovingLeadingAndTrailingPadding​(java.lang.String[] src)
      Copy a string removing leading and trailing padding.
      static double[] copyStringToDoubleArray​(java.lang.String[] src)
      Extract decimal values from an array of strings into an array of double.
      static float[] copyStringToFloatArray​(java.lang.String[] src)
      Extract decimal values from an array of strings into an array of float.
      static int[] copyStringToIntArray​(java.lang.String[] src)
      Extract integer values from an array of strings into an array of int.
      static long[] copyStringToLongArray​(java.lang.String[] src)
      Extract long values from an array of strings into an array of int.
      static short[] copyStringToShortArray​(java.lang.String[] src)
      Extract short values from an array of strings into an array of short.
      static double[] copyUnsignedIntToDoubleArray​(int[] src)
      Copy an array of unsigned values in int, into an array of double.
      static float[] copyUnsignedIntToFloatArray​(int[] src)
      Copy an array of unsigned values in int, into an array of float.
      static long[] copyUnsignedIntToLongArray​(int[] src)
      Copy an array of unsigned values in int, into an array of long.
      static short[] copyUnsignedIntToShortArray​(int[] src)
      Copy an array of unsigned values in int, into an array of short.
      static double[] copyUnsignedLongToDoubleArray​(long[] src)
      Copy an array of unsigned values in long, into an array of double.
      static float[] copyUnsignedLongToFloatArray​(long[] src)
      Copy an array of unsigned values in long, into an array of float.
      static int[] copyUnsignedLongToIntArray​(long[] src)
      Copy an array of unsigned values in long, into an array of int.
      static short[] copyUnsignedLongToShortArray​(long[] src)
      Copy an array of unsigned values in long, into an array of short.
      static double[] copyUnsignedShortToDoubleArray​(short[] src)
      Copy an array of unsigned values in short, into an array of double.
      static float[] copyUnsignedShortToFloatArray​(short[] src)
      Copy an array of unsigned values in short, into an array of float.
      static int[] copyUnsignedShortToIntArray​(short[] src)
      Copy an array of unsigned values in short, into an array of int.
      static long[] copyUnsignedShortToLongArray​(short[] src)
      Copy an array of unsigned values in short, into an array of long.
      static double[] expandArray​(double[] src)
      Expand an array by adding one element to the end.
      static double[] expandArray​(double[] src, int expandBy)
      Expand an array by adding elements to the end.
      static float[] expandArray​(float[] src)
      Expand an array by adding one element to the end.
      static float[] expandArray​(float[] src, int expandBy)
      Expand an array by adding elements to the end.
      static int[] expandArray​(int[] src)
      Expand an array by adding one element to the end.
      static int[] expandArray​(int[] src, int expandBy)
      Expand an array by adding elements to the end.
      static long[] expandArray​(long[] src)
      Expand an array by adding one element to the end.
      static long[] expandArray​(long[] src, int expandBy)
      Expand an array by adding elements to the end.
      static short[] expandArray​(short[] src)
      Expand an array by adding one element to the end.
      static short[][] expandArray​(short[][] src)
      Expand an array by adding one element to the end.
      static short[][] expandArray​(short[][] src, int expandBy)
      Expand an array by adding elements to the end.
      static short[] expandArray​(short[] src, int expandBy)
      Expand an array by adding elements to the end.
      static java.lang.String[] expandArray​(java.lang.String[] src)
      Expand an array by adding one element to the end.
      static java.lang.String[] expandArray​(java.lang.String[] src, int expandBy)
      Expand an array by adding elements to the end.
      static double[] minMax​(double[] array)
      Find the minimum and maximum values in an array.
      static float[] minMax​(float[] array)
      Find the minimum and maximum values in an array.
      static short[] packByteArrayIntoShortArrayLittleEndian​(byte[] src)
      Pack an array of byte values into an array of short.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ArrayCopyUtilities

        public ArrayCopyUtilities()
    • Method Detail

      • packByteArrayIntoShortArrayLittleEndian

        public static short[] packByteArrayIntoShortArrayLittleEndian​(byte[] src)

        Pack an array of byte values into an array of short.

        Order is little endian (first byte into low order byte of short.

        Parameters:
        src - an array of byte
        Returns:
        an array of short, half the length of the src
      • copyUnsignedShortToIntArray

        public static int[] copyUnsignedShortToIntArray​(short[] src)

        Copy an array of unsigned values in short, into an array of int.

        Sign extension is prevented.

        Parameters:
        src - an array of short, whose values are interpreted as unsigned
        Returns:
        an array of int
      • copySignedShortToIntArray

        public static int[] copySignedShortToIntArray​(short[] src)

        Copy an array of signed values in short, into an array of int.

        Sign extension is performed.

        Parameters:
        src - an array of short, whose values are interpreted as signed
        Returns:
        an array of int
      • copyUnsignedShortToLongArray

        public static long[] copyUnsignedShortToLongArray​(short[] src)

        Copy an array of unsigned values in short, into an array of long.

        Sign extension is prevented.

        Parameters:
        src - an array of short, whose values are interpreted as unsigned
        Returns:
        an array of long
      • copySignedShortToLongArray

        public static long[] copySignedShortToLongArray​(short[] src)

        Copy an array of signed values in short, into an array of long.

        Sign extension is performed.

        Parameters:
        src - an array of short, whose values are interpreted as signed
        Returns:
        an array of long
      • copyUnsignedShortToFloatArray

        public static float[] copyUnsignedShortToFloatArray​(short[] src)

        Copy an array of unsigned values in short, into an array of float.

        Sign extension is prevented.

        Parameters:
        src - an array of short, whose values are interpreted as unsigned
        Returns:
        an array of float
      • copySignedShortToFloatArray

        public static float[] copySignedShortToFloatArray​(short[] src)

        Copy an array of signed values in short, into an array of float.

        Sign extension is performed.

        Parameters:
        src - an array of short, whose values are interpreted as signed
        Returns:
        an array of float
      • copyUnsignedShortToDoubleArray

        public static double[] copyUnsignedShortToDoubleArray​(short[] src)

        Copy an array of unsigned values in short, into an array of double.

        Sign extension is prevented.

        Parameters:
        src - an array of short, whose values are interpreted as unsigned
        Returns:
        an array of double
      • copySignedShortToDoubleArray

        public static double[] copySignedShortToDoubleArray​(short[] src)

        Copy an array of signed values in short, into an array of double.

        Sign extension is performed.

        Parameters:
        src - an array of short, whose values are interpreted as signed
        Returns:
        an array of double
      • copyUnsignedIntToLongArray

        public static long[] copyUnsignedIntToLongArray​(int[] src)

        Copy an array of unsigned values in int, into an array of long.

        Sign extension is prevented.

        Parameters:
        src - an array of int, whose values are interpreted as unsigned
        Returns:
        an array of long
      • copySignedIntToDoubleArray

        public static double[] copySignedIntToDoubleArray​(int[] src)

        Copy an array of signed values in int, into an array of double.

        Sign extension is performed.

        Parameters:
        src - an array of int, whose values are interpreted as signed
        Returns:
        an array of double
      • copyUnsignedIntToDoubleArray

        public static double[] copyUnsignedIntToDoubleArray​(int[] src)

        Copy an array of unsigned values in int, into an array of double.

        Sign extension is prevented.

        Parameters:
        src - an array of int, whose values are interpreted as unsigned
        Returns:
        an array of double
      • copyFloatToDoubleArray

        public static double[] copyFloatToDoubleArray​(float[] src)

        Copy an array of float values into an array of double.

        Parameters:
        src - an array of float
        Returns:
        an array of double
      • copySignedIntToFloatArray

        public static float[] copySignedIntToFloatArray​(int[] src)

        Copy an array of signed values in int, into an array of float.

        Sign extension is performed.

        Parameters:
        src - an array of int, whose values are interpreted as signed
        Returns:
        an array of float
      • copyUnsignedIntToFloatArray

        public static float[] copyUnsignedIntToFloatArray​(int[] src)

        Copy an array of unsigned values in int, into an array of float.

        Sign extension is prevented.

        Parameters:
        src - an array of int, whose values are interpreted as unsigned
        Returns:
        an array of float
      • copySignedIntToLongArray

        public static long[] copySignedIntToLongArray​(int[] src)

        Copy an array of signed values in int, into an array of long.

        Sign extension is performed.

        Parameters:
        src - an array of int, whose values are interpreted as signed
        Returns:
        an array of long
      • copyUnsignedIntToShortArray

        public static short[] copyUnsignedIntToShortArray​(int[] src)

        Copy an array of unsigned values in int, into an array of short.

        The value is truncated as necessary.

        Parameters:
        src - an array of int
        Returns:
        an array of short
      • copySignedIntToShortArray

        public static short[] copySignedIntToShortArray​(int[] src)

        Copy an array of signed values in int, into an array of short.

        The value is truncated as necessary.

        Parameters:
        src - an array of int
        Returns:
        an array of short
      • copySignedLongToDoubleArray

        public static double[] copySignedLongToDoubleArray​(long[] src)

        Copy an array of signed values in long, into an array of double.

        Sign extension is performed.

        Parameters:
        src - an array of long, whose values are interpreted as signed
        Returns:
        an array of double
      • copyUnsignedLongToDoubleArray

        public static double[] copyUnsignedLongToDoubleArray​(long[] src)

        Copy an array of unsigned values in long, into an array of double.

        Sign extension cannot be prevented since Java has no unsigned long type.

        Parameters:
        src - an array of int, whose values are interpreted as unsigned
        Returns:
        an array of double
      • copySignedLongToFloatArray

        public static float[] copySignedLongToFloatArray​(long[] src)

        Copy an array of signed values in long, into an array of float.

        Sign extension is performed.

        Parameters:
        src - an array of long, whose values are interpreted as signed
        Returns:
        an array of float
      • copyUnsignedLongToFloatArray

        public static float[] copyUnsignedLongToFloatArray​(long[] src)

        Copy an array of unsigned values in long, into an array of float.

        Sign extension cannot be prevented since Java has no unsigned long type.

        Parameters:
        src - an array of long, whose values are interpreted as unsigned
        Returns:
        an array of float
      • copySignedLongToIntArray

        public static int[] copySignedLongToIntArray​(long[] src)

        Copy an array of signed values in long, into an array of int.

        The values are truncated as necessary.

        Parameters:
        src - an array of long, whose values are interpreted as signed
        Returns:
        an array of int
      • copyUnsignedLongToIntArray

        public static int[] copyUnsignedLongToIntArray​(long[] src)

        Copy an array of unsigned values in long, into an array of int.

        The values are truncated as necessary.

        Parameters:
        src - an array of long, whose values are interpreted as unsigned
        Returns:
        an array of int
      • copyUnsignedLongToShortArray

        public static short[] copyUnsignedLongToShortArray​(long[] src)

        Copy an array of unsigned values in long, into an array of short.

        The values are truncated as necessary.

        Parameters:
        src - an array of long
        Returns:
        an array of short
      • copySignedLongToShortArray

        public static short[] copySignedLongToShortArray​(long[] src)

        Copy an array of signed values in long, into an array of short.

        The values are truncated as necessary.

        Parameters:
        src - an array of long
        Returns:
        an array of short
      • copyStringArrayRemovingLeadingAndTrailingPadding

        public static java.lang.String[] copyStringArrayRemovingLeadingAndTrailingPadding​(java.lang.String[] src)

        Copy a string removing leading and trailing padding.

        Parameters:
        src - the padded value
        Returns:
        the unpadded value
      • copyStringToShortArray

        public static short[] copyStringToShortArray​(java.lang.String[] src)

        Extract short values from an array of strings into an array of short.

        Exceptions in the format of the string are trapped and 0 value(s) returned.

        Parameters:
        src - an array of strings, each of which should be a short numeric value
        Returns:
        an array of short
      • copyStringToIntArray

        public static int[] copyStringToIntArray​(java.lang.String[] src)

        Extract integer values from an array of strings into an array of int.

        Exceptions in the format of the string are trapped and 0 value(s) returned.

        Parameters:
        src - an array of strings, each of which should be an integer numeric value
        Returns:
        an array of int
      • copyStringToLongArray

        public static long[] copyStringToLongArray​(java.lang.String[] src)

        Extract long values from an array of strings into an array of int.

        Exceptions in the format of the string are trapped and 0 value(s) returned.

        Parameters:
        src - an array of strings, each of which should be an long numeric value
        Returns:
        an array of long
      • copyStringToFloatArray

        public static float[] copyStringToFloatArray​(java.lang.String[] src)

        Extract decimal values from an array of strings into an array of float.

        Exceptions in the format of the string are trapped and 0 value(s) returned.

        Parameters:
        src - an array of strings, each of which should be a decimal numeric value
        Returns:
        an array of float
      • copyStringToDoubleArray

        public static double[] copyStringToDoubleArray​(java.lang.String[] src)

        Extract decimal values from an array of strings into an array of double.

        Exceptions in the format of the string are trapped and 0 value(s) returned.

        Parameters:
        src - an array of strings, each of which should be a decimal numeric value
        Returns:
        an array of double
      • expandArray

        public static short[] expandArray​(short[] src)

        Expand an array by adding one element to the end.

        Parameters:
        src - an array
        Returns:
        an array that is one element longer
      • expandArray

        public static short[] expandArray​(short[] src,
                                          int expandBy)

        Expand an array by adding elements to the end.

        Parameters:
        src - an array
        expandBy - the number of elements to add
        Returns:
        an array that is longer
      • expandArray

        public static short[][] expandArray​(short[][] src)

        Expand an array by adding one element to the end.

        Parameters:
        src - an array
        Returns:
        an array that is one element longer
      • expandArray

        public static short[][] expandArray​(short[][] src,
                                            int expandBy)

        Expand an array by adding elements to the end.

        Parameters:
        src - an array
        expandBy - the number of elements to add
        Returns:
        an array that is longer
      • expandArray

        public static int[] expandArray​(int[] src)

        Expand an array by adding one element to the end.

        Parameters:
        src - an array
        Returns:
        an array that is one element longer
      • expandArray

        public static int[] expandArray​(int[] src,
                                        int expandBy)

        Expand an array by adding elements to the end.

        Parameters:
        src - an array
        expandBy - the number of elements to add
        Returns:
        an array that is longer
      • expandArray

        public static long[] expandArray​(long[] src)

        Expand an array by adding one element to the end.

        Parameters:
        src - an array
        Returns:
        an array that is one element longer
      • expandArray

        public static long[] expandArray​(long[] src,
                                         int expandBy)

        Expand an array by adding elements to the end.

        Parameters:
        src - an array
        expandBy - the number of elements to add
        Returns:
        an array that is longer
      • expandArray

        public static float[] expandArray​(float[] src)

        Expand an array by adding one element to the end.

        Parameters:
        src - an array
        Returns:
        an array that is one element longer
      • expandArray

        public static float[] expandArray​(float[] src,
                                          int expandBy)

        Expand an array by adding elements to the end.

        Parameters:
        src - an array
        expandBy - the number of elements to add
        Returns:
        an array that is longer
      • expandArray

        public static double[] expandArray​(double[] src)

        Expand an array by adding one element to the end.

        Parameters:
        src - an array
        Returns:
        an array that is one element longer
      • expandArray

        public static double[] expandArray​(double[] src,
                                           int expandBy)

        Expand an array by adding elements to the end.

        Parameters:
        src - an array
        expandBy - the number of elements to add
        Returns:
        an array that is longer
      • expandArray

        public static java.lang.String[] expandArray​(java.lang.String[] src)

        Expand an array by adding one element to the end.

        Parameters:
        src - an array
        Returns:
        an array that is one element longer
      • expandArray

        public static java.lang.String[] expandArray​(java.lang.String[] src,
                                                     int expandBy)

        Expand an array by adding elements to the end.

        Parameters:
        src - an array
        expandBy - the number of elements to add
        Returns:
        an array that is longer
      • arraysAreEqual

        public static boolean arraysAreEqual​(double[] a1,
                                             double[] a2)

        Compare two double arrays and return true if both not null, and are of equal length and contain equal values.

        Parameters:
        a1 - first array
        a2 - second array
        Returns:
        true if equal
      • minMax

        public static float[] minMax​(float[] array)

        Find the minimum and maximum values in an array.

        Parameters:
        array - the array
        Returns:
        an array of two values, the first being the minimum and the second the maximum values found
      • minMax

        public static double[] minMax​(double[] array)

        Find the minimum and maximum values in an array.

        Parameters:
        array - the array
        Returns:
        an array of two values, the first being the minimum and the second the maximum values found