Package google.registry.util
Class CollectionUtils
java.lang.Object
google.registry.util.CollectionUtils
Utility methods related to collections.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> com.google.common.collect.ImmutableSet
<T> difference
(Set<T> set, T... toRemove) Copy anImmutableSet
and remove members.static <T> Set
<T> findDuplicates
(Iterable<T> iterable) Returns any duplicates in an iterable.static <T,
C extends Collection<T>>
CforceEmptyToNull
(C potentiallyEmpty) Turns an empty collection into a null collection.static boolean
isNullOrEmpty
(com.google.common.collect.Multimap<?, ?> potentiallyNull) Checks if a Multimap is null or empty.static boolean
isNullOrEmpty
(Iterable<?> potentiallyNull) Checks if an iterable is null or empty.static boolean
isNullOrEmpty
(Map<?, ?> potentiallyNull) Checks if a map is null or empty.static <V> com.google.common.collect.ImmutableList
<V> nullSafeImmutableCopy
(List<V> data) Defensive copy helper forList
.static <V> com.google.common.collect.ImmutableSet
<V> nullSafeImmutableCopy
(Set<V> data) Defensive copy helper forSet
.static <T,
U> com.google.common.collect.Multimap <T, U> nullToEmpty
(com.google.common.collect.Multimap<T, U> potentiallyNull) Turns a null multimap into an empty multimap.static <T> List
<T> nullToEmpty
(List<T> potentiallyNull) Turns a null list into an empty list.static <T,
U> Map <T, U> nullToEmpty
(Map<T, U> potentiallyNull) Turns a null map into an empty map.static <T> Set
<T> nullToEmpty
(Set<T> potentiallyNull) Turns a null set into an empty set.static <T,
U> SortedMap <T, U> nullToEmpty
(SortedMap<T, U> potentiallyNull) Turns a null sorted map into an empty sorted map..static <V> com.google.common.collect.ImmutableList
<V> nullToEmptyImmutableCopy
(List<V> data) Defensive copy helper forList
.static <K,
V> com.google.common.collect.ImmutableMap <K, V> nullToEmptyImmutableCopy
(Map<K, V> data) Defensive copy helper forMap
.static <V> com.google.common.collect.ImmutableSet
<V> nullToEmptyImmutableCopy
(Set<V> data) Defensive copy helper forSet
.static <K,
V> com.google.common.collect.ImmutableSortedMap <K, V> nullToEmptyImmutableCopy
(SortedMap<K, V> data) Defensive copy helper forSortedMap
.static <V extends Comparable<V>>
com.google.common.collect.ImmutableSortedSet<V> nullToEmptyImmutableSortedCopy
(Set<V> data) Defensive copy helper forSet
.static <K,
V> com.google.common.collect.ImmutableList <com.google.common.collect.ImmutableMap<K, V>> partitionMap
(Map<K, V> map, int size) Partitions a Map into a Collection of Maps, each of max size n.static <T> com.google.common.collect.ImmutableSet
<T> Copy anImmutableSet
and add members.
-
Constructor Details
-
CollectionUtils
public CollectionUtils()
-
-
Method Details
-
isNullOrEmpty
Checks if an iterable is null or empty. -
isNullOrEmpty
Checks if a map is null or empty. -
isNullOrEmpty
public static boolean isNullOrEmpty(@Nullable com.google.common.collect.Multimap<?, ?> potentiallyNull) Checks if a Multimap is null or empty. -
nullToEmpty
Turns a null set into an empty set. JAXB leaves lots of null sets lying around. -
nullToEmpty
Turns a null list into an empty list. -
nullToEmpty
Turns a null map into an empty map. -
nullToEmpty
public static <T,U> com.google.common.collect.Multimap<T,U> nullToEmpty(@Nullable com.google.common.collect.Multimap<T, U> potentiallyNull) Turns a null multimap into an empty multimap. -
nullToEmpty
Turns a null sorted map into an empty sorted map.. -
nullSafeImmutableCopy
public static <V> com.google.common.collect.ImmutableSet<V> nullSafeImmutableCopy(@Nullable Set<V> data) Defensive copy helper forSet
. -
nullSafeImmutableCopy
public static <V> com.google.common.collect.ImmutableList<V> nullSafeImmutableCopy(@Nullable List<V> data) Defensive copy helper forList
. -
nullToEmptyImmutableCopy
public static <V> com.google.common.collect.ImmutableSet<V> nullToEmptyImmutableCopy(@Nullable Set<V> data) Defensive copy helper forSet
. -
nullToEmptyImmutableSortedCopy
public static <V extends Comparable<V>> com.google.common.collect.ImmutableSortedSet<V> nullToEmptyImmutableSortedCopy(@Nullable Set<V> data) Defensive copy helper forSet
. -
nullToEmptyImmutableCopy
public static <K,V> com.google.common.collect.ImmutableSortedMap<K,V> nullToEmptyImmutableCopy(@Nullable SortedMap<K, V> data) Defensive copy helper forSortedMap
. -
nullToEmptyImmutableCopy
public static <V> com.google.common.collect.ImmutableList<V> nullToEmptyImmutableCopy(@Nullable List<V> data) Defensive copy helper forList
. -
nullToEmptyImmutableCopy
public static <K,V> com.google.common.collect.ImmutableMap<K,V> nullToEmptyImmutableCopy(@Nullable Map<K, V> data) Defensive copy helper forMap
. -
forceEmptyToNull
@Nullable public static <T,C extends Collection<T>> C forceEmptyToNull(@Nullable C potentiallyEmpty) Turns an empty collection into a null collection.This is unwise in the general case (nulls are bad; empties are good) but occasionally needed to cause JAXB not to emit a field. The method name includes "force" to indicate that you should think twice before using it.
-
union
@SafeVarargs public static <T> com.google.common.collect.ImmutableSet<T> union(Set<T> set, T... newMembers) Copy anImmutableSet
and add members. -
difference
@SafeVarargs public static <T> com.google.common.collect.ImmutableSet<T> difference(Set<T> set, T... toRemove) Copy anImmutableSet
and remove members. -
findDuplicates
Returns any duplicates in an iterable. -
partitionMap
public static <K,V> com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableMap<K,V>> partitionMap(Map<K, V> map, int size) Partitions a Map into a Collection of Maps, each of max size n. -
entriesToImmutableMap
-