Coverage Report - org.kuali.core.db.torque.SetUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
SetUtils
0%
0/17
0%
0/4
1.333
 
 1  
 package org.kuali.core.db.torque;
 2  
 
 3  
 import java.util.Set;
 4  
 import java.util.TreeSet;
 5  
 
 6  
 /**
 7  
  * Utility methods for Set operations
 8  
  */
 9  0
 public class SetUtils {
 10  
 
 11  
     /**
 12  
      * Returns the combined elements from both
 13  
      */
 14  
     public static <T> Set<T> union(Set<T> a, Set<T> b) {
 15  0
         Set<T> tmp = new TreeSet<T>(a);
 16  0
         tmp.addAll(b);
 17  0
         return tmp;
 18  
     }
 19  
 
 20  
     /**
 21  
      * Returns only those elements that are present in both A and B
 22  
      */
 23  
     public static <T> Set<T> intersection(Set<T> a, Set<T> b) {
 24  0
         Set<T> tmp = new TreeSet<T>();
 25  0
         for (T x : a) {
 26  0
             if (b.contains(x)) {
 27  0
                 tmp.add(x);
 28  
             }
 29  
         }
 30  0
         return tmp;
 31  
     }
 32  
 
 33  
     /**
 34  
      * Returns elements from A that are not in B
 35  
      */
 36  
     public static <T> Set<T> difference(Set<T> a, Set<T> b) {
 37  0
         Set<T> tmp = new TreeSet<T>(a);
 38  0
         tmp.removeAll(b);
 39  0
         return tmp;
 40  
     }
 41  
 
 42  
     /**
 43  
      * Return the symDifference
 44  
      */
 45  
     public static <T> Set<T> symDifference(Set<T> a, Set<T> b) {
 46  0
         Set<T> tmpA = union(a, b);
 47  0
         Set<T> tmpB = intersection(a, b);
 48  0
         return difference(tmpA, tmpB);
 49  
     }
 50  
 
 51  
     /**
 52  
      * Return true if every element in A is also present in B
 53  
      */
 54  
     public static <T> boolean isSubset(Set<T> a, Set<T> b) {
 55  0
         return b.containsAll(a);
 56  
     }
 57  
 
 58  
     /**
 59  
      * Return true if every element in B is also present in A
 60  
      */
 61  
     public static <T> boolean isSuperset(Set<T> a, Set<T> b) {
 62  0
         return a.containsAll(b);
 63  
     }
 64  
 }