Class SetUtils


  • public final class SetUtils
    extends java.lang.Object
    A tiny collection of convenience methods useful in dealing with sets but not provided directly by Java's set classes.
    • Constructor Summary

      Constructors 
      Constructor Description
      SetUtils()  
    • Method Summary

      Modifier and Type Method Description
      static <T> java.util.Set<T> getDifference​(java.util.Set<T> s1, java.util.Set<T> s2)
      Returns the set difference between the set s1 and the set s2.
      static <T> java.util.Set<T> getIntersection​(java.util.List<java.util.Set<T>> sets)
      Returns the intersection of all sets contained in the list sets.
      static <T> java.util.Set<T> getIntersection​(java.util.Set<T> s1, java.util.Set<T> s2)
      Returns the intersection of set s1 and set s2.
      static <T> java.util.Set<T> getUnion​(java.util.List<java.util.Set<T>> sets)
      Returns the union of all sets contained in the list sets.
      static <T> java.util.Set<T> getUnion​(java.util.Set<T> s1, java.util.Set<T> s2)
      Returns the union of set s1 and set s2.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SetUtils

        public SetUtils()
    • Method Detail

      • getDifference

        public static <T> java.util.Set<T> getDifference​(java.util.Set<T> s1,
                                                         java.util.Set<T> s2)
        Returns the set difference between the set s1 and the set s2.
        Type Parameters:
        T - Type of the sets' entries.
        Parameters:
        s1 - A set.
        s2 - Another set.
        Returns:
        The difference set.
      • getIntersection

        public static <T> java.util.Set<T> getIntersection​(java.util.Set<T> s1,
                                                           java.util.Set<T> s2)
        Returns the intersection of set s1 and set s2. Returns an empty set if the intersection is empty, i.e., does not return null.
        Type Parameters:
        T - Type of the sets' entries.
        Parameters:
        s1 - A set.
        s2 - Another set.
        Returns:
        The intersection set.
      • getIntersection

        public static <T> java.util.Set<T> getIntersection​(java.util.List<java.util.Set<T>> sets)
        Returns the intersection of all sets contained in the list sets.
        Type Parameters:
        T - Type of the sets' entries.
        Parameters:
        sets - A list of sets
        Returns:
        The intersection of all sets
      • getUnion

        public static <T> java.util.Set<T> getUnion​(java.util.Set<T> s1,
                                                    java.util.Set<T> s2)
        Returns the union of set s1 and set s2.
        Type Parameters:
        T - Type of the sets' entries.
        Parameters:
        s1 - A set.
        s2 - Another set.
        Returns:
        The union set.
      • getUnion

        public static <T> java.util.Set<T> getUnion​(java.util.List<java.util.Set<T>> sets)
        Returns the union of all sets contained in the list sets.
        Type Parameters:
        T - Type of the sets' entries.
        Parameters:
        sets - A list of sets.
        Returns:
        The union of all sets.