Class CollectionUtils

java.lang.Object
google.registry.util.CollectionUtils

public class CollectionUtils extends Object
Utility methods related to collections.
  • Constructor Details

    • CollectionUtils

      public CollectionUtils()
  • Method Details

    • isNullOrEmpty

      public static boolean isNullOrEmpty(@Nullable Iterable<?> potentiallyNull)
      Checks if an iterable is null or empty.
    • isNullOrEmpty

      public static boolean isNullOrEmpty(@Nullable Map<?,?> potentiallyNull)
      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

      public static <T> Set<T> nullToEmpty(@Nullable Set<T> potentiallyNull)
      Turns a null set into an empty set. JAXB leaves lots of null sets lying around.
    • nullToEmpty

      public static <T> List<T> nullToEmpty(@Nullable List<T> potentiallyNull)
      Turns a null list into an empty list.
    • nullToEmpty

      public static <T, U> Map<T,U> nullToEmpty(@Nullable Map<T,U> potentiallyNull)
      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

      public static <T, U> SortedMap<T,U> nullToEmpty(@Nullable SortedMap<T,U> potentiallyNull)
      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 for Set.
    • nullSafeImmutableCopy

      public static <V> com.google.common.collect.ImmutableList<V> nullSafeImmutableCopy(@Nullable List<V> data)
      Defensive copy helper for List.
    • nullToEmptyImmutableCopy

      public static <V> com.google.common.collect.ImmutableSet<V> nullToEmptyImmutableCopy(@Nullable Set<V> data)
      Defensive copy helper for Set.
    • nullToEmptyImmutableSortedCopy

      public static <V extends Comparable<V>> com.google.common.collect.ImmutableSortedSet<V> nullToEmptyImmutableSortedCopy(@Nullable Set<V> data)
      Defensive copy helper for Set.
    • nullToEmptyImmutableCopy

      public static <K, V> com.google.common.collect.ImmutableSortedMap<K,V> nullToEmptyImmutableCopy(@Nullable SortedMap<K,V> data)
      Defensive copy helper for SortedMap.
    • nullToEmptyImmutableCopy

      public static <V> com.google.common.collect.ImmutableList<V> nullToEmptyImmutableCopy(@Nullable List<V> data)
      Defensive copy helper for List.
    • nullToEmptyImmutableCopy

      public static <K, V> com.google.common.collect.ImmutableMap<K,V> nullToEmptyImmutableCopy(@Nullable Map<K,V> data)
      Defensive copy helper for Map.
    • 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 an ImmutableSet and add members.
    • difference

      @SafeVarargs public static <T> com.google.common.collect.ImmutableSet<T> difference(Set<T> set, T... toRemove)
      Copy an ImmutableSet and remove members.
    • findDuplicates

      public static <T> Set<T> findDuplicates(Iterable<T> iterable)
      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

      public static <K, V> Collector<Map.Entry<K,V>,?,com.google.common.collect.ImmutableMap<K,V>> entriesToImmutableMap()
      Returns a Collector that accumulates Map.Entrys into an ImmutableMap.