Package org.wildfly.common.array
Class Arrays2
- java.lang.Object
-
- org.wildfly.common.array.Arrays2
-
public final class Arrays2 extends java.lang.Object
Useful general array manipulations beyond whatArrays
provides.- Author:
- David M. Lloyd
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <E> E[]
compactNulls(E[] original)
Create a new array from the original which contains nonull
values, possibly destroying the contents of the original array.static <E> E[]
createArray(java.lang.Class<E> elementType, int size)
Create an array of the given size, ensuring type safety.static boolean
equals(byte[] a1, int offs1, byte[] a2)
Compare two sub-regions of the given arrays.static boolean
equals(byte[] a1, int offs1, byte[] a2, int offs2, int len)
Compare two sub-regions of the given arrays.static boolean
equals(char[] a1, int offs1, char[] a2)
Compare two sub-regions of the given arrays.static boolean
equals(char[] a1, int offs1, char[] a2, int offs2, int len)
Compare two sub-regions of the given arrays.static boolean
equals(char[] a1, int offs1, java.lang.String a2)
Compare two sub-regions of the given array and string.static boolean
equals(char[] a1, int offs1, java.lang.String a2, int offs2, int len)
Compare two sub-regions of the given array and string.static boolean
equals(java.lang.String a1, char[] a2)
Compare the given array and string.static boolean
equals(java.lang.String a1, int offs1, char[] a2)
Compare two sub-regions of the given array and string.static int
indexOf(byte[] array, int search)
Find the first occurrence of a byte in a byte array.static int
indexOf(byte[] array, int search, int offs)
Find the first occurrence of a byte in a byte array.static int
indexOf(byte[] array, int search, int offs, int len)
Find the first occurrence of a byte in a byte array.static java.lang.String
objectToString(java.lang.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 java.lang.String
toString(byte[] bytes)
Render the given byte array as a hexadecimal string in big-endian order.
-
-
-
Method Detail
-
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:
true
if the regions are equal, orfalse
if 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:
true
if the regions are equal, orfalse
if 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:
true
if the regions are equal, orfalse
if 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:
true
if the regions are equal, orfalse
if 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, java.lang.String a2, int offs2, int len)
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:
true
if the regions are equal, orfalse
if the regions are not equal or a length or offset is out of bounds for the array or string
-
equals
public static boolean equals(char[] a1, int offs1, java.lang.String a2)
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:
true
if the regions are equal, orfalse
if the regions are not equal or a length or offset is out of bounds for the array or string
-
equals
public static boolean equals(java.lang.String a1, int offs1, char[] a2)
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:
true
if the regions are equal, orfalse
if the regions are not equal or a length or offset is out of bounds for the array or string
-
equals
public static boolean equals(java.lang.String a1, char[] a2)
Compare the given array and string.- Parameters:
a1
- the string (must not benull
)a2
- the array (must not benull
)- Returns:
true
if the regions are equal, orfalse
if the regions are not equal or a length or offset is out of bounds for the array or string
-
of
@SafeVarargs public static <T> T[] of(T... items)
Return the varargs list as its array representation.- Type Parameters:
T
- the item type- Parameters:
items
- the items- Returns:
- the array
-
toString
public static java.lang.String toString(byte[] bytes)
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
public static <E> E[] createArray(java.lang.Class<E> elementType, int size)
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 nonull
values, possibly destroying the contents of the original array. If the original contains nonull
values, 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
public static java.lang.String objectToString(java.lang.Object value)
Deeply convert an object to a string, expanding arrays as they are encountered.- Parameters:
value
- the value to convert- Returns:
- the string
-
-