com.mockrunner.util.common
Class ArrayUtil

java.lang.Object
  extended bycom.mockrunner.util.common.ArrayUtil

public class ArrayUtil
extends java.lang.Object

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 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 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 java.util.List getListFromObjectArray(java.lang.Object[] data)
          Returns a List containing the objects from the specified array.
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

ArrayUtil

public ArrayUtil()
Method Detail

getListFromByteArray

public static java.util.List getListFromByteArray(byte[] data)
Returns a List containing the bytes from the specified array as Byte objects.

Parameters:
data - the byte data
Returns:
the List with the Byte objects

getListFromObjectArray

public static java.util.List getListFromObjectArray(java.lang.Object[] data)
Returns a List containing the objects from the specified array.

Parameters:
data - the data
Returns:
the List with the objects

getByteArrayFromList

public static byte[] getByteArrayFromList(java.util.List data)
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
Returns:
the resulting byte array

getByteArrayFromList

public static byte[] getByteArrayFromList(java.util.List data,
                                          int index)
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
index - the index at which to start
Returns:
the resulting byte array

getByteArrayFromList

public static byte[] getByteArrayFromList(java.util.List data,
                                          int index,
                                          int len)
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
index - the index at which to start
len - the number of bytes
Returns:
the resulting byte array

addBytesToList

public 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. Grows the list if necessary. index must be a valid index in the list.

Parameters:
data - the byte data
list - the List
index - the index at which to start copying

addBytesToList

public 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. Grows the list if necessary. index must be a valid index in the list.

Parameters:
data - the byte data
offset - the offset into the byte array at which to start
len - the number of bytes to copy
list - the List
index - the index at which to start copying

truncateArray

public static java.lang.Object truncateArray(java.lang.Object sourceArray,
                                             int len)
Returns a truncated copy of sourceArray. len entries are copied.

Parameters:
sourceArray - the source array
len - the truncate length
Returns:
the truncated array
Throws:
java.lang.IllegalArgumentException - if the specified object is not an array (either of reference or primitive component type)

truncateArray

public static java.lang.Object truncateArray(java.lang.Object sourceArray,
                                             int index,
                                             int len)
Returns a truncated copy of sourceArray. len entries are copied starting at the specified index.

Parameters:
sourceArray - the source array
index - the start index
len - the truncate length
Returns:
the truncated array
Throws:
java.lang.IllegalArgumentException - if the specified object is not an array (either of reference or primitive component type)

copyArray

public static java.lang.Object copyArray(java.lang.Object array)
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
Returns:
the copy of the array

convertToObjectArray

public static java.lang.Object[] convertToObjectArray(java.lang.Object sourceArray)
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
Returns:
the corresponding object array
Throws:
java.lang.IllegalArgumentException - if the specified object is not an array (either of reference or primitive component type)

convertToArray

public static java.lang.Object convertToArray(java.lang.Object object)
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
Returns:
the corresponding array

indexOf

public static int indexOf(byte[] source,
                          byte[] bytes)
Returns the index of the first occurence of the array bytes in the array source.

Parameters:
source - the array in which to search
bytes - the array to search
Returns:
the index of the first occurence, resp. -1, if source does not contain bytes

indexOf

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.

Parameters:
source - the array in which to search
bytes - the array to search
index - the index where to begin the search
Returns:
the index of the first occurence, resp. -1, if source does not contain bytes

ensureUnique

public 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. 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