public class ArrayUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static <T> java.util.Set<T> |
asImmutableSet(T[] a)
Return an immutable Set containing the same elements as the specified
array.
|
static java.util.List<java.lang.Integer> |
asList(int[] array)
needed because Arrays.asList() won't to autoboxing,
so if you give it a primitive array you get a
singleton list back with just that array as an element.
|
static double[] |
asPrimitiveDoubleArray(java.util.Collection<java.lang.Double> d) |
static int[] |
asPrimitiveIntArray(java.util.Collection<java.lang.Integer> d) |
static <T> java.util.Set<T> |
asSet(T[] a)
Return a Set containing the same elements as the specified array.
|
static <T extends java.lang.Comparable<T>> |
compareArrays(T[] first,
T[] second)
Provides a consistent ordering over arrays.
|
static int |
compareBooleanArrays(boolean[] a1,
boolean[] a2) |
static <T> T[] |
concatenate(T[] first,
T[] second)
Concatenates two arrays and returns the result
|
static <T> boolean |
contains(T[] a,
T o)
Returns true iff object o equals (not ==) some element of array a.
|
static double[] |
copy(double[] d) |
static double[][] |
copy(double[][] d) |
static double[][][] |
copy(double[][][] d) |
static float[] |
copy(float[] d) |
static float[][] |
copy(float[][] d) |
static float[][][] |
copy(float[][][] d) |
static int[] |
copy(int[] i) |
static int[][] |
copy(int[][] i) |
static long[] |
copy(long[] arr) |
static short[] |
copy(short[] arr) |
static int[] |
deltaDecode(byte[] deltaEncoded) |
static int[] |
deltaDecode(byte[] deltaEncoded,
int startIndex,
int endIndex) |
static java.util.List<java.lang.Integer> |
deltaDecodeList(byte[] deltaEncoded) |
static java.util.List<java.lang.Integer> |
deltaDecodeList(byte[] deltaEncoded,
int startIndex,
int endIndex) |
static byte[] |
deltaEncode(int[] orig) |
static java.util.List<java.lang.Byte> |
deltaEncodeList(int[] orig) |
static boolean |
equalContents(int[][] xs,
int[][] ys)
Tests two int[][] arrays for having equal contents.
|
static boolean |
equalContents(int[] xs,
int[] ys)
tests two int[] arrays for having equal contents
|
static boolean |
equals(boolean[][] xs,
boolean[][] ys)
Tests two boolean[][] arrays for having equal contents.
|
static boolean |
equals(double[][] xs,
double[][] ys)
Tests two double[][] arrays for having equal contents.
|
static void |
fill(boolean[][][][] d,
boolean val) |
static void |
fill(boolean[][][] d,
boolean val) |
static void |
fill(boolean[][] d,
boolean val) |
static void |
fill(double[][][][] d,
double val) |
static void |
fill(double[][][] d,
double val) |
static void |
fill(double[][] d,
double val) |
static <T> T[] |
filter(T[] original,
java.util.function.Predicate<? super T> filter)
Returns an array with only the elements accepted by
filter
Implementation notes: creates two arrays, calls filter
once for each element, does not alter original |
static double[] |
flatten(double[][] array) |
static int[] |
gapDecode(byte[] gapEncoded) |
static int[] |
gapDecode(byte[] gapEncoded,
int startIndex,
int endIndex) |
static java.util.List<java.lang.Integer> |
gapDecodeList(byte[] gapEncoded) |
static java.util.List<java.lang.Integer> |
gapDecodeList(byte[] gapEncoded,
int startIndex,
int endIndex) |
static byte[] |
gapEncode(int[] orig) |
static java.util.List<java.lang.Byte> |
gapEncodeList(int[] orig) |
static java.util.List<java.lang.Integer> |
getSubListIndex(java.lang.Object[] tofind,
java.lang.Object[] tokens) |
static java.util.List<java.lang.Integer> |
getSubListIndex(java.lang.Object[] tofind,
java.lang.Object[] tokens,
java.util.function.Predicate<Pair> matchingFunction)
If tofind is a part of tokens, it finds the ****starting index***** of tofind in tokens
If tofind is not a sub-array of tokens, then it returns null
note that tokens sublist should have the exact elements and order as in tofind
|
static <T> int |
indexOf(T[] array,
T object)
Returns the index of the first occurrence of the specified element in this array,
or -1 if this array does not contain the element.
|
static <T> int |
indexOf(T[] array,
T object,
int startIndex)
Returns the index of the first occurrence of the specified element in this array starting at the specified index,
or -1 if this array does not contain the element.
|
static double[] |
normalize(double[] ar)
Returns a new array which has the numbers in the input array
L1-normalized.
|
static double[] |
removeAt(double[] array,
int index)
Removes the element at the specified index from the array, and returns
a new array containing the remaining elements.
|
static java.lang.Object[] |
removeAt(java.lang.Object[] array,
int index)
Removes the element at the specified index from the array, and returns
a new array containing the remaining elements.
|
static java.lang.Object[] |
subArray(java.lang.Object[] arr,
int startindexInclusive,
int endindexExclusive) |
static double[][] |
to2D(double[] array,
int dim1Size) |
static double[][] |
to2D(double[] array,
int dim1Size,
int dim2Size) |
static double[] |
toDouble(float[] a)
Casts to a double array
|
static double[] |
toDouble(int[] array)
Casts to a double array.
|
static double[] |
toDoubleArray(java.lang.String[] in) |
static char[] |
toPrimitive(java.lang.Character[] in) |
static char[] |
toPrimitive(java.lang.Character[] in,
char valueForNull) |
static double[] |
toPrimitive(java.lang.Double[] in) |
static double[] |
toPrimitive(java.lang.Double[] in,
double valueForNull) |
static int[] |
toPrimitive(java.lang.Integer[] in) |
static int[] |
toPrimitive(java.lang.Integer[] in,
int valueForNull) |
static long[] |
toPrimitive(java.lang.Long[] in) |
static long[] |
toPrimitive(java.lang.Long[] in,
long valueForNull) |
static short[] |
toPrimitive(java.lang.Short[] in) |
static short[] |
toPrimitive(java.lang.Short[] in,
short valueForNull) |
static java.lang.String |
toString(boolean[][] b) |
static java.lang.String |
toString(double[][] b) |
static java.lang.String |
toString(double[] doubles,
java.lang.String glue) |
static java.lang.String |
toString(int[][] a) |
public static byte[] gapEncode(int[] orig)
public static java.util.List<java.lang.Byte> gapEncodeList(int[] orig)
public static int[] gapDecode(byte[] gapEncoded)
public static int[] gapDecode(byte[] gapEncoded, int startIndex, int endIndex)
public static java.util.List<java.lang.Integer> gapDecodeList(byte[] gapEncoded)
public static java.util.List<java.lang.Integer> gapDecodeList(byte[] gapEncoded, int startIndex, int endIndex)
public static byte[] deltaEncode(int[] orig)
public static java.util.List<java.lang.Byte> deltaEncodeList(int[] orig)
public static int[] deltaDecode(byte[] deltaEncoded)
public static int[] deltaDecode(byte[] deltaEncoded, int startIndex, int endIndex)
public static java.util.List<java.lang.Integer> deltaDecodeList(byte[] deltaEncoded)
public static java.util.List<java.lang.Integer> deltaDecodeList(byte[] deltaEncoded, int startIndex, int endIndex)
public static double[] flatten(double[][] array)
public static double[][] to2D(double[] array, int dim1Size)
public static double[][] to2D(double[] array, int dim1Size, int dim2Size)
public static double[] removeAt(double[] array, int index)
public static java.lang.Object[] removeAt(java.lang.Object[] array, int index)
public static java.lang.String toString(int[][] a)
public static boolean equalContents(int[][] xs, int[][] ys)
equalContents(xs[i],ys[i])
is truepublic static boolean equals(double[][] xs, double[][] ys)
equals(xs[i],ys[i])
is truepublic static boolean equalContents(int[] xs, int[] ys)
xs[i]==ys[i]
public static boolean equals(boolean[][] xs, boolean[][] ys)
Arrays.equals(xs[i],ys[i])
is truepublic static <T> boolean contains(T[] a, T o)
public static <T> T[] concatenate(T[] first, T[] second)
public static <T> T[] filter(T[] original, java.util.function.Predicate<? super T> filter)
filter
filter
once for each element, does not alter original
public static <T> java.util.Set<T> asSet(T[] a)
public static <T> java.util.Set<T> asImmutableSet(T[] a)
public static void fill(double[][] d, double val)
public static void fill(double[][][] d, double val)
public static void fill(double[][][][] d, double val)
public static void fill(boolean[][] d, boolean val)
public static void fill(boolean[][][] d, boolean val)
public static void fill(boolean[][][][] d, boolean val)
public static double[] toDouble(float[] a)
public static double[] toDouble(int[] array)
public static java.util.List<java.lang.Integer> asList(int[] array)
public static double[] asPrimitiveDoubleArray(java.util.Collection<java.lang.Double> d)
public static int[] asPrimitiveIntArray(java.util.Collection<java.lang.Integer> d)
public static long[] copy(long[] arr)
public static int[] copy(int[] i)
public static int[][] copy(int[][] i)
public static short[] copy(short[] arr)
public static double[] copy(double[] d)
public static double[][] copy(double[][] d)
public static double[][][] copy(double[][][] d)
public static float[] copy(float[] d)
public static float[][] copy(float[][] d)
public static float[][][] copy(float[][][] d)
public static java.lang.String toString(double[][] b)
public static java.lang.String toString(boolean[][] b)
public static long[] toPrimitive(java.lang.Long[] in)
public static int[] toPrimitive(java.lang.Integer[] in)
public static short[] toPrimitive(java.lang.Short[] in)
public static char[] toPrimitive(java.lang.Character[] in)
public static double[] toPrimitive(java.lang.Double[] in)
public static long[] toPrimitive(java.lang.Long[] in, long valueForNull)
public static int[] toPrimitive(java.lang.Integer[] in, int valueForNull)
public static short[] toPrimitive(java.lang.Short[] in, short valueForNull)
public static char[] toPrimitive(java.lang.Character[] in, char valueForNull)
public static double[] toDoubleArray(java.lang.String[] in)
public static double[] toPrimitive(java.lang.Double[] in, double valueForNull)
public static <T extends java.lang.Comparable<T>> int compareArrays(T[] first, T[] second)
CollectionUtils.compareLists(java.util.List<T>, java.util.List<T>)
and uses the same logic when the arrays are of different lengths.public static <T> int indexOf(T[] array, T object, int startIndex)
array
- Array to searchobject
- Object to look forstartIndex
- Start indexpublic static <T> int indexOf(T[] array, T object)
array
- Array to searchobject
- Object to look forpublic static java.util.List<java.lang.Integer> getSubListIndex(java.lang.Object[] tofind, java.lang.Object[] tokens)
public static java.util.List<java.lang.Integer> getSubListIndex(java.lang.Object[] tofind, java.lang.Object[] tokens, java.util.function.Predicate<Pair> matchingFunction)
tofind
- array you want to find in tokenstokens
- matchingFunction
- function that takes (tofindtoken, token) pair and returns whether they matchpublic static double[] normalize(double[] ar)
ar
- Input arraypublic static java.lang.Object[] subArray(java.lang.Object[] arr, int startindexInclusive, int endindexExclusive)
public static int compareBooleanArrays(boolean[] a1, boolean[] a2)
public static java.lang.String toString(double[] doubles, java.lang.String glue)