Package org.kiwiproject.collect
Class KiwiCollectors
- java.lang.Object
-
- org.kiwiproject.collect.KiwiCollectors
-
-
Constructor Summary
Constructors Constructor Description KiwiCollectors()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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)static <E extends Enum<E>>
Collector<E,EnumSet<E>,EnumSet<E>>toEnumSet(Class<E> type)static <T> Collector<T,com.google.common.collect.ImmutableList.Builder<T>,com.google.common.collect.ImmutableList.Builder<T>>toImmutableListBuilder()Return aCollectorthat collects into a GuavaImmutableList.Builder.static <T,K,U>
Collector<T,?,Map<K,U>>toLinkedMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper)Returns aCollectorthat collects intoaLinkedHashMap.
-
-
-
Method Detail
-
toImmutableListBuilder
public static <T> Collector<T,com.google.common.collect.ImmutableList.Builder<T>,com.google.common.collect.ImmutableList.Builder<T>> toImmutableListBuilder()
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
public static <E extends Enum<E>> Collector<E,EnumSet<E>,EnumSet<E>> toEnumSet(Class<E> type)
-
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 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,U> Collector<T,?,Map<K,U>> toLinkedMap(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.
-
-