Package snap.util
Class ArrayUtils
java.lang.Object
snap.util.ArrayUtils
A collection of array utility methods.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic double[]
add
(double[] anArray, double anObj) Returns new double array by adding given value to given array.static double[]
add
(double[] anArray, double anObj, int anIndex) Returns new double array by adding given value to given array at given index.static <T> T[]
add
(T[] anArray, T anObj) Adds a value to an array of objects.static <T> T[]
add
(T[] anArray, T anObj, int anIndex) Returns a new array by adding a value to an array of objects at the given index.static <T> T[]
addAll
(T[] anArray, T... theObjs) Returns an array by adding to the given array the given objects (array).static <T> T[]
addAllUnique
(T[] anArray, T... theObjects) Adds all object from second list to first list (creates first list if missing).static <T> T[]
addId
(T[] anArray, T anObj) Adds a value to an array of objects if list doesn't already contain it.static <T> T[]
addId
(T[] anArray, T anObj, int anIndex) Adds a value to an array of objects if list doesn't already contain it.static <T> T[]
addUnique
(T[] anArray, T anObj) Adds all object from second list to first list (creates first list if missing).static boolean
Returns whether the given array contains the given object.static <T> boolean
containsId
(T[] anArray, T aValue) Returns whether the given array contains the identical given object.static boolean
equals
(byte[] array1, byte[] array2) Returns whether two byte arrays are equal.static boolean
equals
(byte[] array1, byte[] array2, int length) Returns whether two byte arrays are equal to the given length.static boolean
equals
(double[] array1, double[] array2) Returns whether two double arrays are equal.static boolean
equals
(double[] array1, double[] array2, int length) Returns whether two float arrays are equal to the given length.static boolean
equals
(float[] array1, float[] array2) Returns whether two float arrays are equal.static boolean
equals
(float[] array1, float[] array2, int length) Returns whether two float arrays are equal to the given length.static boolean
Returns whether two arrays are equal using identity check (==).static <T> T[]
Returns a filtered array for given original and Predicate.static <T,
R> R[] filterByClass
(T[] anArray, Class<R> aClass) Returns a filtered array for given original and Predicate.static <T> T
Returns the first item in array that matches given predicate (or null).static <T> int
findMatchIndex
(T[] anArray, Predicate<? super T> aPred) Returns the index of first item in array that matches given predicate (or -1).static <T> T[]
Returns the individual object of a given class at given index (from all objects of given class).static <T> T
Returns the individual object of a given class at given index (from all objects of given class).static int
Returns the number of object in array of a given class.static <T> T
getMax
(T[] anArray, Comparator<T> aComparator) Returns the max value of a given array using given comparator function.static <T> T
getMin
(T[] anArray, Comparator<T> aComparator) Returns the min value of a given array using given comparator function.static <T> boolean
Returns whether given array has match for given predicate.static int
Returns the index of the given object in the given array.static <T> int
indexOfId
(T[] anArray, T aValue) Returns the index of the given object in the given array using "==" instead of equals.static int
Returns the length of a given object array (or zero, if null).static <T,
R> R[] Returns a mapped array for given original and Function.static <T,
R> R[] mapNonNull
(T[] anArray, Function<? super T, ? extends R> aFunction, Class<R> aClass) Returns a mapped array for given original and Function.static <T> String
mapToStringsAndJoin
(T[] anArray, Function<T, String> aFunc, String aDelim) Maps an array of items to strings using given function, then joins them by given delimiter.static int[]
remove
(int[] anArray, int anIndex) Returns a new array by removing a value from an array of objects at the given index.static <T> T[]
remove
(T[] anArray, int anIndex) Returns a new array by removing a value from an array of objects at the given index.static <T> T[]
remove
(T[] anArray, T anObj) Returns a new array by removing a value from an array of objects at the given index.static <T> T[]
removeId
(T[] anArray, T anObj) Removes a value from an array of objects if list doesn't already contain it.static <T> T[]
replace
(T[] anArray, int start, int end, T... swapInArray) Replaces a range of values in an array with values from another array.static void
Reverse and array.
-
Constructor Details
-
ArrayUtils
public ArrayUtils()
-
-
Method Details
-
length
Returns the length of a given object array (or zero, if null). -
add
public static <T> T[] add(T[] anArray, T anObj) Adds a value to an array of objects. -
add
public static <T> T[] add(T[] anArray, T anObj, int anIndex) Returns a new array by adding a value to an array of objects at the given index. -
addUnique
public static <T> T[] addUnique(T[] anArray, T anObj) Adds all object from second list to first list (creates first list if missing). -
addAll
public static <T> T[] addAll(T[] anArray, T... theObjs) Returns an array by adding to the given array the given objects (array). -
addAllUnique
public static <T> T[] addAllUnique(T[] anArray, T... theObjects) Adds all object from second list to first list (creates first list if missing). -
remove
public static <T> T[] remove(T[] anArray, int anIndex) Returns a new array by removing a value from an array of objects at the given index. -
remove
public static <T> T[] remove(T[] anArray, T anObj) Returns a new array by removing a value from an array of objects at the given index. -
remove
public static int[] remove(int[] anArray, int anIndex) Returns a new array by removing a value from an array of objects at the given index. -
replace
public static <T> T[] replace(T[] anArray, int start, int end, T... swapInArray) Replaces a range of values in an array with values from another array. -
addId
public static <T> T[] addId(T[] anArray, T anObj) Adds a value to an array of objects if list doesn't already contain it. -
addId
public static <T> T[] addId(T[] anArray, T anObj, int anIndex) Adds a value to an array of objects if list doesn't already contain it. -
removeId
public static <T> T[] removeId(T[] anArray, T anObj) Removes a value from an array of objects if list doesn't already contain it. -
add
public static double[] add(double[] anArray, double anObj) Returns new double array by adding given value to given array. -
add
public static double[] add(double[] anArray, double anObj, int anIndex) Returns new double array by adding given value to given array at given index. -
getCount
Returns the number of object in array of a given class. -
get
Returns the individual object of a given class at given index (from all objects of given class). -
get
Returns the individual object of a given class at given index (from all objects of given class). -
equals
public static boolean equals(byte[] array1, byte[] array2) Returns whether two byte arrays are equal. -
equals
public static boolean equals(byte[] array1, byte[] array2, int length) Returns whether two byte arrays are equal to the given length. -
equals
public static boolean equals(float[] array1, float[] array2) Returns whether two float arrays are equal. -
equals
public static boolean equals(float[] array1, float[] array2, int length) Returns whether two float arrays are equal to the given length. -
equals
public static boolean equals(double[] array1, double[] array2) Returns whether two double arrays are equal. -
equals
public static boolean equals(double[] array1, double[] array2, int length) Returns whether two float arrays are equal to the given length. -
equalsId
Returns whether two arrays are equal using identity check (==). -
indexOf
Returns the index of the given object in the given array. -
contains
Returns whether the given array contains the given object. -
indexOfId
public static <T> int indexOfId(T[] anArray, T aValue) Returns the index of the given object in the given array using "==" instead of equals. -
containsId
public static <T> boolean containsId(T[] anArray, T aValue) Returns whether the given array contains the identical given object. -
reverse
Reverse and array. -
filter
Returns a filtered array for given original and Predicate. -
filterByClass
Returns a filtered array for given original and Predicate. -
map
public static <T,R> R[] map(T[] anArray, Function<? super T, ? extends R> aFunction, Class<R> aClass) Returns a mapped array for given original and Function. -
mapNonNull
public static <T,R> R[] mapNonNull(T[] anArray, Function<? super T, ? extends R> aFunction, Class<R> aClass) Returns a mapped array for given original and Function. -
hasMatch
Returns whether given array has match for given predicate. -
findMatch
Returns the first item in array that matches given predicate (or null). -
findMatchIndex
Returns the index of first item in array that matches given predicate (or -1). -
mapToStringsAndJoin
Maps an array of items to strings using given function, then joins them by given delimiter. -
getMin
Returns the min value of a given array using given comparator function. -
getMax
Returns the max value of a given array using given comparator function.
-