Package org.kiwiproject.stream
Class KiwiMultimapCollectors
java.lang.Object
org.kiwiproject.stream.KiwiMultimapCollectors
A
Collector that can collect into a Guava Multimap.-
Method Summary
Modifier and TypeMethodDescriptionstatic <K,V> Collector<Map.Entry<K, V>, com.google.common.collect.Multimap<K, V>, com.google.common.collect.Multimap<K, V>> Collects into anArrayListMultimap.static <K,V> Collector<Map.Entry<K, V>, com.google.common.collect.Multimap<K, V>, com.google.common.collect.Multimap<K, V>> Collects into anHashMultimap.static <K,V> Collector<Map.Entry<K, V>, com.google.common.collect.Multimap<K, V>, com.google.common.collect.Multimap<K, V>> Collects into anLinkedHashMultimap.toMultimap(Supplier<A> supplier)
-
Method Details
-
toMultimap
public static <K,V, Collector<Map.Entry<K,A extends com.google.common.collect.Multimap<K, V>> V>, toMultimapA, A> (Supplier<A> supplier) Given a stream ofMap.Entryobjects, collects to theMultimapspecified in thesupplierargument. This lets you create any type of Multimap you want to collect into. Usually you will use a method reference as the supplier, e.g.ArrayListMultimap:create. You can easily get a stream of Map.Entry objects by getting the map'sMap.entrySet()and then calling stream on it, e.g.someMap.entrySet().stream().- Type Parameters:
K- the key type of the Map.Entry objectsV- the value type of the Map.Entry objectsA- the accumulator type, i.e. some kind of Multimap- Parameters:
supplier- the Multimap to collect into- Returns:
- the collected Multimap
-
toArrayListMultimap
public static <K,V> Collector<Map.Entry<K,V>, toArrayListMultimap()com.google.common.collect.Multimap<K, V>, com.google.common.collect.Multimap<K, V>> Collects into anArrayListMultimap.- Type Parameters:
K- the key type of the Map.Entry objectsV- the value type of the Map.Entry objects- Returns:
- the collected ArrayListMultimap
-
toHashMultimap
public static <K,V> Collector<Map.Entry<K,V>, toHashMultimap()com.google.common.collect.Multimap<K, V>, com.google.common.collect.Multimap<K, V>> Collects into anHashMultimap.- Type Parameters:
K- the key type of the Map.Entry objectsV- the value type of the Map.Entry objects- Returns:
- the collected HashMultimap
-
toLinkedHashMultimap
public static <K,V> Collector<Map.Entry<K,V>, toLinkedHashMultimap()com.google.common.collect.Multimap<K, V>, com.google.common.collect.Multimap<K, V>> Collects into anLinkedHashMultimap.- Type Parameters:
K- the key type of the Map.Entry objectsV- the value type of the Map.Entry objects- Returns:
- the collected LinkedHashMultimap
-