rebuild.collections
Class CollectionUtilities

java.lang.Object
  extended by rebuild.collections.CollectionUtilities

public final class CollectionUtilities
extends java.lang.Object

Various utilities and functions related to collections.

Since:
BBX 1.2.0

Method Summary
static boolean equals(java.util.Hashtable main, java.util.Hashtable comp)
          Perform a shallow comparison of two Hashtables to determine if they are equal.
static boolean equals(java.util.Vector main, java.util.Vector comp)
          Perform a shallow comparison of two Vectors to determine if they are equal.
static void putAll(java.util.Hashtable dest, java.util.Hashtable source)
          Copies all of the mappings from the specified table to another table.
static void putAll(java.util.Vector dest, java.util.Vector source)
          Copies all of the elements from the specified Vector to another Vector.
static java.util.Hashtable readonlyTable(java.util.Hashtable table)
          Returns a wrapper on the specified table which has readonly access to the table.
static java.util.Vector readonlyVector(java.util.Vector vector)
          Returns a wrapper on the specified Vector which has readonly access to the Vector.
static java.util.Hashtable synchronizedTable(java.util.Hashtable table)
          Returns a synchronized (thread-safe) table backed by the specified table.
static java.util.Vector synchronizedVector(java.util.Vector vector)
          Returns a synchronized (thread-safe) Vector backed by the specified Vector.
static java.lang.Object[] toArray(java.util.Vector vect)
          Convert a Vector to an array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toArray

public static java.lang.Object[] toArray(java.util.Vector vect)
Convert a Vector to an array.

Parameters:
vect - The Vector to convert to an array.
Returns:
If vect is null then null is returned. Else an array is returned of the items in vect.

equals

public static boolean equals(java.util.Vector main,
                             java.util.Vector comp)
Perform a shallow comparison of two Vectors to determine if they are equal.

Parameters:
main - The first Vector for comparison.
comp - The second Vector to compare to the main Vector.
Returns:
true if the vectors are the same, false if otherwise.

equals

public static boolean equals(java.util.Hashtable main,
                             java.util.Hashtable comp)
Perform a shallow comparison of two Hashtables to determine if they are equal.

Parameters:
main - The first Hashtable for comparison.
comp - The second Hashtable to compare to the main Hashtable.
Returns:
true if the tables are the same, false if otherwise.

putAll

public static void putAll(java.util.Hashtable dest,
                          java.util.Hashtable source)
Copies all of the mappings from the specified table to another table. These mappings will replace any mappings that this table had for any of the keys currently in the specified table.

Parameters:
dest - the table to store the elements in
source - mappings to be stored in the dest table
Throws:
java.lang.NullPointerException - if the specified tables are null

putAll

public static void putAll(java.util.Vector dest,
                          java.util.Vector source)
Copies all of the elements from the specified Vector to another Vector.

Parameters:
dest - the Vector to store the elements in
source - elements to be stored in the dest Vector
Throws:
java.lang.NullPointerException - if the specified Vectors are null

synchronizedVector

public static java.util.Vector synchronizedVector(java.util.Vector vector)
Returns a synchronized (thread-safe) Vector backed by the specified Vector. In order to guarantee serial access, it is critical that all access to the backing Vector is accomplished through the returned Vector.

It is imperative that the user manually synchronize on the returned Vector when enumerating over it:

 Vector vector = CollectionUtilities.synchronizedVector(new Vector());
 ...
 synchronized (vector) {
        Enumeration e = vector.elements(); // Must be in synchronized block
        while (e.hasMoreElements())
                foo(e.nextElement());
 }
 

Failure to follow this advice may result in non-deterministic behavior.

Parameters:
vector - the Vector to wrap in a synchronized Vector.
Returns:
a synchronized Vector.

synchronizedTable

public static java.util.Hashtable synchronizedTable(java.util.Hashtable table)
Returns a synchronized (thread-safe) table backed by the specified table. In order to guarantee serial access, it is critical that all access to the backing table is accomplished through the returned table.

It is imperative that the user manually synchronize on the returned table when enumerating over it:

 Hashtable table = CollectionUtilities.synchronizedTable(new Hashtable());
 ...
 synchronized (table) {
        Enumeration e = table.elements(); // Must be in synchronized block
        while (e.hasMoreElements())
                foo(e.nextElement());
        ...
        Enumeration k = table.keys(); // Must be in synchronized block
        while (k.hasMoreElements())
                foo(k.nextElement());
 }
 

Failure to follow this advice may result in non-deterministic behavior.

Parameters:
table - The table to make synchronized.
Returns:
The synchronized table.

readonlyVector

public static java.util.Vector readonlyVector(java.util.Vector vector)
Returns a wrapper on the specified Vector which has readonly access to the Vector.

Parameters:
vector - the Vector to wrap in a readonly Vector.
Returns:
a readonly Vector.

readonlyTable

public static java.util.Hashtable readonlyTable(java.util.Hashtable table)
Returns a wrapper on the specified table which has readonly access to the table.

Parameters:
table - the table to wrap in a readonly table.
Returns:
a readonly Vector.