Class KiwiCollectors

java.lang.Object
org.kiwiproject.collect.KiwiCollectors

public final class KiwiCollectors extends Object
Utility for custom Collector implementations
  • Method Details

    • toImmutableListBuilder

      public static <T> Collector<T,com.google.common.collect.ImmutableList.Builder<T>,com.google.common.collect.ImmutableList.Builder<T>> toImmutableListBuilder()
      Return a Collector that collects into a Guava ImmutableList.Builder. You only then need to call ImmutableList.Builder.build().
      Type Parameters:
      T - the type in the list
      Returns:
      ImmutableList of T
    • toEnumSet

      public static <E extends Enum<E>> Collector<E,EnumSet<E>,EnumSet<E>> toEnumSet(Class<E> type)
      Returns a Collector that collects into an EnumSet.
      Type Parameters:
      E - the enum type subclass
      Parameters:
      type - the type in the EnumSet
      Returns:
      the Collector
    • toEnumMap

      public static <T, K extends Enum<K>, U> Collector<T,?,Map<K,U>> toEnumMap(Class<K> enumClass, Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper)
      Returns a Collector that collects into an EnumMap.

      If the mapped keys contain duplicates (according to Object.equals(Object)), an IllegalStateException is thrown when the collection operation is performed.

      Type Parameters:
      T - the type of the input elements
      K - the output type of the key mapping function
      U - the outptu type of the value mapping function
      Parameters:
      enumClass - the key type for the returned map
      keyMapper - a mapping function to produce keys
      valueMapper - a mapping function to produce values
      Returns:
      a Collector which collects elements into an EnumMap whose keys are the result of applying key and value mapping functions.
    • toLinkedMap

      public static <T, K, U> Collector<T,?,Map<K,U>> toLinkedMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper)
      Returns a Collector that collects intoa LinkedHashMap.
      Type Parameters:
      T - the type of the input elements
      K - the output type of the key mapping function
      U - the output type of the value mapping function
      Parameters:
      keyMapper - a mapping function to produce keys
      valueMapper - a mapping function to produce values
      Returns:
      a Collector which collects elements into a LinkedHashMap whose keys are the result of applying key and value mapping functions.