Home » commons-beanutils-1.8.3-src » org.apache.commons » collections » [javadoc | source]
org.apache.commons.collections
public class: SetUtils [javadoc | source]
java.lang.Object
   org.apache.commons.collections.SetUtils
Provides utility methods and decorators for Set and SortedSet instances.
Field Summary
public static final  Set EMPTY_SET    An empty unmodifiable set. This uses the Collections implementation and is provided for completeness. 
public static final  SortedSet EMPTY_SORTED_SET    An empty unmodifiable sorted set. This is not provided in the JDK. 
Constructor:
 public SetUtils() 
Method from org.apache.commons.collections.SetUtils Summary:
hashCodeForSet,   isEqualSet,   orderedSet,   predicatedSet,   predicatedSortedSet,   synchronizedSet,   synchronizedSortedSet,   transformedSet,   transformedSortedSet,   typedSet,   typedSortedSet,   unmodifiableSet,   unmodifiableSortedSet
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.commons.collections.SetUtils Detail:
 public static int hashCodeForSet(Collection set) 
    Generates a hash code using the algorithm specified in java.util.Set#hashCode() .

    This method is useful for implementing Set when you cannot extend AbstractSet. The method takes Collection instances to enable other collection types to use the Set implementation algorithm.

 public static boolean isEqualSet(Collection set1,
    Collection set2) 
    Tests two sets for equality as per the equals() contract in java.util.Set#equals(java.lang.Object) .

    This method is useful for implementing Set when you cannot extend AbstractSet. The method takes Collection instances to enable other collection types to use the Set implementation algorithm.

    The relevant text (slightly paraphrased as this is a static method) is:

    Two sets are considered equal if they have the same size, and every member of the first set is contained in the second. This ensures that the equals method works properly across different implementations of the Set interface.

    This implementation first checks if the two sets are the same object: if so it returns true. Then, it checks if the two sets are identical in size; if not, it returns false. If so, it returns a.containsAll((Collection) b).

 public static Set orderedSet(Set set) 
    Returns a set that maintains the order of elements that are added backed by the given set.

    If an element is added twice, the order is determined by the first add. The order is observed through the iterator or toArray.

 public static Set predicatedSet(Set set,
    Predicate predicate) 
    Returns a predicated (validating) set backed by the given set.

    Only objects that pass the test in the given predicate can be added to the set. Trying to add an invalid object results in an IllegalArgumentException. It is important not to use the original set after invoking this method, as it is a backdoor for adding invalid objects.

 public static SortedSet predicatedSortedSet(SortedSet set,
    Predicate predicate) 
    Returns a predicated (validating) sorted set backed by the given sorted set.

    Only objects that pass the test in the given predicate can be added to the set. Trying to add an invalid object results in an IllegalArgumentException. It is important not to use the original set after invoking this method, as it is a backdoor for adding invalid objects.

 public static Set synchronizedSet(Set set) 
    Returns a synchronized set backed by the given set.

    You must manually synchronize on the returned buffer's iterator to avoid non-deterministic behavior:

    Set s = SetUtils.synchronizedSet(mySet);
    synchronized (s) {
        Iterator i = s.iterator();
        while (i.hasNext()) {
            process (i.next());
        }
    }
    
    This method uses the implementation in the decorators subpackage.
 public static SortedSet synchronizedSortedSet(SortedSet set) 
    Returns a synchronized sorted set backed by the given sorted set.

    You must manually synchronize on the returned buffer's iterator to avoid non-deterministic behavior:

    Set s = SetUtils.synchronizedSet(mySet);
    synchronized (s) {
        Iterator i = s.iterator();
        while (i.hasNext()) {
            process (i.next());
        }
    }
    
    This method uses the implementation in the decorators subpackage.
 public static Set transformedSet(Set set,
    Transformer transformer) 
    Returns a transformed set backed by the given set.

    Each object is passed through the transformer as it is added to the Set. It is important not to use the original set after invoking this method, as it is a backdoor for adding untransformed objects.

 public static SortedSet transformedSortedSet(SortedSet set,
    Transformer transformer) 
    Returns a transformed sorted set backed by the given set.

    Each object is passed through the transformer as it is added to the Set. It is important not to use the original set after invoking this method, as it is a backdoor for adding untransformed objects.

 public static Set typedSet(Set set,
    Class type) 
    Returns a typed set backed by the given set.

    Only objects of the specified type can be added to the set.

 public static SortedSet typedSortedSet(SortedSet set,
    Class type) 
    Returns a typed sorted set backed by the given set.

    Only objects of the specified type can be added to the set.

 public static Set unmodifiableSet(Set set) 
    Returns an unmodifiable set backed by the given set.

    This method uses the implementation in the decorators subpackage.

 public static SortedSet unmodifiableSortedSet(SortedSet set) 
    Returns an unmodifiable sorted set backed by the given sorted set.

    This method uses the implementation in the decorators subpackage.