Package edu.stanford.nlp.util
Class Sets
- java.lang.Object
-
- edu.stanford.nlp.util.Sets
-
public class Sets extends Object
Utilities for sets.- Author:
- Roger Levy, Bill MacCartney
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <E> voidassertEquals(Set<E> first, Set<E> second, String firstName, String secondName, boolean outputShared, Supplier<String> errorMessage)Tests whether two sets are equal.static <E,F>
Set<Pair<E,F>>cross(Set<E> s1, Set<F> s2)Returns the set cross product of s1 and s2, asPairsstatic <E> Set<E>diff(Set<E> s1, Set<E> s2)Returns the difference of sets s1 and s2.static <E> Set<E>intersection(Set<E> s1, Set<E> s2)Returns the intersection of sets s1 and s2.static <E> booleanintersects(Set<E> s1, Set<E> s2)Returns true if there is at least element that is in both s1 and s2.static voidmain(String[] args)static <E,F>
Set<F>map(Set<E> oldSet, Function<E,F> lambda)static <E> Set<Set<E>>powerSet(Set<E> s)Returns the powerset (the set of all subsets) of set s.static <E> Set<E>symmetricDiff(Set<E> s1, Set<E> s2)Returns the symmetric difference of sets s1 and s2 (i.e.static <E> Set<E>union(Set<E> s1, Set<E> s2)Returns the union of sets s1 and s2.
-
-
-
Method Detail
-
cross
public static <E,F> Set<Pair<E,F>> cross(Set<E> s1, Set<F> s2)
Returns the set cross product of s1 and s2, asPairs
-
symmetricDiff
public static <E> Set<E> symmetricDiff(Set<E> s1, Set<E> s2)
Returns the symmetric difference of sets s1 and s2 (i.e. all elements that are in only one of the two sets)
-
intersection
public static <E> Set<E> intersection(Set<E> s1, Set<E> s2)
Returns the intersection of sets s1 and s2.
-
intersects
public static <E> boolean intersects(Set<E> s1, Set<E> s2)
Returns true if there is at least element that is in both s1 and s2. Faster than calling intersection(Set,Set) if you don't need the contents of the intersection.
-
powerSet
public static <E> Set<Set<E>> powerSet(Set<E> s)
Returns the powerset (the set of all subsets) of set s.
-
assertEquals
public static <E> void assertEquals(Set<E> first, Set<E> second, String firstName, String secondName, boolean outputShared, Supplier<String> errorMessage)
Tests whether two sets are equal. If not, throws an assertion and gives a detailed report on the differences. May be long depending on the sizes of the sets!- Parameters:
first- a set to comparesecond- a set to compare againstfirstName- the name of the first set, used if an error occurssecondName- the name of the second set, used if an error occursoutputShared- output the common values for the two setserrorMessage- a Supplier of an error message, in case it is expensive to generate
-
main
public static void main(String[] args)
-
-