@Test void testHasIntersection() { Set<Integer> a = newHashSet(2, 3, 4); Set<Integer> b = newHashSet(3, 4, 5, 6); assertTrue(CollectionUtils.hasIntersection(a, b)); }
public static <T> boolean hasIntersection(Set<T> a, Set<T> b) { if (isEmpty(a) || isEmpty(b)) { return false; } if (a.size() < b.size()) { if (a.size() < 8) { return a.stream().anyMatch(b::contains); } else { return a.parallelStream().anyMatch(b::contains); } } else { if (b.size() < 8) { return b.stream().anyMatch(a::contains); } else { return b.parallelStream().anyMatch(a::contains); } } }
CollectionUtils { public static <T> boolean hasIntersection(Set<T> a, Set<T> b) { if (isEmpty(a) || isEmpty(b)) { return false; } if (a.size() < b.size()) { if (a.size() < 8) { return a.stream().anyMatch(b::contains); } else { return a.parallelStream().anyMatch(b::contains); } } else { if (b.size() < 8) { return b.stream().anyMatch(a::contains); } else { return b.parallelStream().anyMatch(a::contains); } } } }
CollectionUtils { public static <T> boolean hasIntersection(Set<T> a, Set<T> b) { if (isEmpty(a) || isEmpty(b)) { return false; } if (a.size() < b.size()) { if (a.size() < 8) { return a.stream().anyMatch(b::contains); } else { return a.parallelStream().anyMatch(b::contains); } } else { if (b.size() < 8) { return b.stream().anyMatch(a::contains); } else { return b.parallelStream().anyMatch(a::contains); } } }  }
CollectionUtils { public static <T> boolean hasIntersection(Set<T> a, Set<T> b) { if (isEmpty(a) || isEmpty(b)) { return false; } if (a.size() < b.size()) { if (a.size() < 8) { return a.stream().anyMatch(b::contains); } else { return a.parallelStream().anyMatch(b::contains); } } else { if (b.size() < 8) { return b.stream().anyMatch(a::contains); } else { return b.parallelStream().anyMatch(a::contains); } } }  static boolean isEmpty(Object[] array); static boolean isEmpty(Map<?, ?> map); static boolean isEmpty(Collection<?> collection); static Set<T> intersect(Set<T> a, Set<T> b); static Set<T> union(Set<T> a, Set<T> b); static boolean hasIntersection(Set<T> a, Set<T> b); @SafeVarargs static Set<T> newHashSet(T... values); }
CollectionUtils { public static <T> boolean hasIntersection(Set<T> a, Set<T> b) { if (isEmpty(a) || isEmpty(b)) { return false; } if (a.size() < b.size()) { if (a.size() < 8) { return a.stream().anyMatch(b::contains); } else { return a.parallelStream().anyMatch(b::contains); } } else { if (b.size() < 8) { return b.stream().anyMatch(a::contains); } else { return b.parallelStream().anyMatch(a::contains); } } }  static boolean isEmpty(Object[] array); static boolean isEmpty(Map<?, ?> map); static boolean isEmpty(Collection<?> collection); static Set<T> intersect(Set<T> a, Set<T> b); static Set<T> union(Set<T> a, Set<T> b); static boolean hasIntersection(Set<T> a, Set<T> b); @SafeVarargs static Set<T> newHashSet(T... values);  }