Package org.drasyl.util
Class SetUtil
java.lang.Object
org.drasyl.util.SetUtil
Utility class for operations on
Sets.-
Method Summary
Modifier and TypeMethodDescriptioncartesianProduct(Set<A> a, Set<B> b) Returns the cartesian product of the two setsaandb.static <E> Set<E>difference(Set<E> a, E... b) Returns a set containing all elements from setathat are notb.static <E> Set<E>difference(Set<E> a, Collection<E> b) Returns a set containing all elements from setathat are not in setb.static <E> EfirstElement(Set<E> set) Returns the first element from setset.static <E> Set<E>firstElements(Set<E> set, int n) Returns the firstnelements from setset.static <E> Set<E>Returns a set containing all elements fromaand the elementb.static <E> Set<E>Returns a set containing all elements from setaand setb.static <E> EnthElement(Set<E> set, int n) Returns then-th element from setset.
-
Method Details
-
merge
Returns a set containing all elements from setaand setb. If there are duplicates in both sets, the elements from the setaare favored.- Type Parameters:
E- theSet's element type- Parameters:
a- set ab- set b- Returns:
- a
Setcontaining the specified elements
-
merge
Returns a set containing all elements fromaand the elementb.bis ignored if an equal element is already contained in the seta.- Type Parameters:
E- theSet's element type- Parameters:
a- set ab- set b- Returns:
- a
Setcontaining the specified elements
-
difference
Returns a set containing all elements from setathat are not in setb.- Type Parameters:
E- theSet's element type- Parameters:
a- set ab- set b- Returns:
- a
Setcontaining the specified elements
-
difference
Returns a set containing all elements from setathat are notb.- Type Parameters:
E- theSet's element type- Parameters:
a- set ab- set b- Returns:
- a
Setcontaining the specified elements
-
nthElement
Returns then-th element from setset. Throws aIndexOutOfBoundsExceptionifnis negative or greater than the set's cardinality.- Type Parameters:
E- theSet's element type- Parameters:
set- a setn- specifies the element to be taken- Returns:
n-th element from setset- Throws:
IndexOutOfBoundsException- ifnis negative or greater than the set's cardinality
-
firstElement
Returns the first element from setset. Returnsnullif set is empty.- Type Parameters:
E- theSet's element type- Parameters:
set- a set- Returns:
- first element from set
set
-
firstElements
Returns the firstnelements from setset.- Type Parameters:
E- theSet's element type- Parameters:
set- a setn- elements to return- Returns:
- first
nelements from setset - Throws:
IllegalArgumentException- ifnis negative
-
cartesianProduct
Returns the cartesian product of the two setsaandb. This is the set of all orderedPairs(x,y)wherexis inaandyis inb.- Type Parameters:
A- the type of the elements in setaB- the type of the elements in setb- Parameters:
a- first set for the cartesian productb- second set for the cartesian product- Returns:
- the cartesian product of the two sets
aandb
-