Package org.planit.utils.arrays
Class ArrayUtils
- java.lang.Object
-
- org.planit.utils.arrays.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 arraystatic void
addTo(double[] destination, double[] addToDestination, int numberOfElements)
Add the values of a second array element-wise to the first arraystatic 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 doublesstatic void
loopAll(double[][] array, BiConsumer<Integer,Integer> consumer)
Loop over array entries and apply consumerstatic void
loopAll(double[] array, Consumer<Integer> consumer)
Loop over array entries and apply consumerstatic <T> void
loopAll(T[] array, Consumer<T> consumer)
Loop over array entries and apply consumer
-
-
-
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 updatedaddToDestination
- array of values to be added to destination arraynumberOfElements
- 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 updatedaddToDestination
- 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 productd2
- second array in the dot productnumberOfElements
- 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 starttheArray
- 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 toconsumer
- to apply
-
loopAll
public static void loopAll(double[] array, Consumer<Integer> consumer)
Loop over array entries and apply consumer- Parameters:
array
- to apply consumer toconsumer
- 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 toconsumer
- to apply
-
-