Package org.jdbi.v3.guava
Class GuavaCollectors
java.lang.Object
org.jdbi.v3.guava.GuavaCollectors
Provides Collectors for Guava collection types.
Supported container types:
- com.google.common.base.Optional<T> (throws an exception if more than one row in result)
- com.google.common.collect.ImmutableList<T>
- com.google.common.collect.ImmutableSet<T>
- com.google.common.collect.ImmutableSortedSet<T extends Comparable>
Supported Maps and Multimaps types - for rows mapped to Map.Entry<K, V>:
- com.google.common.collect.BiMap<K, V>
- com.google.common.collect.ImmutableMap<K, V>
- com.google.common.collect.Multimap<K, V>
- com.google.common.collect.ListMultimap<K, V>
- com.google.common.collect.ArrayListMultimap<K, V>
- com.google.common.collect.LinkedListMultimap<K, V>
- com.google.common.collect.SetMultimap<K, V>
- com.google.common.collect.HashMultimap<K, V>
- com.google.common.collect.TreeMultimap<K, V>
- com.google.common.collect.ImmutableMultimap<K, V>
- com.google.common.collect.ImmutableListMultimap<K, V>
- com.google.common.collect.ImmutableSetMultimap<K, V>
-
Method Summary
Modifier and TypeMethodDescriptionstatic CollectorFactoryfactory()Returns aCollectorFactorywhich knows how to create all supported Guava types.Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into anArrayListMultimap<K, V>.Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into aHashBiMap<K, V>.Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into aHashMultimap<K, V>.Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into anImmutableListMultimap<K, V>.Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into anImmutableMap<K, V>.Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into anImmutableSetMultimap<K, V>.Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into aLinkedListMultimap<K, V>.toMultimap(Supplier<M> multimapFactory) Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into aMultimap<K, V>of the supplied type.static <T> Collector<T,?, com.google.common.base.Optional<T>> Returns aCollectorthat accumulates 0 or 1 input elements into Guava'sOptional<T>.static <K extends Comparable,V extends Comparable>
Collector<Map.Entry<K,V>, ?, com.google.common.collect.TreeMultimap<K, V>> Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into aTreeMultimap<K, V>.
-
Method Details
-
factory
Returns aCollectorFactorywhich knows how to create all supported Guava types.- Returns:
- A
CollectorFactorywhich knows how to create all supported Guava types
-
toOptional
Returns aCollectorthat accumulates 0 or 1 input elements into Guava'sOptional<T>. The returned collector will throwIllegalStateExceptionwhenever 2 or more elements are present in a stream. Null elements are mapped toOptional.absent().- Type Parameters:
T- the collected type- Returns:
- a
Collectorwhich collects 0 or 1 input elements into a GuavaOptional<T>.
-
toImmutableMap
public static <K,V> Collector<Map.Entry<K,V>, toImmutableMap()?, com.google.common.collect.ImmutableMap<K, V>> Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into anImmutableMap<K, V>.- Type Parameters:
K- the type of map keysV- the type of map values- Returns:
- a
Collectorwhich collects map entry elements into anImmutableMap, in encounter order.
-
toHashBiMap
Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into aHashBiMap<K, V>. The returned collector will throwIllegalStateExceptionwhenever a set of input elements contains multiple entries with the same key.- Type Parameters:
K- the type of map keysV- the type of map values- Returns:
- a
Collectorwhich collects map entry elements into aHashBiMap, in encounter order.
-
toImmutableListMultimap
public static <K,V> Collector<Map.Entry<K,V>, toImmutableListMultimap()?, com.google.common.collect.ImmutableListMultimap<K, V>> Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into anImmutableListMultimap<K, V>.- Type Parameters:
K- the type of map keysV- the type of map values- Returns:
- a
Collectorwhich collects map entry elements into anImmutableListMultimap, in encounter order.
-
toImmutableSetMultimap
public static <K,V> Collector<Map.Entry<K,V>, toImmutableSetMultimap()?, com.google.common.collect.ImmutableSetMultimap<K, V>> Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into anImmutableSetMultimap<K, V>.- Type Parameters:
K- the type of map keysV- the type of map values- Returns:
- a
Collectorwhich collects map entry elements into anImmutableSetMultimap, in encounter order.
-
toArrayListMultimap
public static <K,V> Collector<Map.Entry<K,V>, toArrayListMultimap()?, com.google.common.collect.ArrayListMultimap<K, V>> Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into anArrayListMultimap<K, V>.- Type Parameters:
K- the type of map keysV- the type of map values- Returns:
- a
Collectorwhich collects map entry elements into anArrayListMultimap, in encounter order.
-
toLinkedListMultimap
public static <K,V> Collector<Map.Entry<K,V>, toLinkedListMultimap()?, com.google.common.collect.LinkedListMultimap<K, V>> Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into aLinkedListMultimap<K, V>.- Type Parameters:
K- the type of map keysV- the type of map values- Returns:
- a
Collectorwhich collects map entry elements into aLinkedListMultimap, in encounter order.
-
toHashMultimap
public static <K,V> Collector<Map.Entry<K,V>, toHashMultimap()?, com.google.common.collect.HashMultimap<K, V>> Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into aHashMultimap<K, V>.- Type Parameters:
K- the type of map keysV- the type of map values- Returns:
- a
Collectorwhich collects map entry elements into aArrayListMultimap, in encounter order.
-
toTreeMultimap
public static <K extends Comparable,V extends Comparable> Collector<Map.Entry<K,V>, toTreeMultimap()?, com.google.common.collect.TreeMultimap<K, V>> Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into aTreeMultimap<K, V>.- Type Parameters:
K- the type of map keysV- the type of map values- Returns:
- a
Collectorwhich collects map entry elements into aTreeMultimap, in encounter order.
-
toMultimap
public static <K,V, Collector<Map.Entry<K,M extends com.google.common.collect.Multimap<K, V>> V>, toMultimap?, M> (Supplier<M> multimapFactory) Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into aMultimap<K, V>of the supplied type.- Type Parameters:
K- the type of map keysV- the type of map valuesM- a supplier of your multimap type- Parameters:
multimapFactory- aSupplierwhich return a new, emptyMultimapof the appropriate type.- Returns:
- a
Collectorwhich collects map entry elements into aMultiamp, in encounter order.
-