Package org.kiwiproject.stream
Class KiwiMultimapCollectors
- java.lang.Object
-
- org.kiwiproject.stream.KiwiMultimapCollectors
-
-
Constructor Summary
Constructors Constructor Description KiwiMultimapCollectors()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <K,V>
Collector<Map.Entry<K,V>,com.google.common.collect.Multimap<K,V>,com.google.common.collect.Multimap<K,V>>toArrayListMultimap()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>>toHashMultimap()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>>toLinkedHashMultimap()Collects into anLinkedHashMultimap.static <K,V,A extends com.google.common.collect.Multimap<K,V>>
Collector<Map.Entry<K,V>,A,A>toMultimap(Supplier<A> supplier)
-
-
-
Method Detail
-
toMultimap
public static <K,V,A extends com.google.common.collect.Multimap<K,V>> Collector<Map.Entry<K,V>,A,A> toMultimap(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>,com.google.common.collect.Multimap<K,V>,com.google.common.collect.Multimap<K,V>> toArrayListMultimap()
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>,com.google.common.collect.Multimap<K,V>,com.google.common.collect.Multimap<K,V>> toHashMultimap()
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>,com.google.common.collect.Multimap<K,V>,com.google.common.collect.Multimap<K,V>> toLinkedHashMultimap()
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
-
-