import java.lang.reflect.Array;
import java.util.Enumeration;
import java.util.Hashtable;
/*********************************************************************
* Array manipulation for Java 1.1+.
*
*
* Java 1.1 compatible.
*
*
* @see
* ArrayLib2
*
* @version
* 2003-04-07
* @since
* 2001-04-06
* @author
* David Wallace Croft*/
public class Util{
/*********************************************************************
* Creates a new subarray from a larger array.
*
*
* To avoid unnecessary object creation, this method returns the
* original array argument if the requested subarray length is the same
* and the startIndex is 0. That is to say, if the method arguments
* are such that the algorithm would have created a shallow clone, the
* original array is returned instead.
*
*
* @throws NullArgumentException
*
* If objectArray is null.
*
* @throws ArrayIndexOutOfBoundsException
*
* If startIndex, length, or startIndex + length are out of range.
*
* @return
*
* Returns an array with the same component type as the old array.
*********************************************************************/
public static Object [ ] subArray (
Object [ ] objectArray,
int startIndex,
int length )
//////////////////////////////////////////////////////////////////////
{
if ( ( startIndex == 0 )
&& ( length == objectArray.length ) )
{
return objectArray;
}
Object [ ] newArray = ( Object [ ] ) Array.newInstance (
objectArray.getClass ( ).getComponentType ( ), length );
System.arraycopy ( objectArray, startIndex, newArray, 0, length );
return newArray;
}
}