Package org.jdbi.v3.core.collector
Class OptionalCollectors
java.lang.Object
org.jdbi.v3.core.collector.OptionalCollectors
Factory methods for
collectors
of optional types.-
Method Summary
Modifier and TypeMethodDescriptionReturns aCollector
that accumulates 0 or 1 input elements into anOptional<T>
.static <T,
O> Collector <T, ?, O> toOptional
(Supplier<O> empty, Function<T, O> factory) Returns aCollector
that accumulates 0 or 1 input elements into an arbitrary optional-style container type.static Collector
<Double, ?, OptionalDouble> Returns aCollector
that accumulates 0 or 1 inputDouble
elements into anOptionalDouble
.static Collector
<Integer, ?, OptionalInt> Returns aCollector
that accumulates 0 or 1 inputInteger
elements into anOptionalInt
.static Collector
<Long, ?, OptionalLong> Returns aCollector
that accumulates 0 or 1 inputLong
elements into anOptionalLong
.
-
Method Details
-
toOptional
Returns aCollector
that accumulates 0 or 1 input elements into anOptional<T>
. The returned collector will throwIllegalStateException
whenever 2 or more elements are present in a stream. Null elements are mapped toOptional.empty()
.- Type Parameters:
T
- the collected type- Returns:
- a
Collector
which collects 0 or 1 input elements into anOptional<T>
.
-
toOptionalInt
Returns aCollector
that accumulates 0 or 1 inputInteger
elements into anOptionalInt
. The returned collector will throwIllegalStateException
whenever 2 or more elements are present in a stream. Null elements are mapped toOptionalInt.empty()
.- Returns:
- a
Collector
which collects 0 or 1 inputInteger
elements into anOptionalInt
.
-
toOptionalLong
Returns aCollector
that accumulates 0 or 1 inputLong
elements into anOptionalLong
. The returned collector will throwIllegalStateException
whenever 2 or more elements are present in a stream. Null elements are mapped toOptionalLong.empty()
.- Returns:
- a
Collector
which collects 0 or 1 inputLong
elements into anOptionalLong
.
-
toOptionalDouble
Returns aCollector
that accumulates 0 or 1 inputDouble
elements into anOptionalDouble
. The returned collector will throwIllegalStateException
whenever 2 or more elements are present in a stream. Null elements are mapped toOptionalDouble.empty()
.- Returns:
- a
Collector
which collects 0 or 1 inputDouble
elements into anOptionalDouble
.
-
toOptional
Returns aCollector
that accumulates 0 or 1 input elements into an arbitrary optional-style container type. The returned collector will throwIllegalStateException
whenever 2 or more elements are present in a stream. Null elements are mapped to an empty container.- Type Parameters:
T
- The optional element type.O
- The optional type, which may incorporate theT
generic parameter e.g.Optional<T>
.- Parameters:
empty
- Supplies an instance of the optional type with no value.factory
- Returns an instance of the optional type with the input parameter as the value.- Returns:
- a
Collector
which collects 0 or 1 input elements into an arbitrary optional-style container type.
-