public class ZArrays
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static <T> java.util.Set<T> |
asSet(T[] array)
Converts the array into a set.
|
static <T> T[] |
filter(T[] array,
Predicate<T> predicate)
Creates a new array containing only the values matching the given
predicate.
|
static <T> T |
first(T[] array,
Predicate<T> predicate)
Returns the first value matching the given predicate, or null if none
could be found.
|
static <T> int |
indexOf(T[] array,
T value)
Find the first index of the given object in the array.
|
static <T> T |
last(T[] array,
Predicate<T> predicate)
Returns the last value matching the given predicate, or null if none
could be found.
|
static <T> int |
lastIndexOf(T[] array,
T value)
Find the last index of the given object in the array.
|
static <T,R> R[] |
map(java.lang.Class<R> component,
T[] array,
Function<T,R> function)
Creates a new array, converting each value of the original value using
the mapping function.
|
static double |
max(double[] array)
Determines the largest value in this array.
|
static float |
max(float[] array)
Determines the largest value in this array.
|
static int |
max(int[] array)
Determines the largest value in this array.
|
static long |
max(long[] array)
Determines the largest value in this array.
|
static <T> T |
max(T[] array,
java.util.Comparator<T> comparator)
Returns the largest element in this array, according to the given
comparator.
|
static <T> double |
maxDouble(T[] array,
ToDoubleFunction<T> function)
Returns the smallest value returned by the evaluation function, for any
of the elements in the given array.
|
static <T> T |
maxForDouble(T[] array,
ToDoubleFunction<T> function)
Returns the element for which the given function returns the largest
double value.
|
static <T> T |
maxForInt(T[] array,
ToIntFunction<T> function)
Returns the element for which the given function returns the largest
integer value.
|
static <T> T |
maxForLong(T[] array,
ToLongFunction<T> function)
Returns the element for which the given function returns the largest
long value.
|
static <T> int |
maxInt(T[] array,
ToIntFunction<T> function)
Returns the largest value returned by the evaluation function, for any
of the elements in the given array.
|
static <T> long |
maxLong(T[] array,
ToLongFunction<T> function)
Returns the largest value returned by the evaluation function, for any
of the elements in the given array.
|
static double |
min(double[] array)
Determines the smallest value in this array.
|
static float |
min(float[] array)
Determines the smallest value in this array.
|
static int |
min(int[] array)
Determines the smallest value in this array.
|
static long |
min(long[] array)
Determines the smallest value in this array.
|
static <T> T |
min(T[] array,
java.util.Comparator<T> comparator)
Returns the smallest element in this array, according to the given
comparator.
|
static <T> double |
minDouble(T[] array,
ToDoubleFunction<T> function)
Returns the smallest value returned by the evaluation function, for any
of the elements in the given array.
|
static <T> T |
minForDouble(T[] array,
ToDoubleFunction<T> function)
Returns the element for which the given function returns the smallest
double value.
|
static <T> T |
minForInt(T[] array,
ToIntFunction<T> function)
Returns the element for which the given function returns the smallest
integer value.
|
static <T> T |
minForLong(T[] array,
ToLongFunction<T> function)
Returns the element for which the given function returns the smallest
long value.
|
static <T> int |
minInt(T[] array,
ToIntFunction<T> function)
Returns the smallest value returned by the evaluation function, for any
of the elements in the given array.
|
static <T> long |
minLong(T[] array,
ToLongFunction<T> function)
Returns the smallest value returned by the evaluation function, for any
of the elements in the given array.
|
static double |
sum(double[] array)
Calculates the sum of all elements in this array
|
static float |
sum(float[] array)
Calculates the sum of all elements in this array
|
static int |
sum(int[] array)
Calculates the sum of all elements in this array.
|
static <T> double |
sumForDouble(T[] array,
ToDoubleFunction<T> function)
Calculates the sum of a function over the given array.
|
static <T> int |
sumForInt(T[] array,
ToIntFunction<T> function)
Calculates the sum of a function over the given array.
|
public static <T> int indexOf(T[] array,
T value)
T - object typearray - haystackvalue - needlepublic static <T> int lastIndexOf(T[] array,
T value)
T - object typearray - haystackvalue - needlepublic static int sum(int[] array)
array - array to sumpublic static float sum(float[] array)
array - array to sumpublic static double sum(double[] array)
array - array to sumpublic static <T> int sumForInt(T[] array,
ToIntFunction<T> function)
T - object typearray - arrayfunction - calculation functionpublic static <T> double sumForDouble(T[] array,
ToDoubleFunction<T> function)
T - object typearray - arrayfunction - calculation functionpublic static <T> java.util.Set<T> asSet(T[] array)
T - object typearray - array to be convertedpublic static <T,R> R[] map(java.lang.Class<R> component,
T[] array,
Function<T,R> function)
T - original component typeR - resulting component typecomponent - component classarray - original arrayfunction - mapping functionpublic static <T> T[] filter(T[] array,
Predicate<T> predicate)
T - component typearray - original arraypredicate - predicatepublic static <T> T first(T[] array,
Predicate<T> predicate)
T - component typearray - array to look inpredicate - predicatepublic static <T> T last(T[] array,
Predicate<T> predicate)
T - component typearray - array to look inpredicate - predicatepublic static int min(int[] array)
array - array to readpublic static long min(long[] array)
array - array to readpublic static float min(float[] array)
array - array to readpublic static double min(double[] array)
array - array to readpublic static <T> T min(T[] array,
java.util.Comparator<T> comparator)
T - component typearray - array to evaluatecomparator - comparatorpublic static <T> T minForInt(T[] array,
ToIntFunction<T> function)
T - component typearray - array to evaluatefunction - evaluation functionpublic static <T> T minForLong(T[] array,
ToLongFunction<T> function)
T - component typearray - array to evaluatefunction - evaluation functionpublic static <T> T minForDouble(T[] array,
ToDoubleFunction<T> function)
T - component typearray - array to evaluatefunction - evaluation functionpublic static <T> int minInt(T[] array,
ToIntFunction<T> function)
T - component typearray - array to evaluatefunction - evaluation functionpublic static <T> long minLong(T[] array,
ToLongFunction<T> function)
T - component typearray - array to evaluatefunction - evaluation functionpublic static <T> double minDouble(T[] array,
ToDoubleFunction<T> function)
T - component typearray - array to evaluatefunction - evaluation functionpublic static int max(int[] array)
array - array to readpublic static long max(long[] array)
array - array to readpublic static float max(float[] array)
array - array to readpublic static double max(double[] array)
array - array to readpublic static <T> T max(T[] array,
java.util.Comparator<T> comparator)
T - component typearray - array to evaluatecomparator - comparatorpublic static <T> T maxForInt(T[] array,
ToIntFunction<T> function)
T - component typearray - array to evaluatefunction - evaluation functionpublic static <T> T maxForLong(T[] array,
ToLongFunction<T> function)
T - component typearray - array to evaluatefunction - evaluation functionpublic static <T> T maxForDouble(T[] array,
ToDoubleFunction<T> function)
T - component typearray - array to evaluatefunction - evaluation functionpublic static <T> int maxInt(T[] array,
ToIntFunction<T> function)
T - component typearray - array to evaluatefunction - evaluation functionpublic static <T> long maxLong(T[] array,
ToLongFunction<T> function)
T - component typearray - array to evaluatefunction - evaluation functionpublic static <T> double maxDouble(T[] array,
ToDoubleFunction<T> function)
T - component typearray - array to evaluatefunction - evaluation function