|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectariba.util.core.SetUtil
public final class SetUtil
Set Utilities. These are helper functions for dealing with sets.
| Field Summary | |
|---|---|
static SortedSet |
EmptySortedSet
An immutable, empty SortedSet. |
static Class |
ImmutableSetClass
|
| Method Summary | ||
|---|---|---|
static Set |
arrayToSet(Object[] array,
boolean assertIfDuplicateElementFound)
Creates a Set from the objects in the given array.
Note, the elements in the array are NOT copied. |
|
static
|
cloneSet(Set<? extends T> set)
Clones and returns the specified set if the actual
dynamic type of set supports clone (that is, implements
Cloneable and has a publicly available clone()
method.) |
|
static
|
emptySortedSet()
|
|
static
|
getAnyElement(Set<T> set)
Retrieve a random element from set. |
|
static
|
immutableSet(Set<? extends T> s)
Returns a version of the Set that is not modifiable If s is null, null will be returned. |
|
static
|
intersect(Set<? extends T> set1,
Set<? extends T> set2)
Perform the operation intersect on two given sets. |
|
static boolean |
nullOrEmptySet(Set<?> set)
Determine if a Set is null or empty. |
|
static
|
set()
Constructs an empty optionally type-safe Set. |
|
static
|
set(int initialCapacity)
Constructs a Set capable of holding a specified number of elements. |
|
static
|
set(Set<? extends T> source)
Creates new Set with the same contents as the given Set. |
|
static
|
sortedSet()
Creates an empty SortedSet. |
|
static
|
sortedSet(Comparator<? super T> comparator)
Creates an empty SortedSet Given that compX is a Comparator<X>,
compY is a Comparator<Y> (and that Y
extends X) and comp is a raw
Comparator, the following all compile validly. |
|
static
|
sortedSet(SortedSet<? extends T> source)
Creates a new SortedSet with the same content as the given
SortedSet. |
|
static
|
subtract(Set<? extends T> set1,
Set<? extends T> set2)
Performs the operation subtract set2 from set1. |
|
static
|
union(Set<? extends T> set1,
Set<? extends T> set2)
Returns a new Set containing all the elements from two sets |
|
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final SortedSet EmptySortedSet
SortedSet.
public static final Class ImmutableSetClass
| Method Detail |
|---|
public static <T> Set<T> set()
Set.
To construct a type-safe Set:
Set<X> typesafe = SetUtil.set()
Set:Set raw = SetUtil.set()
public static <T> Set<T> set(int initialCapacity)
Set:Set<X> typesafe = SetUtil.set(10)
Set:Set raw = SetUtil.set(10)
initialCapacity - the number of elements this Set
is capable of holding before needing to grow.
public static <T> Set<T> set(Set<? extends T> source)
setOfX is a Set<X>,
setOfY is a Set<Y> (and that Y
extends X) and
raw is a Set, the following
all compile validly. Set<X> typesafe = SetUtil.set(setOfX)
Set<X> typesafe = SetUtil.<X>set(setOfY)
Set<?> unknown = SetUtil.set(setOfX)
Set<X> typesafe = SetUtil.set(raw)
Set raw = SetUtil.set(setOfX)
source - source set
source
NullPointerException - if the specified Set is null.public static <T> Set<T> cloneSet(Set<? extends T> set)
set if the actual
dynamic type of set supports clone (that is, implements
Cloneable and has a publicly available clone()
method.)
If you just want a java.util.Set, then you're better off using
set(java.util.Set), since it's guaranteed to work and is probably
just as fast on small sets.
set - the Set to clone
public static <T> Set<T> immutableSet(Set<? extends T> s)
setOfX is a Set<X>,
setOfY is a Set<Y> (and that Y
extends X) and
raw is a Set, the following
all compile validly. Set<X> typesafe = SetUtil.immutableSet(setOfX)
Set<X> typesafe = SetUtil.<X>immutableSet(setOfY)
Set<?> unknown = SetUtil.immutableSet(setOfX)
Set<X> typesafe = SetUtil.immutableSet(raw)
Set raw = SetUtil.immutableSet(setOfX)
s but is not
modifiablepublic static <T> SortedSet<T> sortedSet()
Set:Set<X> typesafe = SetUtil.sortedSet()
Set:Set raw = SetUtil.set()
SortedSetpublic static <T> SortedSet<T> sortedSet(Comparator<? super T> comparator)
compX is a Comparator<X>,
compY is a Comparator<Y> (and that Y
extends X) and comp is a raw
Comparator, the following all compile validly. Set<X> typesafe = SetUtil.sortedSet(compX)
Set<X> typesafe = SetUtil.<X>sortedSet(compY)
Set<?> unknown = SetUtil.immutableSet(compX)
Set<X> typesafe = SetUtil.immutableSet(comp)
Set raw = SetUtil.immutableSet(compX)
comparator - the non-null comparator that will be used to
sort the Set
SortedSetpublic static <T> SortedSet<T> sortedSet(SortedSet<? extends T> source)
SortedSet with the same content as the given
SortedSet.
Given that setOfX is a SortedSet<X>,
setOfY is a SortedSet<Y> (and that Y
extends X) and raw is a raw
SortedSet, the following all compile validly. SortedSet<X> typesafe = SetUtil.sortedSet(setOfX)
SortedSet<X> typesafe = SetUtil.<X>sortedSet(setOfY)
SortedSet<?> unknown = SetUtil.sortedSet(setOfX)
SortedSet<X> typesafe = SetUtil.sortedSet(raw)
SortedSet raw = SetUtil.sortedSet(setOfX)
source - the non-null sorted set based on the given SortedSet
SortedSet
public static Set arrayToSet(Object[] array,
boolean assertIfDuplicateElementFound)
Set from the objects in the given array.
Note, the elements in the array are NOT copied.
array - to use as the initial contents of the Set; may
not be nullassertIfDuplicateElementFound - if true the method
asserts if an duplicated element is found in the input array
otherwise it will be ignored
public static boolean nullOrEmptySet(Set<?> set)
set - object to check
public static <T> T getAnyElement(Set<T> set)
Note that the set can contain null element (at most one).
set - object from which to retrieve an element
set if it's not null or empty,
assert otherwise.
public static <T> Set<T> intersect(Set<? extends T> set1,
Set<? extends T> set2)
If one of the sets is null or empty the method returns an empty set.
set1 - input setset2 - input set
public static <T> Set<T> subtract(Set<? extends T> set1,
Set<? extends T> set2)
set1 - input setset2 - input set
public static <T> Set<T> union(Set<? extends T> set1,
Set<? extends T> set2)
set1 - input setset2 - input set
public static <T> SortedSet<T> emptySortedSet()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||