| java.lang.Object com.mockrunner.util.common.ArrayUtil
ArrayUtil | public class ArrayUtil (Code) | | Util class for arrays
|
Method Summary | |
public static void | addBytesToList(byte[] data, List list, int index) Copies the bytes from the specified array to the specified
List as Byte objects starting
at the specified index. | public static void | addBytesToList(byte[] data, int offset, int len, List list, int index) Copies the bytes from the specified array to the specified
List as Byte objects starting
at the specified index. | public static boolean | areArraysEqual(Object array1, Object array2) Compares the two specified arrays. | public static int | computeHashCode(Object array) Returns a suitable hash code for the specified array. | public static Object | convertToArray(Object object) Creates an array with a single object as component.
If the specified object is an array, it will be returned
unchanged. | public static Object[] | convertToObjectArray(Object sourceArray) Returns an object array by wrapping primitive types. | public static Object | convertToPrimitiveArray(Object[] sourceArray) Returns a primitive array by unwrapping the corresponding types. | public static Object | copyArray(Object array) Returns a copy of the specified array. | public static void | ensureUnique(String[] values) Ensures that each entry in the specified string array
is unique by adding a number to duplicate entries.
I.e. | public static byte[] | getByteArrayFromList(List data) Returns a byte array containing the bytes from the List . | public static byte[] | getByteArrayFromList(List data, int index) Returns a byte array containing the bytes from the List . | public static byte[] | getByteArrayFromList(List data, int index, int len) Returns a byte array containing the bytes from the List . | public static List | getListFromByteArray(byte[] data) Returns a List containing the bytes from the
specified array as Byte objects. | public static int | indexOf(byte[] source, byte[] bytes) Returns the index of the first occurence of the
array bytes in the array source. | public static int | indexOf(byte[] source, byte[] bytes, int index) Returns the index of the first occurence of the
array bytes in the array source. | public static Object | truncateArray(Object sourceArray, int len) Returns a truncated copy of sourceArray. | public static Object | truncateArray(Object sourceArray, int index, int len) Returns a truncated copy of sourceArray. |
addBytesToList | public static void addBytesToList(byte[] data, List list, int index)(Code) | | Copies the bytes from the specified array to the specified
List as Byte objects starting
at the specified index. Grows the list if necessary.
index must be a valid index in the list.
Parameters: data - the byte data Parameters: list - the List Parameters: index - the index at which to start copying |
addBytesToList | public static void addBytesToList(byte[] data, int offset, int len, List list, int index)(Code) | | Copies the bytes from the specified array to the specified
List as Byte objects starting
at the specified index. Grows the list if necessary.
index must be a valid index in the list.
Parameters: data - the byte data Parameters: offset - the offset into the byte array at which to start Parameters: len - the number of bytes to copy Parameters: list - the List Parameters: index - the index at which to start copying |
areArraysEqual | public static boolean areArraysEqual(Object array1, Object array2)(Code) | | Compares the two specified arrays. If both passed objects are
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.
Parameters: array1 - the first array Parameters: array2 - the second array true if the arrays are equal, false otherwise |
computeHashCode | public static int computeHashCode(Object array)(Code) | | Returns a suitable hash code for the specified array. If the passed
object is 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.
Parameters: array - the array a suitable hash code |
convertToArray | public static Object convertToArray(Object object)(Code) | | Creates an array with a single object as component.
If the specified object is an array, it will be returned
unchanged. Otherwise an array with the specified object
as the single element will be returned.
Parameters: object - the object the corresponding array |
convertToObjectArray | public static Object[] convertToObjectArray(Object sourceArray)(Code) | | Returns an object array by wrapping primitive types. If the
specified array is of primitive component type, an Object[]
with the corresponding wrapper component type is returned.
If the specified array is already an object array, the instance is
returned unchanged.
Parameters: sourceArray - the array the corresponding object array throws: IllegalArgumentException - if the specified objectis not an array (either of reference or primitivecomponent type) |
convertToPrimitiveArray | public static Object convertToPrimitiveArray(Object[] sourceArray)(Code) | | Returns a primitive array by unwrapping the corresponding types. If the
specified array is not an array of primitive wrapper types (e.g. Integer[] ),
an IllegalArgumentException will be thrown.
If an array element is null , an IllegalArgumentException
will be thrown.
Parameters: sourceArray - the array the corresponding primitive array throws: IllegalArgumentException - if the specified arrayis not an array of primitive wrapper types or if anarray element is null |
copyArray | public static Object copyArray(Object array)(Code) | | Returns a copy of the specified array. If array
is not an array, the object itself will be returned.
Otherwise a copy of the array will be returned. The components
themselves are not cloned.
Parameters: array - the array the copy of the array |
ensureUnique | public static void ensureUnique(String[] values)(Code) | | Ensures that each entry in the specified string array
is unique by adding a number to duplicate entries.
I.e. if the string "entry" occurs three
times, the three entries will be renamed to "entry1" ,
"entry2" and "entry3" .
Parameters: values - the array of strings |
getByteArrayFromList | public static byte[] getByteArrayFromList(List data)(Code) | | Returns a byte array containing the bytes from the List .
The List must contain Byte objects.
null entries in the List are
allowed, the resulting byte will be 0.
Parameters: data - the List the resulting byte array |
getByteArrayFromList | public static byte[] getByteArrayFromList(List data, int index)(Code) | | Returns a byte array containing the bytes from the List .
The List must contain Byte objects.
null entries in the List are
allowed, the resulting byte will be 0.
Parameters: data - the List Parameters: index - the index at which to start the resulting byte array |
getByteArrayFromList | public static byte[] getByteArrayFromList(List data, int index, int len)(Code) | | Returns a byte array containing the bytes from the List .
The List must contain Byte objects.
null entries in the List are
allowed, the resulting byte will be 0.
Parameters: data - the List Parameters: index - the index at which to start Parameters: len - the number of bytes the resulting byte array |
getListFromByteArray | public static List getListFromByteArray(byte[] data)(Code) | | Returns a List containing the bytes from the
specified array as Byte objects.
Parameters: data - the byte data the List with the Byte objects |
indexOf | public static int indexOf(byte[] source, byte[] bytes)(Code) | | Returns the index of the first occurence of the
array bytes in the array source.
Parameters: source - the array in which to search Parameters: bytes - the array to search the index of the first occurence or-1, if source does not contain bytes |
indexOf | public static int indexOf(byte[] source, byte[] bytes, int index)(Code) | | Returns the index of the first occurence of the
array bytes in the array source.
Parameters: source - the array in which to search Parameters: bytes - the array to search Parameters: index - the index where to begin the search the index of the first occurence or-1, if source does not contain bytes |
truncateArray | public static Object truncateArray(Object sourceArray, int len)(Code) | | Returns a truncated copy of sourceArray. len
entries are copied.
Parameters: sourceArray - the source array Parameters: len - the truncate length the truncated array throws: IllegalArgumentException - if the specified objectis not an array (either of reference or primitivecomponent type) |
truncateArray | public static Object truncateArray(Object sourceArray, int index, int len)(Code) | | Returns a truncated copy of sourceArray. len
entries are copied starting at the specified index.
Parameters: sourceArray - the source array Parameters: index - the start index Parameters: len - the truncate length the truncated array throws: IllegalArgumentException - if the specified objectis not an array (either of reference or primitivecomponent type) |
|
|