Top Description Constructors Methods
org.wildfly.common.array

public final Class Arrays2

extends Object
Class Inheritance
Imports
java.lang.reflect.Array, java.util.Arrays

Useful general array manipulations beyond what Arrays provides.
Author
David M. Lloyd

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <
the element type
E
>
E[]

Returns:

the compacted (possibly empty) array
compactNulls
(E[]
the original array (not null, will be modified)
original
)

Create a new array from the original which contains no null values, possibly destroying the contents of the original array.

public static <
the element type
E
>
E[]

Returns:

the array
createArray
(Class<E>
the element type class
elementType
,
int
the array size
size
)

Create an array of the given size, ensuring type safety.

public static boolean

Returns:

true if the regions are equal, or false if the regions are not equal or a length or offset is out of bounds for an array
equals
(byte[]
the first array (must not be null)
a1
,
int
the offset into the first array
offs1
,
byte[]
the second array (must not be null)
a2
,
int
the offset into the second array
offs2
,
int
the length to compare
len
)

Compare two sub-regions of the given arrays.

public static boolean

Returns:

true if the regions are equal, or false if the regions are not equal or a length or offset is out of bounds for an array
equals
(byte[]
the first array (must not be null)
a1
,
int
the offset into the first array
offs1
,
byte[]
the second array (must not be null)
a2
)

Compare two sub-regions of the given arrays.

public static boolean

Returns:

true if the regions are equal, or false if the regions are not equal or a length or offset is out of bounds for an array
equals
(char[]
the first array (must not be null)
a1
,
int
the offset into the first array
offs1
,
char[]
the second array (must not be null)
a2
,
int
the offset into the second array
offs2
,
int
the length to compare
len
)

Compare two sub-regions of the given arrays.

public static boolean

Returns:

true if the regions are equal, or false if the regions are not equal or a length or offset is out of bounds for an array
equals
(char[]
the first array (must not be null)
a1
,
int
the offset into the first array
offs1
,
char[]
the second array (must not be null)
a2
)

Compare two sub-regions of the given arrays.

public static boolean

Returns:

true if the regions are equal, or false if the regions are not equal or a length or offset is out of bounds for the array or string
equals
(char[]
the array (must not be null)
a1
,
int
the offset into the array
offs1
,
String
the string (must not be null)
a2
,
int
the offset into the string
offs2
,
int
the length to compare
len
)

Compare two sub-regions of the given array and string.

public static boolean

Returns:

true if the regions are equal, or false if the regions are not equal or a length or offset is out of bounds for the array or string
equals
(char[]
the array (must not be null)
a1
,
int
the offset into the array
offs1
,
String
the string (must not be null)
a2
)

Compare two sub-regions of the given array and string.

public static boolean

Returns:

true if the regions are equal, or false if the regions are not equal or a length or offset is out of bounds for the array or string
equals
(String
the string (must not be null)
a1
,
int
the offset into the string
offs1
,
char[]
the array (must not be null)
a2
)

Compare two sub-regions of the given array and string.

public static boolean

Returns:

true if the regions are equal, or false if the regions are not equal or a length or offset is out of bounds for the array or string
equals
(String
the string (must not be null)
a1
,
char[]
the array (must not be null)
a2
)

Compare the given array and string.

private static char
hex(int v)

public static int

Returns:

the index, or -1 if the byte is not found
indexOf
(byte[]
the array to search
array
,
int
the byte to search for
search
,
int
the offset in the array to start searching
offs
,
int
the length of the segment to search
len
)

Find the first occurrence of a byte in a byte array.

public static int

Returns:

the index, or -1 if the byte is not found
indexOf
(byte[]
the array to search
array
,
int
the byte to search for
search
,
int
the offset in the array to start searching
offs
)

Find the first occurrence of a byte in a byte array.

public static int

Returns:

the index, or -1 if the byte is not found
indexOf
(byte[]
the array to search
array
,
int
the byte to search for
search
)

Find the first occurrence of a byte in a byte array.

public static String

Returns:

the string
objectToString
(Object
the value to convert
value
)

Deeply convert an object to a string, expanding arrays as they are encountered.

public static <
the item type
T
>
T[]

Returns:

the array
of
(final T...
the items
items
)

Return the varargs list as its array representation.

public static String

Returns:

the string
toString
(final byte[]
the byte array (must not be null)
bytes
)

Render the given byte array as a hexadecimal string in big-endian order.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Arrays2back to summary
private Arrays2()

Method Detail

compactNullsback to summary
public static <E> E[] compactNulls(E[] original)

Create a new array from the original which contains no null values, possibly destroying the contents of the original array. If the original contains no null values, the original array is returned.

Parameters
<E>
the element type
original:E[]

the original array (not null, will be modified)

Returns:E[]

the compacted (possibly empty) array

