//: com/mindviewinc/util/Sets.java // ©2015 MindView LLC: see Copyright.txt package com.mindviewinc.util; import java.util.*; public class Sets { public static Set union(Set a, Set b) { Set result = new HashSet<>(a); result.addAll(b); return result; } public static Set intersection(Set a, Set b) { Set result = new HashSet<>(a); result.retainAll(b); return result; } // Subtract subset from superset: public static Set difference(Set superset, Set subset) { Set result = new HashSet<>(superset); result.removeAll(subset); return result; } // Reflexive--everything not in the intersection: public static Set complement(Set a, Set b) { return difference(union(a, b), intersection(a, b)); } } ///:~