Class KiwiMultimapCollectors


  • public class KiwiMultimapCollectors
    extends Object
    A Collector that can collect into a Guava Multimap.
    • Constructor Detail

      • KiwiMultimapCollectors

        public KiwiMultimapCollectors()
    • 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 of Map.Entry objects, collects to the Multimap specified in the supplier argument. 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's Map.entrySet() and then calling stream on it, e.g. someMap.entrySet().stream().
        Type Parameters:
        K - the key type of the Map.Entry objects
        V - the value type of the Map.Entry objects
        A - 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 an ArrayListMultimap.
        Type Parameters:
        K - the key type of the Map.Entry objects
        V - 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 an HashMultimap.
        Type Parameters:
        K - the key type of the Map.Entry objects
        V - 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 an LinkedHashMultimap.
        Type Parameters:
        K - the key type of the Map.Entry objects
        V - the value type of the Map.Entry objects
        Returns:
        the collected LinkedHashMultimap