CollectionUtil { public static <T> boolean distinct(final Collection<T> collection) { final Set<T> set = new HashSet<>(); for (final T t : collection) { if (!set.add(t)) { return false; } } return true; } 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 shouldReturnTrueWhenDistinctCalledWithCollectionOfUniqueValues() { final Collection<Integer> collection = Lists.newArrayList(1, 2, 3, 4, 5); final boolean result = CollectionUtil.distinct(collection); assertTrue(result); }
@Test public void shouldReturnFalseWhenDistinctCalledWithCollectionOfNonUniqueValues() { final Collection<Integer> collection = Lists.newArrayList(1, 2, 3, 1, 2); final boolean result = CollectionUtil.distinct(collection); assertFalse(result); }