- Author:
- AO Industries, Inc.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanallEquals(byte[] b, int off, int len, byte value) Checks if all the values in the provided range are equal tovalue.static <E> Set<E> asUnmodifiableSet(E... array) Gets an unmodifiable set view with the contents of a backing array.static intcompare(byte[] ba1, byte[] ba2) Compares two byte[].static booleanequals(byte[] b1, byte[] b2, int off, int len) Deprecated, for removal: This API element is subject to removal in a future version.static booleanequals(byte[] b1, int off1, byte[] b2, int off2, int len) Deprecated, for removal: This API element is subject to removal in a future version.static inthashCode(byte[] a, int off, int len) Computes hashCode compatible with Arrays.hashCode, but only across the given subset of the array.static intindexOf(byte[] array, byte element) Finds the first index of an element or-1if not found.static intindexOf(byte[] array, byte element, int fromIndex) Finds the first index of an element or-1if not found.static intindexOf(char[] array, char element) Finds the first index of an element or-1if not found.static intindexOf(char[] array, char element, int fromIndex) Finds the first index of an element or-1if not found.static intindexOf(double[] array, double element) Finds the first index of an element or-1if not found.static intindexOf(double[] array, double element, int fromIndex) Finds the first index of an element or-1if not found.static intindexOf(float[] array, float element) Finds the first index of an element or-1if not found.static intindexOf(float[] array, float element, int fromIndex) Finds the first index of an element or-1if not found.static intindexOf(int[] array, int element) Finds the first index of an element or-1if not found.static intindexOf(int[] array, int element, int fromIndex) Finds the first index of an element or-1if not found.static intindexOf(long[] array, long element) Finds the first index of an element or-1if not found.static intindexOf(long[] array, long element, int fromIndex) Finds the first index of an element or-1if not found.static intindexOf(short[] array, short element) Finds the first index of an element or-1if not found.static intindexOf(short[] array, short element, int fromIndex) Finds the first index of an element or-1if not found.static <E> intindexOf(E[] array, E element) Finds the first index of an element or-1if not found.static <E> intindexOf(E[] array, E element, int fromIndex) Finds the first index of an element or-1if not found.static intlastIndexOf(byte[] array, byte element) Finds the last index of an element or-1if not found.static intlastIndexOf(byte[] array, byte element, int fromIndex) Finds the last index of an element or-1if not found.static intlastIndexOf(char[] array, char element) Finds the last index of an element or-1if not found.static intlastIndexOf(char[] array, char element, int fromIndex) Finds the last index of an element or-1if not found.static intlastIndexOf(double[] array, double element) Finds the last index of an element or-1if not found.static intlastIndexOf(double[] array, double element, int fromIndex) Finds the last index of an element or-1if not found.static intlastIndexOf(float[] array, float element) Finds the last index of an element or-1if not found.static intlastIndexOf(float[] array, float element, int fromIndex) Finds the last index of an element or-1if not found.static intlastIndexOf(int[] array, int element) Finds the last index of an element or-1if not found.static intlastIndexOf(int[] array, int element, int fromIndex) Finds the last index of an element or-1if not found.static intlastIndexOf(long[] array, long element) Finds the last index of an element or-1if not found.static intlastIndexOf(long[] array, long element, int fromIndex) Finds the last index of an element or-1if not found.static intlastIndexOf(short[] array, short element) Finds the last index of an element or-1if not found.static intlastIndexOf(short[] array, short element, int fromIndex) Finds the last index of an element or-1if not found.static <E> intlastIndexOf(E[] array, E element) Finds the last index of an element or-1if not found.static <E> intlastIndexOf(E[] array, E element, int fromIndex) Finds the last index of an element or-1if not found.static <T extends Comparable<? super T>>
TmaxNonNull(T... values) Gets the maximum non-null value, ornullif no non-null value.static <V> V[]merge(Class<V> clazz, Collection<? extends Collection<? extends V>> collections, Comparator<? super V> comparator) Merges multiple already-sorted collections into one big array.static <E extends Comparable<? super E>>
voidsortParallelArrays(E[] keys, Object[]... otherArrays) Sorts parallel arrays in-place.
-
Method Details
-
equals
Deprecated, for removal: This API element is subject to removal in a future version.Checks if the subrange of two byte arrays is equal. -
equals
@Deprecated(forRemoval=true) public static boolean equals(byte[] b1, int off1, byte[] b2, int off2, int len) Deprecated, for removal: This API element is subject to removal in a future version.Checks if the subrange of two byte arrays is equal. -
allEquals
public static boolean allEquals(byte[] b, int off, int len, byte value) Checks if all the values in the provided range are equal tovalue. -
compare
public static int compare(byte[] ba1, byte[] ba2) Compares two byte[]. Shorter byte[] are ordered before longer when the shorter is a prefix of the longer. The comparison considers each byte as a value from 0-255. -
merge
public static <V> V[] merge(Class<V> clazz, Collection<? extends Collection<? extends V>> collections, Comparator<? super V> comparator) Merges multiple already-sorted collections into one big array.Worst-case Complexity:
0 collections: constant 1 collection: O(n), where n is the number of elements in the collection 2 collection: O(n+m), where n is the number of elements in one collection, and m is the number of elements in the other collection 3+ collections: O(n*log(m)), where n is the total number of elements in all collections, and m is the number of collections- Returns:
- Object[] of results.
-
asUnmodifiableSet
Gets an unmodifiable set view with the contents of a backing array.Contains is implemented sequentially and is thus O(n). As a result, this is best used for very small sets.
In order to have correct set semantics, the array must have unique values as determined by the element equals methods. This is not checked, however, and passing in an array with duplicate values will result in duplicate values on iteration and a size that doesn't match the number of unique values.
- Parameters:
array- may benull, which will returnnull- Returns:
- an unmodifiable set or
nullwhenarray == null
-
indexOf
public static <E> int indexOf(E[] array, E element) Finds the first index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
indexOf
public static <E> int indexOf(E[] array, E element, int fromIndex) Finds the first index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
lastIndexOf
public static <E> int lastIndexOf(E[] array, E element) Finds the last index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
lastIndexOf
public static <E> int lastIndexOf(E[] array, E element, int fromIndex) Finds the last index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
indexOf
Finds the first index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
indexOf
Finds the first index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
lastIndexOf
Finds the last index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
lastIndexOf
Finds the last index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
indexOf
public static int indexOf(byte[] array, byte element) Finds the first index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
indexOf
public static int indexOf(byte[] array, byte element, int fromIndex) Finds the first index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
lastIndexOf
public static int lastIndexOf(byte[] array, byte element) Finds the last index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
lastIndexOf
public static int lastIndexOf(byte[] array, byte element, int fromIndex) Finds the last index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
indexOf
public static int indexOf(short[] array, short element) Finds the first index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
indexOf
public static int indexOf(short[] array, short element, int fromIndex) Finds the first index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
lastIndexOf
public static int lastIndexOf(short[] array, short element) Finds the last index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
lastIndexOf
public static int lastIndexOf(short[] array, short element, int fromIndex) Finds the last index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
indexOf
public static int indexOf(int[] array, int element) Finds the first index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
indexOf
public static int indexOf(int[] array, int element, int fromIndex) Finds the first index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
lastIndexOf
public static int lastIndexOf(int[] array, int element) Finds the last index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
lastIndexOf
public static int lastIndexOf(int[] array, int element, int fromIndex) Finds the last index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
indexOf
public static int indexOf(long[] array, long element) Finds the first index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
indexOf
public static int indexOf(long[] array, long element, int fromIndex) Finds the first index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
lastIndexOf
public static int lastIndexOf(long[] array, long element) Finds the last index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
lastIndexOf
public static int lastIndexOf(long[] array, long element, int fromIndex) Finds the last index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
indexOf
public static int indexOf(float[] array, float element) Finds the first index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
indexOf
public static int indexOf(float[] array, float element, int fromIndex) Finds the first index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
lastIndexOf
public static int lastIndexOf(float[] array, float element) Finds the last index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
lastIndexOf
public static int lastIndexOf(float[] array, float element, int fromIndex) Finds the last index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
indexOf
public static int indexOf(double[] array, double element) Finds the first index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
indexOf
public static int indexOf(double[] array, double element, int fromIndex) Finds the first index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
lastIndexOf
public static int lastIndexOf(double[] array, double element) Finds the last index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
lastIndexOf
public static int lastIndexOf(double[] array, double element, int fromIndex) Finds the last index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
indexOf
public static int indexOf(char[] array, char element) Finds the first index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
indexOf
public static int indexOf(char[] array, char element, int fromIndex) Finds the first index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
lastIndexOf
public static int lastIndexOf(char[] array, char element) Finds the last index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
lastIndexOf
public static int lastIndexOf(char[] array, char element, int fromIndex) Finds the last index of an element or-1if not found.- Parameters:
array- may benull, in which the element is never found
-
hashCode
public static int hashCode(byte[] a, int off, int len) Computes hashCode compatible with Arrays.hashCode, but only across the given subset of the array.- Parameters:
a- may benull, which will return0- See Also:
-
maxNonNull
Gets the maximum non-null value, ornullif no non-null value.- Parameters:
values- may benull, which will returnnull
-
sortParallelArrays
public static <E extends Comparable<? super E>> void sortParallelArrays(E[] keys, Object[]... otherArrays) Sorts parallel arrays in-place. Sorts by the first array and updates all other arrays to match. Uses the natural sorting of the objects. All arrays must be the same length.The time complexity isn't too bad. Looks something like
O((M+1)*N*log(N)), whereMis the number of otherArrays andNis the number of keys. No crazy worst-case issues, at least.- Parameters:
keys- the values used to sort, may be duplicateotherArrays- the arrays to have reordered to match the sorting of the keys array.- Throws:
IllegalArgumentException- if any of otherArrays have a length different that the keys array.
-

Arrays.equals(byte[], int, int, byte[], int, int)