Class CollectionUtils

java.lang.Object
org.kuali.coeus.s2sgen.impl.util.CollectionUtils

public final class CollectionUtils extends Object
Yet another collection utility. Contains methods that are not found in the apache util classes or the jdk util classes.
  • Method Details

    • entry

      public static <K, V> Map.Entry<K,V> entry(K key, V value)
      Creates an entry from a key and value.
      Type Parameters:
      K - the key type
      V - the value type
      Parameters:
      key - the key. Can be null.
      value - the value. Can be null.
      Returns:
      a Map.Entry
    • entriesToMap

      public static <K, U, M extends Map<K, U>> Collector<Map.Entry<K,U>,?,M> entriesToMap(Supplier<M> mapSupplier)
      Convenience method to a return a Collector that converts an Map.Entry to a Map which type is provided as a mapSupplier.
      Type Parameters:
      K - the key type
      U - the value type
      M - the map type
      Parameters:
      mapSupplier - supplies a new instance of a Map. cannot be null.
      Returns:
      A Collector from Map.Entry to Map as defined by the mapSupplier
    • entriesToMap

      public static <K, U> Collector<Map.Entry<K,U>,?,Map<K,U>> entriesToMap()
      Convenience method to a return a Collector that converts an Map.Entry to a Map.
      Type Parameters:
      K - the key type
      U - the value type
      Returns:
      A Collector from Map.Entry to Map
    • entriesToMapWithReplacing

      public static <K, U> Collector<Map.Entry<K,U>,?,Map<K,U>> entriesToMapWithReplacing()
      Convenience method to a return a Collector that converts an Map.Entry to a Map. If a duplicate key is detected, the value is replaced rather throwing an exception as is the default behavior.
      Type Parameters:
      K - the key type
      U - the value type
      Returns:
      A Collector from Map.Entry to Map
    • nullSafeEntriesToMap

      public static <K, U> Collector<Map.Entry<K,U>,?,Map<K,U>> nullSafeEntriesToMap()
      Convenience method to a return a Collector that converts an Map.Entry to a Map.
      Type Parameters:
      K - the key type
      U - the value type
      Returns:
      A Collector from Map.Entry to Map
    • nullSafeToMap

      public static <T, K, U> Collector<T,?,Map<K,U>> nullSafeToMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper)
      Null-safe replacement for Collectors.toMap. Allows null keys and values. If a duplicate key is found, throws IllegalStateException
      Parameters:
      keyMapper - function to get the key from the items
      valueMapper - function to get the value from the items
      Returns:
      A Collector from List to Map