Class SetOperations


  • public class SetOperations
    extends java.lang.Object
    Specific reusable operations for sets.
    Author:
    Holger Eichelberger
    • Constructor Summary

      Constructors 
      Constructor Description
      SetOperations()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> java.util.Set<T> difference​(Set<T> s1, Set<T> s2)
      Calculates the difference between the given two sets, i.e., the elements of s1 that are not in s2.
      private static <T> java.util.Set<T> difference​(Set<T> s1, Set<T> s2, java.util.Set<T> result)
      Calculates the difference between the given two sets, i.e., the elements of s1 that are not in s2.
      static <T> java.util.Set<T> symmetricDifference​(Set<T> s1, Set<T> s2)
      Calculates the symmetric difference between the given two sets, i.e., the elements that are either in s1 or in s2 but not in both.
      • Methods inherited from class java.lang.Object

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

      • SetOperations

        public SetOperations()
    • Method Detail

      • difference

        public static <T> java.util.Set<T> difference​(Set<T> s1,
                                                      Set<T> s2)
        Calculates the difference between the given two sets, i.e., the elements of s1 that are not in s2.
        Type Parameters:
        T - the element type
        Parameters:
        s1 - the first set
        s2 - the second set
        Returns:
        the set difference
      • difference

        private static <T> java.util.Set<T> difference​(Set<T> s1,
                                                       Set<T> s2,
                                                       java.util.Set<T> result)
        Calculates the difference between the given two sets, i.e., the elements of s1 that are not in s2.
        Type Parameters:
        T - the element type
        Parameters:
        s1 - the first set
        s2 - the second set
        result - the result set (a new one is created if null)
        Returns:
        the set difference in terms of result or the new set created
      • symmetricDifference

        public static <T> java.util.Set<T> symmetricDifference​(Set<T> s1,
                                                               Set<T> s2)
        Calculates the symmetric difference between the given two sets, i.e., the elements that are either in s1 or in s2 but not in both.
        Type Parameters:
        T - the element type
        Parameters:
        s1 - the first set
        s2 - the second set
        Returns:
        the symmetric set difference