SetUtils { public static <T> Set<T> intersection(Set<? extends T> setLeft, Set<? extends T> setRight) { Set<T> results = new HashSet<>(setLeft) ; results.retainAll(setRight) ; return results ; } private  SetUtils(); static final Set<X> concurrentHashSet(); static Set<T> intersection(Set<? extends T> setLeft, Set<? extends T> setRight); static boolean intersectionP(Set<? extends T> s1, Set<? extends T> s2); static Set<T> union(Set<? extends T> s1, Set<? extends T> s2); static Set<T> symmetricDifference(Set<? extends T> s1, Set<? extends T> s2); static Set<T> difference(Set<? extends T> s1, Set<? extends T> s2); static Set<T> toSet(Stream<T> stream);  }
@Test public void set_intersection_1() { Set<Integer> x1 = set(1,2,3) ; Set<Integer> x2 = set(1,2,3) ; Set<Integer> x3 = SetUtils.intersection(x1, x2) ; test(x3, 1,2,3) ; x3 = SetUtils.intersection(x2, x1) ; test(x3, 1,2,3) ; }
@Test public void set_intersection_2() { Set<Integer> x1 = set(1,2,3) ; Set<Integer> x2 = set(2,9) ; Set<Integer> x3 = SetUtils.intersection(x1, x2) ; test(x3, 2) ; x3 = SetUtils.intersection(x2, x1) ; test(x3, 2) ; }
@Test public void set_intersection_3() { Set<Integer> x1 = set(1,2,3) ; Set<Integer> x2 = set(6,7,8) ; Set<Integer> x3 = SetUtils.intersection(x1, x2) ; test(x3) ; x3 = SetUtils.intersection(x2, x1) ; test(x3) ; }