Package com.persequor.helpers
Class Collectors
java.lang.Object
com.persequor.helpers.Collectors
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <X> X
throwOnMerge
(X a, X b) Helper method to be used as merge function, when duplicate keys are not expected.static <T,
K> Collector<T, ?, LinkedHashMap<K, T>> toOrderedMap
(Function<T, K> keyMapper) Returns a Collector that accumulates elements into a LinkedHashMap whose keys are the result of applying the provided keyMapper function to the input elements, and whose values are the input elements.static <T,
K, U> Collector<T, ?, LinkedHashMap<K, U>> toOrderedMap
(Function<T, K> keyMapper, Function<T, U> valueMapper) Returns a Collector that accumulates elements into a LinkedHashMap whose keys and values are the result of applying the provided mapping functions to the input elements.
-
Constructor Details
-
Collectors
public Collectors()
-
-
Method Details
-
toOrderedMap
Returns a Collector that accumulates elements into a LinkedHashMap whose keys are the result of applying the provided keyMapper function to the input elements, and whose values are the input elements.- Type Parameters:
T
- the type of the input elements and map valuesK
- the type of the map keys- Parameters:
keyMapper
- A function that returns a key for an element- Returns:
- a Collector which collects elements into a LinkedHashMap, in encounter order
-
toOrderedMap
public static <T,K, Collector<T,U> ?, toOrderedMapLinkedHashMap<K, U>> (Function<T, K> keyMapper, Function<T, U> valueMapper) Returns a Collector that accumulates elements into a LinkedHashMap whose keys and values are the result of applying the provided mapping functions to the input elements.- Type Parameters:
T
- the type of the input elementsK
- the type of the map keysU
- the type of the map values- Parameters:
keyMapper
- a mapping function to produce keysvalueMapper
- a mapping function to produce values- Returns:
- a Collector which collects elements into a LinkedHashMap, in encounter order
-
throwOnMerge
public static <X> X throwOnMerge(X a, X b) Helper method to be used as merge function, when duplicate keys are not expected.- Parameters:
a
- ignoredb
- ignored- Throws:
IllegalStateException
- always
-