|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.javatest.util.DynamicArray
public final class DynamicArray
A class that manipulates arrays of Objects (no primitives). Currently, you can remove any element and have the array shrink itself, and you can append an element and have it expand. Note: You should either initialize array variables to a zero length array or use the append method that accepts the Class argument to prevent array storage exceptions. This is an issue when this class is forced to create a new array of unknown type and determine the type from the item being appended.
Constructor Summary | |
---|---|
DynamicArray()
|
Method Summary | |
---|---|
static java.lang.Object[] |
append(java.lang.Object[] oldArr,
java.lang.Object newObj)
Append an object to the end of the array. |
static java.lang.Object[] |
append(java.lang.Object[] oldArr,
java.lang.Object newObj,
java.lang.Class arrayClass)
Append an object to the end of the array. |
static int |
find(java.lang.Object[] arr,
java.lang.Object target)
Find the first index of the object that is equal (reference) to the target. |
protected static java.lang.Class |
getArrayClass(java.lang.Object[] arr)
Get the type of objects that the array is declared to hold. |
static java.lang.Object[] |
insert(java.lang.Object[] oldArr,
java.lang.Object newObj,
int location)
Insert an object into the array at the specified index. |
static java.lang.Object[] |
join(java.lang.Object[] array1,
java.lang.Object[] array2)
Join two arrays. |
static java.lang.Object[] |
remove(java.lang.Object[] oldArr,
int index)
Remove the object at the specified index. |
static java.lang.Object[] |
remove(java.lang.Object[] oldArr,
java.lang.Object victim)
Remove the object from the array. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DynamicArray()
Method Detail |
---|
public static java.lang.Object[] append(java.lang.Object[] oldArr, java.lang.Object newObj)
oldArr
- The original array which we are appending to. May be zero length or null.newObj
- The new value to append to the oldArr. Null is not a legal value.
java.lang.IllegalArgumentException
- If newObj is null.
java.lang.ArrayStoreException
- If there is a type mismatch between oldArr and newObj.public static java.lang.Object[] append(java.lang.Object[] oldArr, java.lang.Object newObj, java.lang.Class arrayClass)
oldArr
- The original array which we are appending to. May be zero length or null.newObj
- The new value to append to the oldArr.arrayClass
- If the oldArr is null, a new array of arrayClass will be created.
If arrayClass is null, the type of newObj will be used to create the array.
java.lang.IllegalArgumentException
- If newObj is null.
java.lang.ArrayStoreException
- If there is a type mismatch between oldArr and newObj.public static java.lang.Object[] join(java.lang.Object[] array1, java.lang.Object[] array2)
array1
- The first array to be joined.array2
- The second array to be joined.
public static java.lang.Object[] insert(java.lang.Object[] oldArr, java.lang.Object newObj, int location)
oldArr
- The array to insert into. May be null, in which case a new array
will be created using the type of newObj
.newObj
- The object to insert.location
- The index at which to insert the item. An exception will occur
if the location in out of range. This location can be equal to
oldArr.length
, in which case this becomes an append
operation.
public static java.lang.Object[] remove(java.lang.Object[] oldArr, int index)
oldArr
- The original array which we are removing from. May not be
null or zero length.index
- The index to remove from oldArr
. Exception
will be thrown if it is out of range.
java.lang.IllegalArgumentException
- Will occur if the given index is out of range,
or the given array is null.
java.lang.NullPointerException
- May occur if the source array has null
values, particularly in the first array position.
java.lang.ArrayStoreException
- May occur if all the objects in the
array do not match.public static java.lang.Object[] remove(java.lang.Object[] oldArr, java.lang.Object victim)
oldArr
- The array to remove from.victim
- The object to remove from the array. May be null.
public static int find(java.lang.Object[] arr, java.lang.Object target)
arr
- The data to search; should not be null.target
- The reference to search for; can be null.
protected static java.lang.Class getArrayClass(java.lang.Object[] arr)
arr
- The array to examine.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |