public class GuavaCollectors extends Object
Supported container types:
Supported Maps and Multimaps types - for rows mapped to Map.Entry<K, V>:
| Modifier and Type | Method and Description |
|---|---|
static CollectorFactory |
factory() |
static <K,V> Collector<Map.Entry<K,V>,?,com.google.common.collect.ArrayListMultimap<K,V>> |
toArrayListMultimap()
Returns a
Collector that accumulates Map.Entry<K, V> input elements into an
ArrayListMultimap<K, V>. |
static <K,V> Collector<Map.Entry<K,V>,?,com.google.common.collect.BiMap<K,V>> |
toHashBiMap()
Returns a
Collector that accumulates Map.Entry<K, V> input elements into a
HashBiMap<K, V>. |
static <K,V> Collector<Map.Entry<K,V>,?,com.google.common.collect.HashMultimap<K,V>> |
toHashMultimap()
Returns a
Collector that accumulates Map.Entry<K, V> input elements into a
HashMultimap<K, V>. |
static <K,V> Collector<Map.Entry<K,V>,?,com.google.common.collect.ImmutableListMultimap<K,V>> |
toImmutableListMultimap()
Returns a
Collector that accumulates Map.Entry<K, V> input elements into an
ImmutableListMultimap<K, V>. |
static <K,V> Collector<Map.Entry<K,V>,?,com.google.common.collect.ImmutableMap<K,V>> |
toImmutableMap()
Returns a
Collector that accumulates Map.Entry<K, V> input elements into an
ImmutableMap<K, V>. |
static <K,V> Collector<Map.Entry<K,V>,?,com.google.common.collect.ImmutableSetMultimap<K,V>> |
toImmutableSetMultimap()
Returns a
Collector that accumulates Map.Entry<K, V> input elements into an
ImmutableSetMultimap<K, V>. |
static <K,V> Collector<Map.Entry<K,V>,?,com.google.common.collect.LinkedListMultimap<K,V>> |
toLinkedListMultimap()
Returns a
Collector that accumulates Map.Entry<K, V> input elements into a
LinkedListMultimap<K, V>. |
static <K,V,M extends com.google.common.collect.Multimap<K,V>> |
toMultimap(Supplier<M> multimapFactory)
Returns a
Collector that accumulates Map.Entry<K, V> input elements into a
Multimap<K, V> of the supplied type. |
static <T> Collector<T,?,com.google.common.base.Optional<T>> |
toOptional()
Returns a
Collector that accumulates 0 or 1 input elements into Guava's Optional<T>. |
static <K extends Comparable,V extends Comparable> |
toTreeMultimap()
Returns a
Collector that accumulates Map.Entry<K, V> input elements into a
TreeMultimap<K, V>. |
public static CollectorFactory factory()
CollectorFactory which knows how to create all supported Guava typespublic static <T> Collector<T,?,com.google.common.base.Optional<T>> toOptional()
Collector that accumulates 0 or 1 input elements into Guava's Optional<T>.
The returned collector will throw IllegalStateException whenever 2 or more elements
are present in a stream. Null elements are mapped to Optional.absent().T - the collected typeCollector which collects 0 or 1 input elements into a Guava Optional<T>.public static <K,V> Collector<Map.Entry<K,V>,?,com.google.common.collect.ImmutableMap<K,V>> toImmutableMap()
Collector that accumulates Map.Entry<K, V> input elements into an
ImmutableMap<K, V>.K - the type of map keysV - the type of map valuesCollector which collects map entry elements into an ImmutableMap,
in encounter order.public static <K,V> Collector<Map.Entry<K,V>,?,com.google.common.collect.BiMap<K,V>> toHashBiMap()
Collector that accumulates Map.Entry<K, V> input elements into a
HashBiMap<K, V>. The returned collector will throw IllegalStateException
whenever a set of input elements contains multiple entries with the same key.K - the type of map keysV - the type of map valuesCollector which collects map entry elements into a HashBiMap,
in encounter order.public static <K,V> Collector<Map.Entry<K,V>,?,com.google.common.collect.ImmutableListMultimap<K,V>> toImmutableListMultimap()
Collector that accumulates Map.Entry<K, V> input elements into an
ImmutableListMultimap<K, V>.K - the type of map keysV - the type of map valuesCollector which collects map entry elements into an ImmutableListMultimap,
in encounter order.public static <K,V> Collector<Map.Entry<K,V>,?,com.google.common.collect.ImmutableSetMultimap<K,V>> toImmutableSetMultimap()
Collector that accumulates Map.Entry<K, V> input elements into an
ImmutableSetMultimap<K, V>.K - the type of map keysV - the type of map valuesCollector which collects map entry elements into an ImmutableSetMultimap,
in encounter order.public static <K,V> Collector<Map.Entry<K,V>,?,com.google.common.collect.ArrayListMultimap<K,V>> toArrayListMultimap()
Collector that accumulates Map.Entry<K, V> input elements into an
ArrayListMultimap<K, V>.K - the type of map keysV - the type of map valuesCollector which collects map entry elements into an ArrayListMultimap,
in encounter order.public static <K,V> Collector<Map.Entry<K,V>,?,com.google.common.collect.LinkedListMultimap<K,V>> toLinkedListMultimap()
Collector that accumulates Map.Entry<K, V> input elements into a
LinkedListMultimap<K, V>.K - the type of map keysV - the type of map valuesCollector which collects map entry elements into a LinkedListMultimap,
in encounter order.public static <K,V> Collector<Map.Entry<K,V>,?,com.google.common.collect.HashMultimap<K,V>> toHashMultimap()
Collector that accumulates Map.Entry<K, V> input elements into a
HashMultimap<K, V>.K - the type of map keysV - the type of map valuesCollector which collects map entry elements into a ArrayListMultimap,
in encounter order.public static <K extends Comparable,V extends Comparable> Collector<Map.Entry<K,V>,?,com.google.common.collect.TreeMultimap<K,V>> toTreeMultimap()
Collector that accumulates Map.Entry<K, V> input elements into a
TreeMultimap<K, V>.K - the type of map keysV - the type of map valuesCollector which collects map entry elements into a TreeMultimap,
in encounter order.public static <K,V,M extends com.google.common.collect.Multimap<K,V>> Collector<Map.Entry<K,V>,?,M> toMultimap(Supplier<M> multimapFactory)
Collector that accumulates Map.Entry<K, V> input elements into a
Multimap<K, V> of the supplied type.K - the type of map keysV - the type of map valuesM - a supplier of your multimap typemultimapFactory - a Supplier which return a new, empty Multimap of the appropriate type.Collector which collects map entry elements into a Multiamp, in encounter order.Copyright © 2019. All rights reserved.