|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.collections.SetUtils
public class SetUtils
Provides utility methods and decorators for
Set
and SortedSet
instances.
Field Summary | |
---|---|
static Set |
EMPTY_SET
An empty unmodifiable set. |
static SortedSet |
EMPTY_SORTED_SET
An empty unmodifiable sorted set. |
Constructor Summary | |
---|---|
SetUtils()
SetUtils should not normally be instantiated. |
Method Summary | ||
---|---|---|
static int |
hashCodeForSet(Collection set)
Generates a hash code using the algorithm specified in Set.hashCode() . |
|
static boolean |
isEqualSet(Collection set1,
Collection set2)
Tests two sets for equality as per the equals() contract
in Set.equals(java.lang.Object) . |
|
static
|
orderedSet(Set<E> set)
Returns a set that maintains the order of elements that are added backed by the given set. |
|
static
|
predicatedSet(Set<E> set,
Predicate<? super E> predicate)
Returns a predicated (validating) set backed by the given set. |
|
static
|
predicatedSortedSet(SortedSet<E> set,
Predicate<? super E> predicate)
Returns a predicated (validating) sorted set backed by the given sorted set. |
|
static
|
synchronizedSet(Set<E> set)
Returns a synchronized set backed by the given set. |
|
static
|
synchronizedSortedSet(SortedSet<E> set)
Returns a synchronized sorted set backed by the given sorted set. |
|
static
|
transformedSet(Set<I> set,
Transformer<? super I,? extends O> transformer)
Returns a transformed set backed by the given set. |
|
static
|
transformedSortedSet(SortedSet<I> set,
Transformer<? super I,? extends O> transformer)
Returns a transformed sorted set backed by the given set. |
|
static
|
typedSet(Set<E> set,
Class<E> type)
Deprecated. Made obsolete by Java 1.5 generics. |
|
static
|
typedSortedSet(SortedSet<E> set,
Class<E> type)
Deprecated. made obsolete by Java 1.5 generics. |
|
static
|
unmodifiableSet(Set<E> set)
Returns an unmodifiable set backed by the given set. |
|
static
|
unmodifiableSortedSet(SortedSet<E> set)
Returns an unmodifiable sorted set backed by the given sorted set. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Set EMPTY_SET
Collections
implementation
and is provided for completeness.
public static final SortedSet EMPTY_SORTED_SET
Constructor Detail |
---|
public SetUtils()
SetUtils
should not normally be instantiated.
Method Detail |
---|
public static boolean isEqualSet(Collection set1, Collection set2)
equals()
contract
in 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).
set1
- the first set, may be nullset2
- the second set, may be null
Set
public static int hashCodeForSet(Collection set)
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.
set
- the set to calculate the hash code for, may be null
Set.hashCode()
public static <E> Set<E> synchronizedSet(Set<E> set)
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.
set
- the set to synchronize, must not be null
IllegalArgumentException
- if the set is nullpublic static <E> Set<E> unmodifiableSet(Set<E> set)
set
- the set to make unmodifiable, must not be null
IllegalArgumentException
- if the set is nullpublic static <E> Set<E> predicatedSet(Set<E> set, Predicate<? super E> predicate)
set
- the set to predicate, must not be nullpredicate
- the predicate for the set, must not be null
IllegalArgumentException
- if the Set or Predicate is nullpublic static <E> Set<E> typedSet(Set<E> set, Class<E> type)
set
- the set to limit to a specific type, must not be nulltype
- the type of objects which may be added to the set
public static <I,O> Set<O> transformedSet(Set<I> set, Transformer<? super I,? extends O> transformer)
set
- the set to transform, must not be nulltransformer
- the transformer for the set, must not be null
IllegalArgumentException
- if the Set or Transformer is nullpublic static <E> Set<E> orderedSet(Set<E> set)
set
- the set to order, must not be null
IllegalArgumentException
- if the Set is nullpublic static <E> SortedSet<E> synchronizedSortedSet(SortedSet<E> set)
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.
set
- the sorted set to synchronize, must not be null
IllegalArgumentException
- if the set is nullpublic static <E> SortedSet<E> unmodifiableSortedSet(SortedSet<E> set)
set
- the sorted set to make unmodifiable, must not be null
IllegalArgumentException
- if the set is nullpublic static <E> SortedSet<E> predicatedSortedSet(SortedSet<E> set, Predicate<? super E> predicate)
set
- the sorted set to predicate, must not be nullpredicate
- the predicate for the sorted set, must not be null
IllegalArgumentException
- if the Set or Predicate is nullpublic static <E> SortedSet<E> typedSortedSet(SortedSet<E> set, Class<E> type)
set
- the set to limit to a specific type, must not be nulltype
- the type of objects which may be added to the set
public static <I,O> SortedSet<O> transformedSortedSet(SortedSet<I> set, Transformer<? super I,? extends O> transformer)
set
- the set to transform, must not be nulltransformer
- the transformer for the set, must not be null
IllegalArgumentException
- if the Set or Transformer is null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |