List of utility methods to do Collection Unique
boolean | hasUniqueObject(Collection collection) CollectionUtils Determine whether the given Collection only contains a single unique object. if (collection == null || collection.isEmpty()) { return false; boolean hasCandidate = false; Object candidate = null; for (Object elem : collection) { if (!hasCandidate) { hasCandidate = true; ... |
Collection | unique(Collection unique if (c != null && c.size() > 0) { Map<T, Integer> map = new LinkedHashMap<T, Integer>(); for (T o : c) { map.put(o, 0); return new ArrayList<T>(map.keySet()); return c; ... |
Collection | unique(Collection unique if (c == null) { return result; Set<T> s = new LinkedHashSet<T>(c); result.addAll(s); return result; |
String | uniqueIdNotIn(String prefix, Collection extends String> exclusions) unique Id Not In StringBuilder sb = new StringBuilder(prefix); for (int counter = 0;; ++counter) { sb.setLength(prefix.length()); sb.append('.').append(counter); String candidate = sb.toString(); if (!exclusions.contains(candidate)) { return candidate; |
T | uniqueResult(Collection Method to take a get a unique result from a set and return it or null. return results.isEmpty() ? null : results.iterator().next();
|
T | uniqueResult(final Collection unique Result switch (c.size()) { case 0: return null; case 1: return c.iterator().next(); default: throw new IllegalStateException("Unexpected number of elements in collection: " + c.size()); |