1 | |
package org.kuali.core.db.torque; |
2 | |
|
3 | |
import java.util.Set; |
4 | |
import java.util.TreeSet; |
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | 0 | public class SetUtils { |
10 | |
|
11 | |
|
12 | |
|
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 | |
|
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 | |
|
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 | |
|
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 | |
|
53 | |
|
54 | |
public static <T> boolean isSubset(Set<T> a, Set<T> b) { |
55 | 0 | return b.containsAll(a); |
56 | |
} |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
public static <T> boolean isSuperset(Set<T> a, Set<T> b) { |
62 | 0 | return a.containsAll(b); |
63 | |
} |
64 | |
} |