Package org.wildfly.common.array
Class Arrays2
java.lang.Object
org.wildfly.common.array.Arrays2
Useful general array manipulations beyond what
Arrays provides.- Author:
- David M. Lloyd
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E> E[]compactNulls(E[] original) Create a new array from the original which contains nonullvalues, possibly destroying the contents of the original array.static <E> E[]createArray(Class<E> elementType, int size) Create an array of the given size, ensuring type safety.static booleanequals(byte[] a1, int offs1, byte[] a2) Compare two sub-regions of the given arrays.static booleanequals(byte[] a1, int offs1, byte[] a2, int offs2, int len) Compare two sub-regions of the given arrays.static booleanequals(char[] a1, int offs1, char[] a2) Compare two sub-regions of the given arrays.static booleanequals(char[] a1, int offs1, char[] a2, int offs2, int len) Compare two sub-regions of the given arrays.static booleanCompare two sub-regions of the given array and string.static booleanCompare two sub-regions of the given array and string.static booleanCompare the given array and string.static booleanCompare two sub-regions of the given array and string.static intindexOf(byte[] array, int search) Find the first occurrence of a byte in a byte array.static intindexOf(byte[] array, int search, int offs) Find the first occurrence of a byte in a byte array.static intindexOf(byte[] array, int search, int offs, int len) Find the first occurrence of a byte in a byte array.static StringobjectToString(Object value) Deeply convert an object to a string, expanding arrays as they are encountered.static <T> T[]of(T... items) Return the varargs list as its array representation.static StringtoString(byte[] bytes) Render the given byte array as a hexadecimal string in big-endian order.
-
Method Details
-
equals
public static boolean equals(byte[] a1, int offs1, byte[] a2, int offs2, int len) Compare two sub-regions of the given arrays.- Parameters:
a1- the first array (must not benull)offs1- the offset into the first arraya2- the second array (must not benull)offs2- the offset into the second arraylen- the length to compare- Returns:
trueif the regions are equal, orfalseif the regions are not equal or a length or offset is out of bounds for an array
-
equals
public static boolean equals(byte[] a1, int offs1, byte[] a2) Compare two sub-regions of the given arrays.- Parameters:
a1- the first array (must not benull)offs1- the offset into the first arraya2- the second array (must not benull)- Returns:
trueif the regions are equal, orfalseif the regions are not equal or a length or offset is out of bounds for an array
-
equals
public static boolean equals(char[] a1, int offs1, char[] a2, int offs2, int len) Compare two sub-regions of the given arrays.- Parameters:
a1- the first array (must not benull)offs1- the offset into the first arraya2- the second array (must not benull)offs2- the offset into the second arraylen- the length to compare- Returns:
trueif the regions are equal, orfalseif the regions are not equal or a length or offset is out of bounds for an array
-
equals
public static boolean equals(char[] a1, int offs1, char[] a2) Compare two sub-regions of the given arrays.- Parameters:
a1- the first array (must not benull)offs1- the offset into the first arraya2- the second array (must not benull)- Returns:
trueif the regions are equal, orfalseif the regions are not equal or a length or offset is out of bounds for an array
-
equals
Compare two sub-regions of the given array and string.- Parameters:
a1- the array (must not benull)offs1- the offset into the arraya2- the string (must not benull)offs2- the offset into the stringlen- the length to compare- Returns:
trueif the regions are equal, orfalseif the regions are not equal or a length or offset is out of bounds for the array or string
-
equals
Compare two sub-regions of the given array and string.- Parameters:
a1- the array (must not benull)offs1- the offset into the arraya2- the string (must not benull)- Returns:
trueif the regions are equal, orfalseif the regions are not equal or a length or offset is out of bounds for the array or string
-
equals
Compare two sub-regions of the given array and string.- Parameters:
a1- the string (must not benull)offs1- the offset into the stringa2- the array (must not benull)- Returns:
trueif the regions are equal, orfalseif the regions are not equal or a length or offset is out of bounds for the array or string
-
equals
Compare the given array and string.- Parameters:
a1- the string (must not benull)a2- the array (must not benull)- Returns:
trueif the regions are equal, orfalseif the regions are not equal or a length or offset is out of bounds for the array or string
-
of
Return the varargs list as its array representation.- Type Parameters:
T- the item type- Parameters:
items- the items- Returns:
- the array
-
toString
Render the given byte array as a hexadecimal string in big-endian order.- Parameters:
bytes- the byte array (must not benull)- Returns:
- the string
-
indexOf
public static int indexOf(byte[] array, int search, int offs, int len) Find the first occurrence of a byte in a byte array.- Parameters:
array- the array to searchsearch- the byte to search foroffs- the offset in the array to start searchinglen- the length of the segment to search- Returns:
- the index, or -1 if the byte is not found
-
indexOf
public static int indexOf(byte[] array, int search, int offs) Find the first occurrence of a byte in a byte array.- Parameters:
array- the array to searchsearch- the byte to search foroffs- the offset in the array to start searching- Returns:
- the index, or -1 if the byte is not found
-
indexOf
public static int indexOf(byte[] array, int search) Find the first occurrence of a byte in a byte array.- Parameters:
array- the array to searchsearch- the byte to search for- Returns:
- the index, or -1 if the byte is not found
-
createArray
Create an array of the given size, ensuring type safety.- Type Parameters:
E- the element type- Parameters:
elementType- the element type classsize- the array size- Returns:
- the array
-
compactNulls
public static <E> E[] compactNulls(E[] original) Create a new array from the original which contains nonullvalues, possibly destroying the contents of the original array. If the original contains nonullvalues, the original array is returned.- Type Parameters:
E- the element type- Parameters:
original- the original array (notnull, will be modified)- Returns:
- the compacted (possibly empty) array
-
objectToString
Deeply convert an object to a string, expanding arrays as they are encountered.- Parameters:
value- the value to convert- Returns:
- the string
-