Class SetOperations


  • public class SetOperations
    extends Object
    Utility methods for sets with common names.
    Author:
    nilshoffmann
    • Constructor Detail

      • SetOperations

        public SetOperations()
    • Method Detail

      • newSet

        public static <T> Set<T> newSet​(Collection<? extends T> c)
        Creates a new typed LinkedHashSet (preserving order of insertion) from the given collection.
        Type Parameters:
        T - the value type
        Parameters:
        c - the collection
        Returns:
        a new typed hash set
      • union

        public static <T> Set<T> union​(Set<T> a,
                                       Set<T> b)
        Returns the union (a+b) of a and b.
        Type Parameters:
        T - the value type
        Parameters:
        a - set a
        b - set b
        Returns:
        the union of a and b
      • intersection

        public static <T> Set<T> intersection​(Set<T> a,
                                              Set<T> b)
        Returns the intersection (a \cap b, all common elements) of a and b.
        Type Parameters:
        T - the value type
        Parameters:
        a - set a
        b - set b
        Returns:
        the intersection of a and b
      • complement

        public static <T> Set<T> complement​(Set<T> a,
                                            Set<T> b)
        Returns the complement (a without elements also in b) of a and b.
        Type Parameters:
        T - the value type
        Parameters:
        a - set a
        b - set b
        Returns:
        the complement of a and b
      • symmetricDifference

        public static <T> Set<T> symmetricDifference​(Set<T> a,
                                                     Set<T> b)
        Returns the symmetric set difference (union(complement(a,b),complement(b,a))) on a and b.
        Type Parameters:
        T - the value type
        Parameters:
        a - set a
        b - set b
        Returns:
        the symmetric set difference