com.croftsoft.core.util
Class ArrayLib

java.lang.Object
  extended by com.croftsoft.core.util.ArrayLib

public final class ArrayLib
extends Object

Array manipulation for Java 1.1+.

Java 1.1 compatible.

Since:
2001-04-06
Version:
2003-04-07
See Also:
ArrayLib2
Author:
David Wallace Croft

Method Summary
static int[] append(int[] intArray, int i)
          Appends an integer to an integer array.
static Object[] append(Object[] oldArray, Object o)
          Appends an Object to an Object array.
static boolean contains(Object[] objectArray, Object o)
          Determines if an array contains an equivalent object.
static boolean equals(Object[] objectArray1, Object[] objectArray2)
          Compares two object arrays for equivalency.
static int[] insert(int[] intArray, int i, int index)
          Inserts an integer into an integer array at the index position.
static Object[] insert(Object[] objectArray, Object o, int index)
          Inserts an Object into an Object array at the index position.
static void main(String[] args)
           
static Object[] prepend(Object[] oldArray, Object o)
          Prepends an Object to an Object array.
static void println(Object[] objectArray)
          Prints each array element to the standard output.
static Object[] remove(Object[] oldArray, int index)
          Removes an Object from an Object array.
static Object[] remove(Object[] oldArray, Object o)
           
static Object[] removeDuplicates(Object[] array)
          Removes duplicate elements from the array.
static Object[] subArray(Object[] objectArray, int startIndex)
          Creates a new subarray from a larger array.
static Object[] subArray(Object[] objectArray, int startIndex, int length)
          Creates a new subarray from a larger array.
static boolean test(String[] args)
           
static Object[] union(Object[] array1, Object[] array2)
          Returns the union of the arrays, discarding duplicates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

main

public static void main(String[] args)

test

public static boolean test(String[] args)

append

public static Object[] append(Object[] oldArray,
                              Object o)
Appends an Object to an Object array.

Example:

 String [ ]  stringArray
   = ( String [ ] ) ArrayLib.append ( new String [ ] { }, "" );
 

Returns:
Returns a new array with the same component type as the old array.
Throws:
NullArgumentException - If either argument is null.

append

public static int[] append(int[] intArray,
                           int i)
Appends an integer to an integer array.

Parameters:
intArray - May be null.

contains

public static boolean contains(Object[] objectArray,
                               Object o)
Determines if an array contains an equivalent object.

Parameters:
objectArray - May not be null.
o - If null, function will return true if an array element is null.

equals

public static boolean equals(Object[] objectArray1,
                             Object[] objectArray2)
Compares two object arrays for equivalency.

A Java 1.1 version of the Java 1.2 method java.util.Arrays.equals().


insert

public static int[] insert(int[] intArray,
                           int i,
                           int index)
Inserts an integer into an integer array at the index position.


insert

public static Object[] insert(Object[] objectArray,
                              Object o,
                              int index)
Inserts an Object into an Object array at the index position.

Example:

 String [ ]  stringArray
   = ( String [ ] ) ArrayLib.insert ( new String [ ] { }, "", 0 );
 

Returns:
Returns a new array with the same component type as the old array.
Throws:
NullArgumentException - If objectArray or o is null.
IndexOutOfBoundsException - If index < 0 or index > objectArray.length.

prepend

public static Object[] prepend(Object[] oldArray,
                               Object o)
Prepends an Object to an Object array.

Example:

 String [ ]  stringArray
   = ( String [ ] ) ArrayLib.prepend ( new String [ ] { }, "" );
 

Returns:
Returns a new array with the same component type as the old array.
Throws:
NullArgumentException - If either argument is null.

println

public static void println(Object[] objectArray)
Prints each array element to the standard output.


remove

public static Object[] remove(Object[] oldArray,
                              int index)
Removes an Object from an Object array.

Example:

 String [ ]  stringArray
   = ( String [ ] ) remove ( new String [ ] { "" }, 0 );
 

Returns:
Returns a new array with the same component type as the old array.
Throws:
NullArgumentException - If oldArray is null.
ArrayIndexOutOfBoundsException - If index < 0 or index >= oldArray.length.

remove

public static Object[] remove(Object[] oldArray,
                              Object o)

removeDuplicates

public static Object[] removeDuplicates(Object[] array)
Removes duplicate elements from the array.


subArray

public static Object[] subArray(Object[] objectArray,
                                int startIndex,
                                int length)
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.

Returns:
Returns an array with the same component type as the old array.
Throws:
NullArgumentException - If objectArray is null.
ArrayIndexOutOfBoundsException - If startIndex, length, or startIndex + length are out of range.

subArray

public static Object[] subArray(Object[] objectArray,
                                int startIndex)
Creates a new subarray from a larger array.

 return subArray (
   objectArray, startIndex, objectArray.length - startIndex );
 


union

public static Object[] union(Object[] array1,
                             Object[] array2)
Returns the union of the arrays, discarding duplicates.


CroftSoft Javadoc

CroftSoft Core Javadoc (2008-09-28 20:58:02)