com.ca.commons.cbutil
Class CBArray

java.lang.Object
  |
  +--com.ca.commons.cbutil.CBArray

public class CBArray
extends java.lang.Object

Utility class for array operations. Not particularly fast - most operations implemented as linear searches. XXX most of these may be redundant - see java 'util.Array' class...


Constructor Summary
CBArray()
           
 
Method Summary
static java.util.Enumeration arrayToEnumeration(java.lang.Object[] o)
           
static boolean contains(java.lang.Object[] array, java.lang.Object o)
          Returns true if the passed object is not null, and is equal to (at least one) element of the array.
static java.lang.Object[] difference(java.lang.Object[] a, java.lang.Object[] b)
          Returns the list of elements that appear in a but not in b.
static java.lang.Object[] enumerationToArray(java.util.Enumeration e)
           
static java.lang.Object[] intersection(java.lang.Object[] a, java.lang.Object[] b)
          Returns the list of elements that appear in both of the passed arrays.
static boolean isOrderedEqual(java.lang.Object[] a, java.lang.Object[] b)
          Returns true if arrays have the same elements, in the same order.
static boolean isUnorderedEqual(java.lang.Object[] a, java.lang.Object[] b)
          Returns true if arrays have the same elements, in any order.
static void print(java.lang.Object[] array)
          Prints an array, using 'toString()' on each component.
static java.lang.Object[] trimNulls(java.lang.Object[] o)
           
static java.lang.Object[] union(java.lang.Object[] a, java.lang.Object[] b)
          Returns the list of elements that appear at least once in one of the passed arrays.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CBArray

public CBArray()
Method Detail

union

public static java.lang.Object[] union(java.lang.Object[] a,
                                       java.lang.Object[] b)
Returns the list of elements that appear at least once in one of the passed arrays. An element appearing in both arrays only appears once in the final array. Behaviour is undefined if Elements are repeated within an array; they may be trimmed, or not.

Parameters:
a - the first array to unionise
b - the second array to unionise.
Returns:
the resultant union.

difference

public static java.lang.Object[] difference(java.lang.Object[] a,
                                            java.lang.Object[] b)
Returns the list of elements that appear in a but not in b. Behaviour is undefined if Elements are repeated within an array; they may be trimmed, or not.

Parameters:
a - the primary array
b - the array to 'subtract'.
Returns:
the resultant difference.

intersection

public static java.lang.Object[] intersection(java.lang.Object[] a,
                                              java.lang.Object[] b)
Returns the list of elements that appear in both of the passed arrays. An element appearing in both arrays only appears once in the final array. Behaviour is undefined if Elements are repeated within an array; they may be trimmed, or not.

Parameters:
a - the first array to unionise
b - the second array to unionise.
Returns:
the resultant union.

isOrderedEqual

public static boolean isOrderedEqual(java.lang.Object[] a,
                                     java.lang.Object[] b)
Returns true if arrays have the same elements, in the same order.


isUnorderedEqual

public static boolean isUnorderedEqual(java.lang.Object[] a,
                                       java.lang.Object[] b)
Returns true if arrays have the same elements, in any order. Does *not* check for different numbers of repeating elements - i.e. {A,A,B} == {A,B,B} is true.


contains

public static boolean contains(java.lang.Object[] array,
                               java.lang.Object o)
Returns true if the passed object is not null, and is equal to (at least one) element of the array.

Parameters:
array - the array that may contain the object.
o - the object to check the existence of.

print

public static void print(java.lang.Object[] array)
Prints an array, using 'toString()' on each component.


enumerationToArray

public static java.lang.Object[] enumerationToArray(java.util.Enumeration e)

arrayToEnumeration

public static java.util.Enumeration arrayToEnumeration(java.lang.Object[] o)

trimNulls

public static java.lang.Object[] trimNulls(java.lang.Object[] o)