Package org.kiwiproject.collect
Class KiwiCollectors
java.lang.Object
org.kiwiproject.collect.KiwiCollectors
Utility for custom
Collector implementations-
Method Summary
Modifier and TypeMethodDescriptiontoEnumMap(Class<K> enumClass, Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) static <T> Collector<T,com.google.common.collect.ImmutableList.Builder<T>, com.google.common.collect.ImmutableList.Builder<T>> Return aCollectorthat collects into a GuavaImmutableList.Builder.toLinkedMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) Returns aCollectorthat collects intoaLinkedHashMap.
-
Method Details
-
toImmutableListBuilder
public static <T> Collector<T,com.google.common.collect.ImmutableList.Builder<T>, toImmutableListBuilder()com.google.common.collect.ImmutableList.Builder<T>> Return aCollectorthat collects into a GuavaImmutableList.Builder. You only then need to callImmutableList.Builder.build().- Type Parameters:
T- the type in the list- Returns:
- ImmutableList of
T
-
toEnumSet
-
toEnumMap
public static <T,K extends Enum<K>, Collector<T,U> ?, toEnumMapMap<K, U>> (Class<K> enumClass, Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) Returns aCollectorthat collects into anEnumMap.If the mapped keys contain duplicates (according to
Object.equals(Object)), anIllegalStateExceptionis thrown when the collection operation is performed.- Type Parameters:
T- the type of the input elementsK- the output type of the key mapping functionU- the outptu type of the value mapping function- Parameters:
enumClass- the key type for the returned mapkeyMapper- a mapping function to produce keysvalueMapper- a mapping function to produce values- Returns:
- a
Collectorwhich collects elements into anEnumMapwhose keys are the result of applying key and value mapping functions.
-
toLinkedMap
public static <T,K, Collector<T,U> ?, toLinkedMapMap<K, U>> (Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper) Returns aCollectorthat collects intoaLinkedHashMap.- Type Parameters:
T- the type of the input elementsK- the output type of the key mapping functionU- the output type of the value mapping function- Parameters:
keyMapper- a mapping function to produce keysvalueMapper- a mapping function to produce values- Returns:
- a
Collectorwhich collects elements into aLinkedHashMapwhose keys are the result of applying key and value mapping functions.
-