createArrayback to summary
public static <E> E[] createArray(Class<E> elementType, int size)

Create an array of the given size, ensuring type safety.

Parameters
<E>
the element type
elementType:Class<E>

the element type class

size:int

the array size

Returns:E[]

the array

Annotations
@SuppressWarnings:unchecked
equalsback to summary
public static boolean equals(byte[] a1, int offs1, byte[] a2, int offs2, int len)

Compare two sub-regions of the given arrays.

Parameters
a1:byte[]

the first array (must not be null)

offs1:int

the offset into the first array

a2:byte[]

the second array (must not be null)

offs2:int

the offset into the second array

len:int

the length to compare

Returns:boolean

true if the regions are equal, or false if the regions are not equal or a length or offset is out of bounds for an array

equalsback to summary
public static boolean equals(byte[] a1, int offs1, byte[] a2)

Compare two sub-regions of the given arrays.

Parameters
a1:byte[]

the first array (must not be null)

offs1:int

the offset into the first array

a2:byte[]

the second array (must not be null)

Returns:boolean

true if the regions are equal, or false if the regions are not equal or a length or offset is out of bounds for an array

equalsback to summary
public static boolean equals(char[] a1, int offs1, char[] a2, int offs2, int len)

Compare two sub-regions of the given arrays.

Parameters
a1:char[]

the first array (must not be null)

offs1:int

the offset into the first array

a2:char[]

the second array (must not be null)

offs2:int

the offset into the second array

len:int

the length to compare

Returns:boolean

true if the regions are equal, or false if the regions are not equal or a length or offset is out of bounds for an array

equalsback to summary
public static boolean equals(char[] a1, int offs1, char[] a2)

Compare two sub-regions of the given arrays.

Parameters
a1:char[]

the first array (must not be null)

offs1:int

the offset into the first array

a2:char[]

the second array (must not be null)

Returns:boolean

true if the regions are equal, or false if the regions are not equal or a length or offset is out of bounds for an array

equalsback to summary
public static boolean equals(char[] a1, int offs1, String a2, int offs2, int len)

Compare two sub-regions of the given array and string.

Parameters
a1:char[]

the array (must not be null)

offs1:int

the offset into the array

a2:String

the string (must not be null)

offs2:int

the offset into the string

len:int

the length to compare

Returns:boolean

true if the regions are equal, or false if the regions are not equal or a length or offset is out of bounds for the array or string

equalsback to summary
public static boolean equals(char[] a1, int offs1, String a2)

Compare two sub-regions of the given array and string.

Parameters
a1:char[]

the array (must not be null)

offs1:int

the offset into the array

a2:String

the string (must not be null)

Returns:boolean

true if the regions are equal, or false if the regions are not equal or a length or offset is out of bounds for the array or string

equalsback to summary
public static boolean equals(String a1, int offs1, char[] a2)

Compare two sub-regions of the given array and string.

Parameters
a1:String

the string (must not be null)

offs1:int

the offset into the string

a2:char[]

the array (must not be null)

Returns:boolean

true if the regions are equal, or false if the regions are not equal or a length or offset is out of bounds for the array or string

equalsback to summary
public static boolean equals(String a1, char[] a2)

Compare the given array and string.

Parameters
a1:String

the string (must not be null)

a2:char[]

the array (must not be null)

Returns:boolean

true if the regions are equal, or false if the regions are not equal or a length or offset is out of bounds for the array or string

hexback to summary
private static char hex(int v)
indexOfback to summary
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:byte[]

the array to search

search:int

the byte to search for

offs:int

the offset in the array to start searching

len:int

the length of the segment to search

Returns:int

the index, or -1 if the byte is not found

indexOfback to summary
public static int indexOf(byte[] array, int search, int offs)

Find the first occurrence of a byte in a byte array.

Parameters
array:byte[]

the array to search

search:int

the byte to search for

offs:int

the offset in the array to start searching

Returns:int

the index, or -1 if the byte is not found

indexOfback to summary
public static int indexOf(byte[] array, int search)

Find the first occurrence of a byte in a byte array.

Parameters
array:byte[]

the array to search

search:int

the byte to search for

Returns:int

the index, or -1 if the byte is not found

objectToStringback to summary
public static String objectToString(Object value)

Deeply convert an object to a string, expanding arrays as they are encountered.

Parameters
value:Object

the value to convert

Returns:String

the string

ofback to summary
public static <T> T[] of(final T... items)

Return the varargs list as its array representation.

Parameters
<T>
the item type
items:T[]

the items

Returns:T[]

the array

Annotations
@SafeVarargs
toStringback to summary
public static String toString(final byte[] bytes)

Render the given byte array as a hexadecimal string in big-endian order.

Parameters
bytes:byte[]

the byte array (must not be null)

Returns:String

the string