org.jutil.java.collections
Class Arrays

java.lang.Object
  |
  +--org.jutil.java.collections.Arrays

public abstract class Arrays
extends java.lang.Object

A class with static methods for arrays

Version:
$Revision: 1.8 $
Author:
Marko van Dooren, Jan Dockx

Field Summary
static java.lang.String CVS_REVISION
           
 
Constructor Summary
Arrays()
           
 
Method Summary
static int[] getArrayDimensions(java.lang.Object[] array)
          // may not be null.
pre array != null;
Return the dimensions of the given array
static java.lang.Class getArrayType(java.lang.Object array)
          // may not be null.
pre array != null;
// must be an array.
pre array.getClass().isArray();
Return the type of an array
static boolean isObjectArray(java.lang.Class clazz)
          // False is is null.
post (clazz == null) ==> (\result == false);
//Return true if is an array of objects.
post \result == clazz.isArray() &&
(clazz.getName().indexOf("[L") != -1);
Check whether the given class is an array of objects
static boolean isObjectArray(java.lang.Object object)
          // False is is null.
post (object == null) ==> (\result == false);
// True if is an array of objects, false otherwise.
post isObjectArray(object.getClass());
Check whether the given object is an array of objects
static java.lang.Object[] newArray(java.lang.Object[] array)
          // may not be null
pre array != null;

// The returned array is not null
post \result != null;
// The returned array has the same type as .
post getArrayType(\result) == getArrayType(array);
// The returned array has the same dimensions as .
post (\forall int i; i >= 0 && i < getArrayDimensions(array).length;
getArrayDimensions(\result)[i] == getArrayDimensions(array)[i]);
Return a new array of the same type and dimension as the given array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CVS_REVISION

public static final java.lang.String CVS_REVISION
Constructor Detail

Arrays

public Arrays()
Method Detail

newArray

public static java.lang.Object[] newArray(java.lang.Object[] array)
                                   throws ZeroDimensionException
// may not be null
pre array != null;

// The returned array is not null
post \result != null;
// The returned array has the same type as .
post getArrayType(\result) == getArrayType(array);
// The returned array has the same dimensions as .
post (\forall int i; i >= 0 && i < getArrayDimensions(array).length;
getArrayDimensions(\result)[i] == getArrayDimensions(array)[i]);
Return a new array of the same type and dimension as the given array.
Parameters:
array - an array that will be "cloned"

getArrayDimensions

public static int[] getArrayDimensions(java.lang.Object[] array)
                                throws ZeroDimensionException
// may not be null.
pre array != null;
Return the dimensions of the given array
Parameters:
array - The array of which the dimensions are requested
Returns:
The dimensions of the given array. The size of the i-th dimension will be at the (i-1)-th position in the returned array.

getArrayType

public static java.lang.Class getArrayType(java.lang.Object array)
// may not be null.
pre array != null;
// must be an array.
pre array.getClass().isArray();
Return the type of an array
Parameters:
array - The array of which the type must be determined
Returns:
The type of the given array. In case of a primitive type, the wrapper class will be returned

isObjectArray

public static boolean isObjectArray(java.lang.Class clazz)
// False is is null.
post (clazz == null) ==> (\result == false);
//Return true if is an array of objects.
post \result == clazz.isArray() &&
(clazz.getName().indexOf("[L") != -1);
Check whether the given class is an array of objects
Returns:
clazz The Class to be checked.

isObjectArray

public static boolean isObjectArray(java.lang.Object object)
// False is is null.
post (object == null) ==> (\result == false);
// True if is an array of objects, false otherwise.
post isObjectArray(object.getClass());
Check whether the given object is an array of objects
Parameters:
clazz - The object to be checked Result True if the given object is an array of objects.