CollectionUtil { public static boolean anyMissing(final Collection collection, final Object[] objects) { boolean result = false; if (null == collection || collection.isEmpty()) { if (null != objects && 0 < objects.length) { result = true; } } else if (null != objects) { for (final Object object : objects) { if (!collection.contains(object)) { result = true; break; } } } return result; } private  CollectionUtil(); static Iterable[] toIterableArray(final Collection<? extends Iterable> collection); static TreeSet<T> treeSet(final T item); static TreeSet<T> treeSet(final T[] items); static void toMapWithClassKeys(final Map<String, V> mapAsStrings, final Map<Class<? extends K>, V> map); static Map<Class<? extends K>, V> toMapWithClassKeys(final Map<String, V> mapAsStrings); static void toMapWithStringKeys(final Map<Class<? extends K>, V> map, final Map<String, V> mapAsStrings); static Map<String, V> toMapWithStringKeys(final Map<Class<? extends K>, V> map); static boolean containsAny(final Collection collection, final Object[] objects); static boolean anyMissing(final Collection collection, final Object[] objects); static boolean distinct(final Collection<T> collection);  }
@Test public void shouldReturnFalseWhenAnyMissingCalledWhenTheCollectionContainsAllValues() { final Collection<Integer> collection = Sets.newHashSet(10, 20, 30); final Object[] values = new Object[] {10, 20, 30}; final boolean result = CollectionUtil.anyMissing(collection, values); assertFalse(result); }
@Test public void shouldReturnFalseWhenAnyMissingCalledWhenNullValues() { final Collection<Integer> collection = Sets.newHashSet(10, 20, 30); final boolean result = CollectionUtil.anyMissing(collection, null); assertFalse(result); }
@Test public void shouldReturnTrueWhenAnyMissingCalledWhenTheCollectionDoesNotContainAProvidedValue() { final Collection<Integer> collection = Sets.newHashSet(10, 20, 30); final Object[] values = new Object[] {1, 2, 3}; final boolean result = CollectionUtil.anyMissing(collection, values); assertTrue(result); }
@Test public void shouldReturnFalseWhenAnyMissingCalledWithNullValue() { final Collection<Integer> collection = Sets.newHashSet(10, 20, 30); final boolean result = CollectionUtil.anyMissing(collection, null); assertFalse(result); }
@Test public void shouldReturnTrueWhenAnyMissingCalledWithNullCollectionAndSomeValues() { final Object[] values = new Object[] {1, 2, 3}; final boolean result = CollectionUtil.anyMissing(null, values); assertTrue(result); }
@Test public void shouldReturnFalseWhenAnyMissingCalledWithNullCollectionAndValues() { final boolean result = CollectionUtil.anyMissing(null, null); assertFalse(result); }