Package org.jdbi.v3.guava
Class GuavaCollectors
- java.lang.Object
-
- org.jdbi.v3.guava.GuavaCollectors
-
public class GuavaCollectors extends java.lang.ObjectProvides 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>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classGuavaCollectors.Factory
-
Constructor Summary
Constructors Modifier Constructor Description privateGuavaCollectors()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static <K,V,MB extends com.google.common.collect.ImmutableMultimap.Builder<K,V>>
MBcombine(MB a, MB b)private static <K,V,M extends com.google.common.collect.Multimap<K,V>>
Mcombine(M a, M b)static CollectorFactoryfactory()Returns aCollectorFactorywhich knows how to create all supported Guava types.private static <K,V,M extends com.google.common.collect.Multimap<K,V>>
voidputEntry(M map, java.util.Map.Entry<K,V> entry)static <K,V>
java.util.stream.Collector<java.util.Map.Entry<K,V>,?,com.google.common.collect.ArrayListMultimap<K,V>>toArrayListMultimap()Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into anArrayListMultimap<K, V>.static <K,V>
java.util.stream.Collector<java.util.Map.Entry<K,V>,?,com.google.common.collect.BiMap<K,V>>toHashBiMap()Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into aHashBiMap<K, V>.static <K,V>
java.util.stream.Collector<java.util.Map.Entry<K,V>,?,com.google.common.collect.HashMultimap<K,V>>toHashMultimap()Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into aHashMultimap<K, V>.static <K,V>
java.util.stream.Collector<java.util.Map.Entry<K,V>,?,com.google.common.collect.ImmutableListMultimap<K,V>>toImmutableListMultimap()Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into anImmutableListMultimap<K, V>.static <K,V>
java.util.stream.Collector<java.util.Map.Entry<K,V>,?,com.google.common.collect.ImmutableMap<K,V>>toImmutableMap()Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into anImmutableMap<K, V>.static <K,V>
java.util.stream.Collector<java.util.Map.Entry<K,V>,?,com.google.common.collect.ImmutableSetMultimap<K,V>>toImmutableSetMultimap()Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into anImmutableSetMultimap<K, V>.static <K,V>
java.util.stream.Collector<java.util.Map.Entry<K,V>,?,com.google.common.collect.LinkedListMultimap<K,V>>toLinkedListMultimap()Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into aLinkedListMultimap<K, V>.static <K,V,M extends com.google.common.collect.Multimap<K,V>>
java.util.stream.Collector<java.util.Map.Entry<K,V>,?,M>toMultimap(java.util.function.Supplier<M> multimapFactory)Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into aMultimap<K, V>of the supplied type.static <T> java.util.stream.Collector<T,?,com.google.common.base.Optional<T>>toOptional()Returns aCollectorthat accumulates 0 or 1 input elements into Guava'sOptional<T>.static <K extends java.lang.Comparable,V extends java.lang.Comparable>
java.util.stream.Collector<java.util.Map.Entry<K,V>,?,com.google.common.collect.TreeMultimap<K,V>>toTreeMultimap()Returns aCollectorthat accumulatesMap.Entry<K, V>input elements into aTreeMultimap<K, V>.
-
-
-
Method Detail
-
factory
public static CollectorFactory factory()
Returns aCollectorFactorywhich knows how to create all supported Guava types.- Returns:
- A
CollectorFactorywhich knows how to create all supported Guava types
-
toOptional
public static <T> java.util.stream.Collector<T,?,com.google.common.base.Optional<T>> 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> java.util.stream.Collector<java.util.Map.Entry<K,V>,?,com.google.common.collect.ImmutableMap<K,V>> toImmutableMap()
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
public static <K,V> java.util.stream.Collector<java.util.Map.Entry<K,V>,?,com.google.common.collect.BiMap<K,V>> 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> java.util.stream.Collector<java.util.Map.Entry<K,V>,?,com.google.common.collect.ImmutableListMultimap<K,V>> toImmutableListMultimap()
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> java.util.stream.Collector<java.util.Map.Entry<K,V>,?,com.google.common.collect.ImmutableSetMultimap<K,V>> toImmutableSetMultimap()
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> java.util.stream.Collector<java.util.Map.Entry<K,V>,?,com.google.common.collect.ArrayListMultimap<K,V>> toArrayListMultimap()
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> java.util.stream.Collector<java.util.Map.Entry<K,V>,?,com.google.common.collect.LinkedListMultimap<K,V>> toLinkedListMultimap()
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> java.util.stream.Collector<java.util.Map.Entry<K,V>,?,com.google.common.collect.HashMultimap<K,V>> toHashMultimap()
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 java.lang.Comparable,V extends java.lang.Comparable> java.util.stream.Collector<java.util.Map.Entry<K,V>,?,com.google.common.collect.TreeMultimap<K,V>> toTreeMultimap()
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,M extends com.google.common.collect.Multimap<K,V>> java.util.stream.Collector<java.util.Map.Entry<K,V>,?,M> toMultimap(java.util.function.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.
-
putEntry
private static <K,V,M extends com.google.common.collect.Multimap<K,V>> void putEntry(M map, java.util.Map.Entry<K,V> entry)
-
combine
private static <K,V,M extends com.google.common.collect.Multimap<K,V>> M combine(M a, M b)
-
combine
private static <K,V,MB extends com.google.common.collect.ImmutableMultimap.Builder<K,V>> MB combine(MB a, MB b)
-
-