public class ArrayUtil extends Object
| Constructor and Description |
|---|
ArrayUtil() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addBytesToList(byte[] data,
int offset,
int len,
List<Byte> list,
int index)
Copies the bytes from the specified array to the specified
List as Byte objects starting
at the specified index. |
static void |
addBytesToList(byte[] data,
List<Byte> list,
int index)
Copies the bytes from the specified array to the specified
List as Byte objects starting
at the specified index. |
static boolean |
areArraysEqual(Object array1,
Object array2)
Compares the two specified arrays.
|
static int |
computeHashCode(Object array)
Returns a suitable hash code for the specified array.
|
static Object |
convertToArray(Object object)
Creates an array with a single object as component.
|
static Object[] |
convertToObjectArray(Object sourceArray)
Returns an object array by wrapping primitive types.
|
static Object |
convertToPrimitiveArray(Object[] sourceArray)
Returns a primitive array by unwrapping the corresponding types.
|
static Object |
copyArray(Object array)
Returns a copy of the specified array.
|
static void |
ensureUnique(String[] values)
Ensures that each entry in the specified string array
is unique by adding a number to duplicate entries.
|
static byte[] |
getByteArrayFromList(List<Byte> data)
Returns a byte array containing the bytes from the
List. |
static byte[] |
getByteArrayFromList(List<Byte> data,
int index)
Returns a byte array containing the bytes from the
List. |
static byte[] |
getByteArrayFromList(List<Byte> data,
int index,
int len)
Returns a byte array containing the bytes from the
List. |
static List<Byte> |
getListFromByteArray(byte[] data)
Returns a
List containing the bytes from the
specified array as Byte objects. |
static int |
indexOf(byte[] source,
byte[] bytes)
Returns the index of the first occurence of the
array bytes in the array source.
|
static int |
indexOf(byte[] source,
byte[] bytes,
int index)
Returns the index of the first occurence of the
array bytes in the array source.
|
static Object |
truncateArray(Object sourceArray,
int len)
Returns a truncated copy of sourceArray.
|
static Object |
truncateArray(Object sourceArray,
int index,
int len)
Returns a truncated copy of sourceArray.
|
public static List<Byte> getListFromByteArray(byte[] data)
List containing the bytes from the
specified array as Byte objects.data - the byte dataList with the Byte objectspublic static byte[] getByteArrayFromList(List<Byte> data)
List.
The List must contain Byte objects.
null entries in the List are
allowed, the resulting byte will be 0.data - the Listpublic static byte[] getByteArrayFromList(List<Byte> data, int index)
List.
The List must contain Byte objects.
null entries in the List are
allowed, the resulting byte will be 0.data - the Listindex - the index at which to startpublic static byte[] getByteArrayFromList(List<Byte> data, int index, int len)
List.
The List must contain Byte objects.
null entries in the List are
allowed, the resulting byte will be 0.data - the Listindex - the index at which to startlen - the number of bytespublic static void addBytesToList(byte[] data,
List<Byte> list,
int index)
List as Byte objects starting
at the specified index. Grows the list if necessary.
index must be a valid index in the list.data - the byte datalist - the Listindex - the index at which to start copyingpublic static void addBytesToList(byte[] data,
int offset,
int len,
List<Byte> list,
int index)
List as Byte objects starting
at the specified index. Grows the list if necessary.
index must be a valid index in the list.data - the byte dataoffset - the offset into the byte array at which to startlen - the number of bytes to copylist - the Listindex - the index at which to start copyingpublic static Object truncateArray(Object sourceArray, int len)
sourceArray - the source arraylen - the truncate lengthIllegalArgumentException - if the specified object
is not an array (either of reference or primitive
component type)public static Object truncateArray(Object sourceArray, int index, int len)
sourceArray - the source arrayindex - the start indexlen - the truncate lengthIllegalArgumentException - if the specified object
is not an array (either of reference or primitive
component type)public static Object copyArray(Object array)
array - the arraypublic static Object[] convertToObjectArray(Object sourceArray)
Object[]
with the corresponding wrapper component type is returned.
If the specified array is already an object array, the instance is
returned unchanged.sourceArray - the arrayIllegalArgumentException - if the specified object
is not an array (either of reference or primitive
component type)public static Object convertToPrimitiveArray(Object[] sourceArray)
Integer[]),
an IllegalArgumentException will be thrown.
If an array element is null, an IllegalArgumentException
will be thrown.sourceArray - the arrayIllegalArgumentException - if the specified array
is not an array of primitive wrapper types or if an
array element is nullpublic static Object convertToArray(Object object)
object - the objectpublic static boolean areArraysEqual(Object array1, Object array2)
null, true is returned. If both passed
objects are not arrays, they are compared using equals.
Otherwise all array elements are compared using equals.
This method does not handle multidimensional arrays, i.e. if an
array contains another array, comparison is based on identity.array1 - the first arrayarray2 - the second arraytrue if the arrays are equal, false
otherwisepublic static int computeHashCode(Object array)
null, 0 is returned.
It is allowed to pass an object that is not an array, in this case,
the hash code of the object will be returned. Otherwise the hash code
will be based on the array elements. null elements are
allowed.
This method does not handle multidimensional arrays, i.e. if an
array contains another array, the hash code is based on identity.array - the arraypublic static int indexOf(byte[] source,
byte[] bytes)
source - the array in which to searchbytes - the array to searchpublic static int indexOf(byte[] source,
byte[] bytes,
int index)
source - the array in which to searchbytes - the array to searchindex - the index where to begin the searchpublic static void ensureUnique(String[] values)
"entry" occurs three
times, the three entries will be renamed to "entry1",
"entry2" and "entry3".values - the array of stringsCopyright © 2003-2016. All Rights Reserved.