|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.mockrunner.util.common.ArrayUtil
public class ArrayUtil
Util class for arrays
Constructor Summary | |
---|---|
ArrayUtil()
|
Method Summary | |
---|---|
static void |
addBytesToList(byte[] data,
int offset,
int len,
java.util.List 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,
java.util.List 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(java.lang.Object array1,
java.lang.Object array2)
Compares the two specified arrays. |
static int |
computeHashCode(java.lang.Object array)
Returns a suitable hash code for the specified array. |
static java.lang.Object |
convertToArray(java.lang.Object object)
Creates an array with a single object as component. |
static java.lang.Object[] |
convertToObjectArray(java.lang.Object sourceArray)
Returns an object array by wrapping primitive types. |
static java.lang.Object |
convertToPrimitiveArray(java.lang.Object[] sourceArray)
Returns a primitive array by unwrapping the corresponding types. |
static java.lang.Object |
copyArray(java.lang.Object array)
Returns a copy of the specified array. |
static void |
ensureUnique(java.lang.String[] values)
Ensures that each entry in the specified string array is unique by adding a number to duplicate entries. |
static byte[] |
getByteArrayFromList(java.util.List data)
Returns a byte array containing the bytes from the List . |
static byte[] |
getByteArrayFromList(java.util.List data,
int index)
Returns a byte array containing the bytes from the List . |
static byte[] |
getByteArrayFromList(java.util.List data,
int index,
int len)
Returns a byte array containing the bytes from the List . |
static java.util.List |
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 java.lang.Object |
truncateArray(java.lang.Object sourceArray,
int len)
Returns a truncated copy of sourceArray. |
static java.lang.Object |
truncateArray(java.lang.Object sourceArray,
int index,
int len)
Returns a truncated copy of sourceArray. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ArrayUtil()
Method Detail |
---|
public static java.util.List getListFromByteArray(byte[] data)
List
containing the bytes from the
specified array as Byte
objects.
data
- the byte data
List
with the Byte
objectspublic static byte[] getByteArrayFromList(java.util.List data)
List
.
The List
must contain Byte
objects.
null
entries in the List
are
allowed, the resulting byte will be 0.
data
- the List
public static byte[] getByteArrayFromList(java.util.List 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 List
index
- the index at which to start
public static byte[] getByteArrayFromList(java.util.List 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 List
index
- the index at which to startlen
- the number of bytes
public static void addBytesToList(byte[] data, java.util.List 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 List
index
- the index at which to start copyingpublic static void addBytesToList(byte[] data, int offset, int len, java.util.List 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 List
index
- the index at which to start copyingpublic static java.lang.Object truncateArray(java.lang.Object sourceArray, int len)
sourceArray
- the source arraylen
- the truncate length
java.lang.IllegalArgumentException
- if the specified object
is not an array (either of reference or primitive
component type)public static java.lang.Object truncateArray(java.lang.Object sourceArray, int index, int len)
sourceArray
- the source arrayindex
- the start indexlen
- the truncate length
java.lang.IllegalArgumentException
- if the specified object
is not an array (either of reference or primitive
component type)public static java.lang.Object copyArray(java.lang.Object array)
array
- the array
public static java.lang.Object[] convertToObjectArray(java.lang.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 array
java.lang.IllegalArgumentException
- if the specified object
is not an array (either of reference or primitive
component type)public static java.lang.Object convertToPrimitiveArray(java.lang.Object[] sourceArray)
Integer[]
),
an IllegalArgumentException
will be thrown.
If an array element is null
, an IllegalArgumentException
will be thrown.
sourceArray
- the array
java.lang.IllegalArgumentException
- if the specified array
is not an array of primitive wrapper types or if an
array element is null
public static java.lang.Object convertToArray(java.lang.Object object)
object
- the object
public static boolean areArraysEqual(java.lang.Object array1, java.lang.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 array
true
if the arrays are equal, false
otherwisepublic static int computeHashCode(java.lang.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 array
public static int indexOf(byte[] source, byte[] bytes)
source
- the array in which to searchbytes
- the array to search
public 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 search
public static void ensureUnique(java.lang.String[] values)
"entry"
occurs three
times, the three entries will be renamed to "entry1"
,
"entry2"
and "entry3"
.
values
- the array of strings
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |