|
|||||||||
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 java.util.SortedSet |
EmptySortedSet
An immutable, empty SortedSet . |
static java.lang.Class |
ImmutableSetClass
|
Method Summary | ||
---|---|---|
static
|
arrayToSet(T[] array,
boolean assertIfDuplicateElementFound)
Creates a Set from the objects in the given array.
Note, the elements in the array are NOT copied. |
|
static
|
cloneSet(java.util.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(java.util.Set<T> set)
Retrieve a random element from set. |
|
static
|
immutableSet(java.util.Set<? extends T> s)
Returns a version of the Set that is not modifiable If s is null, null will be returned. |
|
static
|
intersect(java.util.Set<? extends T> set1,
java.util.Set<? extends T> set2)
Perform the operation intersect on two given sets. |
|
static
|
intersect(java.util.Set<? extends T> set1,
java.util.Set<? extends T> set2,
java.util.Set<T> result)
Perform the operation intersect on two given sets. |
|
static boolean |
nullOrEmptySet(java.util.Set<?> set)
Determine if a Set is null or empty. |
|
static
|
set()
Constructs an empty optionally type-safe Set . |
|
static
|
set(java.util.Collection<? extends T> source)
Creates new Set with the same contents as unique elements in the given Collection. |
|
static
|
set(int initialCapacity)
Constructs a Set capable of holding a specified number of elements. |
|
static
|
setAddAll(java.util.Collection<T> source)
Returns new Set with all the items in source Collection added to it. |
|
static
|
sortedSet()
Creates an empty SortedSet. |
|
static
|
sortedSet(java.util.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(java.util.SortedSet<? extends T> source)
Creates a new SortedSet with the same content as the given
SortedSet . |
|
static
|
subtract(java.util.Set<? extends T> set1,
java.util.Set<? extends T> set2)
Performs the operation subtract set2 from set1. |
|
static
|
subtract(java.util.Set<? extends T> set1,
java.util.Set<? extends T> set2,
java.util.Set<T> result)
Performs the operation subtract set2 from set1. |
|
static
|
union(java.util.Set<? extends T> set1,
java.util.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 java.util.SortedSet EmptySortedSet
SortedSet
.
public static final java.lang.Class ImmutableSetClass
Method Detail |
---|
public static <T> java.util.Set<T> set()
Set
.
To construct a type-safe Set
:
Set<X> typesafe = SetUtil.set()
Set
:Set raw = SetUtil.set()
public static <T> java.util.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> java.util.Set<T> set(java.util.Collection<? 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 collection
source
java.lang.NullPointerException
- if the specified Set is null.public static <T> java.util.Set<T> cloneSet(java.util.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.Collection)
, since it's guaranteed to work and is probably
just as fast on small sets.
set
- the Set
to clone
public static <T> java.util.Set<T> immutableSet(java.util.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> java.util.SortedSet<T> sortedSet()
Set
:Set<X> typesafe = SetUtil.sortedSet()
Set
:Set raw = SetUtil.set()
SortedSet
public static <T> java.util.SortedSet<T> sortedSet(java.util.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
SortedSet
public static <T> java.util.SortedSet<T> sortedSet(java.util.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 <T> java.util.Set<T> arrayToSet(T[] 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 null
assertIfDuplicateElementFound
- if true
the method
asserts if an duplicated element is found in the input array
otherwise it will be ignored
public static <T> java.util.Set<T> setAddAll(java.util.Collection<T> source)
public static boolean nullOrEmptySet(java.util.Set<?> set)
set
- object to check
public static <T> T getAnyElement(java.util.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> java.util.Set<T> intersect(java.util.Set<? extends T> set1, java.util.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> void intersect(java.util.Set<? extends T> set1, java.util.Set<? extends T> set2, java.util.Set<T> result)
If one of the sets is null or empty, nothing would be added to the result set.
set1
- input setset2
- input setresult
- result setpublic static <T> java.util.Set<T> subtract(java.util.Set<? extends T> set1, java.util.Set<? extends T> set2)
set1
- input setset2
- input set
public static <T> void subtract(java.util.Set<? extends T> set1, java.util.Set<? extends T> set2, java.util.Set<T> result)
set1
- input setset2
- input setresult
- result set (containing the elements of the operation
set1 - set2. If set1 is null or empty, no element would be added
to it. If on the other hand set2 is null or empty, all the elements
in set1 would be added to it).public static <T> java.util.Set<T> union(java.util.Set<? extends T> set1, java.util.Set<? extends T> set2)
set1
- input setset2
- input set
public static <T> java.util.SortedSet<T> emptySortedSet()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |