Class ArrayUtils


  • public class ArrayUtils
    extends Object
    General methods for arrays
    Author:
    gman6028, markr
    • Constructor Summary

      Constructors 
      Constructor Description
      ArrayUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addTo​(double[] destination, double[] addToDestination)
      Add the values of a second array element-wise to the first array
      static void addTo​(double[] destination, double[] addToDestination, int numberOfElements)
      Add the values of a second array element-wise to the first array
      static Object[] addtoStart​(Object elementToPrepend, Object[] theArray)
      add an element to the start of the passed in array.
      static double dotProduct​(double[] d1, double[] d2, int numberOfElements)
      Return the dot product of two arrays The dot product is found by multiplying the elements of each array at each position together and then taking the sum of the multiplied values e.g.
      static double getMaximum​(double[] array)
      find the maximum of an array of doubles
      static void loopAll​(double[][] array, BiConsumer<Integer,​Integer> consumer)
      Loop over array entries and apply consumer
      static void loopAll​(double[] array, Consumer<Integer> consumer)
      Loop over array entries and apply consumer
      static <T> void loopAll​(T[] array, Consumer<T> consumer)
      Loop over array entries and apply consumer
    • Constructor Detail

      • ArrayUtils

        public ArrayUtils()
    • Method Detail

      • addTo

        public static void addTo​(double[] destination,
                                 double[] addToDestination,
                                 int numberOfElements)
        Add the values of a second array element-wise to the first array
        Parameters:
        destination - the array to be updated
        addToDestination - array of values to be added to destination array
        numberOfElements - number of elements in array to be updated
      • addTo

        public static void addTo​(double[] destination,
                                 double[] addToDestination)
        Add the values of a second array element-wise to the first array
        Parameters:
        destination - the array to be updated
        addToDestination - array of values to be added to destination array
      • dotProduct

        public static double dotProduct​(double[] d1,
                                        double[] d2,
                                        int numberOfElements)
        Return the dot product of two arrays The dot product is found by multiplying the elements of each array at each position together and then taking the sum of the multiplied values e.g. a[1]*b[1]+ a[2]*b[2] + a[3]*b[3] etc
        Parameters:
        d1 - first array in the dot product
        d2 - second array in the dot product
        numberOfElements - number of elements in each array
        Returns:
        the value of the dot product
      • addtoStart

        public static Object[] addtoStart​(Object elementToPrepend,
                                          Object[] theArray)
        add an element to the start of the passed in array. Note that this involves a copy of the original array
        Parameters:
        elementToPrepend - the element to add to start
        theArray - the array to prepend
        Returns:
        the new array
      • getMaximum

        public static double getMaximum​(double[] array)
        find the maximum of an array of doubles
        Parameters:
        array - to check
        Returns:
        maximum value
      • loopAll

        public static void loopAll​(double[][] array,
                                   BiConsumer<Integer,​Integer> consumer)
        Loop over array entries and apply consumer
        Parameters:
        array - to apply consumer to
        consumer - to apply
      • loopAll

        public static void loopAll​(double[] array,
                                   Consumer<Integer> consumer)
        Loop over array entries and apply consumer
        Parameters:
        array - to apply consumer to
        consumer - to apply
      • loopAll

        public static <T> void loopAll​(T[] array,
                                       Consumer<T> consumer)
        Loop over array entries and apply consumer
        Type Parameters:
        T - type of array contents
        Parameters:
        array - to apply consumer to
        consumer - to apply