SetUtil { public static <S, T extends S, U extends S> boolean differenceEmpty(final Collection<T> a, final Collection<U> b) { if (a == null || a.isEmpty()) { return true; } for (S item : a) { if (!b.contains(item)) { return false; } } return true; } private  SetUtil(); @SafeVarargs static Collection<T> union(final Collection<T>... set); static List<T> union(final List<T>... lists); static Collection<T> symmetricDifference(final Collection<T> a, final Collection<T> b); static Collection<T> getMultiplyContainedItems(final List<T> list); static Collection<S> intersection(final Collection<T> a, final Collection<U> b); static boolean disjoint(final Collection<T> a, final Collection<U> b); static Collection<Collection<T>> getPotenceOfSet(final Collection<T> set, final byte exponent); static Collection<Collection<T>> getCartesianProductOfSetsOfSameClass(final Collection<Collection<T>> items); static Collection<Collection<T>> powerset(final Collection<T> items); static Collection<Collection<T>> getAllPossibleSubsets(final Collection<T> items); static Collection<Set<T>> subsetsOfSize(final Collection<T> set, final int size); static List<Set<T>> getAllPossibleSubsetsWithSizeParallely(final Collection<T> superSet, final int k); static List<Set<T>> getAllPossibleSubsetsWithSize(final Collection<T> superSet, final int k); static Collection<List<T>> getPermutations(final Collection<T> set); static Collection<S> difference(final Collection<T> a, final Collection<U> b); static Collection<S> getDisjointSet(final Collection<T> a, final Collection<U> b); static List<S> difference(final List<T> a, final Collection<U> b); static boolean differenceEmpty(final Collection<T> a, final Collection<U> b); static boolean differenceNotEmpty(final Collection<T> a, final Collection<U> b); static Collection<Pair<S, T>> cartesianProduct(final Collection<S> a, final Collection<T> b); static Collection<List<T>> cartesianProduct(final List<? extends Collection<T>> listOfSets); static Collection<List<S>> cartesianProduct(final Collection<S> set, final int number); static Collection<Pair<K, V>> relation(final Collection<K> keys, final Collection<V> values, final Predicate<Pair<K, V>> relationPredicate); static Map<K, Collection<V>> relationAsFunction(final Collection<K> keys, final Collection<V> values, final Predicate<Pair<K, V>> relationPredicate); static Collection<Map<K, V>> allMappings(final Collection<K> domain, final Collection<V> range, final boolean totalsOnly, final boolean injectivesOnly, final boolean surjectivesOnly); static Collection<Map<K, V>> allTotalMappings(final Collection<K> domain, final Collection<V> range); static Collection<Map<K, V>> allPartialMappings(final Collection<K> domain, final Collection<V> range); static Set<Map<K, V>> allTotalAndInjectiveMappingsWithConstraint(final Collection<K> domain, final Collection<V> range, final Predicate<Map<K, V>> pPredicate); static Set<Map<K, V>> allTotalMappingsWithLocalConstraints(final Collection<K> domain, final Collection<V> range, final Predicate<Pair<K, V>> pPredicate); static Set<Map<K, V>> allFuntionsFromFunctionallyDenotedRelation(final Map<K, Collection<V>> pRelation); static void shuffle(final List<T> list, final long seed); static T getRandomElement(final Collection<T> set, final long seed); static T getRandomElement(final Collection<T> set, final Random random); static Collection<T> getRandomSubset(final Collection<T> set, final int k, final Random random); static Collection<Integer> getRandomSetOfIntegers(final int maxExclusive, final int k, final Random random); static List<T> mergeSort(final Collection<T> set); static List<K> keySetSortedByValues(final Map<K, V> map, final boolean asc); static int calculateNumberOfTotalOrderings(final PartialOrderedSet<?> set); static Collection<List<E>> getAllTotalOrderings(final PartialOrderedSet<E> set); static String serializeAsSet(final Collection<String> set); static Set<String> unserializeSet(final String setDescriptor); static List<String> unserializeList(final String listDescriptor); static Interval unserializeInterval(final String intervalDescriptor); static List<T> getInvertedCopyOfList(final List<T> list); static List<T> addAndGet(final List<T> list, final T item); static Map<U, Collection<T>> groupCollectionByAttribute(final Collection<T> collection, final IGetter<T, U> getter); static List<String> explode(final String stringList); static List<String> explode(final String stringList, final String separator); static String implode(final Collection<? extends Object> collection, final String separator); static boolean doesStringCollectionOnlyContainNumbers(final Collection<String> strings); static Type getGenericClass(final Collection<?> c); static int argmax(final List<T> list); static int argmax(final T[] arr); static int argmin(final List<T> list); static int argmin(final T[] arr); static int argmin(final int[] arr); static int argmax(final int[] arr);  }
@Test public void testDifferenceEmptyPositiveCase() { Collection<String> a = new ArrayList<>(); a.add("i1"); a.add("i2"); a.add("i3"); Collection<String> b = new HashSet<>(); b.add("i1"); b.add("i2"); b.add("i3"); assertTrue("Difference IS empty, but SetUtil.differenceEmpty returns false", SetUtil.differenceEmpty(a, b)); }
@Test public void testDifferenceEmptyNegativeCase() { Collection<String> a = new ArrayList<>(); a.add("i1"); a.add("i2"); a.add("i3"); a.add("i4"); a.add("i5"); Collection<String> b = new ArrayList<>(); b.add("i2"); b.add("i3"); assertTrue(!SetUtil.differenceEmpty(a, b)); }