Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.sun.javatest.util
Class DynamicArray

    java.lang.Object
      com.sun.javatest.util.DynamicArray

    public final class DynamicArray

extends java.lang.Object

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

### DynamicArray

    public DynamicArray()

Method Detail

### append

    public static java.lang.Object[] append(java.lang.Object[] oldArr,
                                            java.lang.Object newObj)

  Append an object to the end of the array.

  Parameters:
    `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.
  Returns:
    A new array with the object appended to it.
  Throws:
    `java.lang.IllegalArgumentException` - If newObj is null.
    `java.lang.ArrayStoreException` - If there is a type mismatch between oldArr and newObj.

### append

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

  Parameters:
    `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.
  Returns:
    A new array with the object appended to it.
  Throws:
    `java.lang.IllegalArgumentException` - If newObj is null.
    `java.lang.ArrayStoreException` - If there is a type mismatch between oldArr and newObj.

### join

    public static java.lang.Object[] join(java.lang.Object[] array1,
                                          java.lang.Object[] array2)

  Join two arrays.

  Parameters:
    `array1` - The first array to be joined.
    `array2` - The second array to be joined.
  Returns:
    If either argument is null, the result is the other argument; otherwise, the result is a new array, whose element type is taken from the first array, containing the elements of the first array, followed by the elements of the second array.

### insert

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

  Parameters:
    `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.
  Returns:
    A new array with the object inserted into it at the specified location.

### remove

    public static java.lang.Object[] remove(java.lang.Object[] oldArr,
                                            int index)

  Remove the object at the specified index. The new array type is determined by the type of element 0 in the original array.

  Parameters:
    `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.
  Returns:
    An array of the same type as the original array (element 0), without the given index. Zero length array if the last element is removed.
  Throws:
    `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.

### remove

    public static java.lang.Object[] remove(java.lang.Object[] oldArr,
                                            java.lang.Object victim)

  Remove the object from the array. If the object is not found, the original array is returned unchanged. The first instance of the target is removed.

  Parameters:
    `oldArr` - The array to remove from.
    `victim` - The object to remove from the array. May be null.
  Returns:
    Zero length array if the last element is removed.

### find

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

  Parameters:
    `arr` - The data to search; should not be null.
    `target` - The reference to search for; can be null.
  Returns:
    The array index of the target.

### getArrayClass

    protected static java.lang.Class getArrayClass(java.lang.Object[] arr)

  Get the type of objects that the array is declared to hold.

  Parameters:
    `arr` - The array to examine.
  Returns:
    The class of objects that the given array can hold.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.