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 aCollectorthat accumulates 0 or 1 input elements into anOptional<T>.static <T,O> Collector <T, ?, O> toOptional(Supplier<O> empty, Function<T, O> factory) Returns aCollectorthat accumulates 0 or 1 input elements into an arbitrary optional-style container type.static Collector<Double, ?, OptionalDouble> Returns aCollectorthat accumulates 0 or 1 inputDoubleelements into anOptionalDouble.static Collector<Integer, ?, OptionalInt> Returns aCollectorthat accumulates 0 or 1 inputIntegerelements into anOptionalInt.static Collector<Long, ?, OptionalLong> Returns aCollectorthat accumulates 0 or 1 inputLongelements into anOptionalLong.
-
Method Details
-
toOptional
Returns aCollectorthat accumulates 0 or 1 input elements into anOptional<T>. The returned collector will throwIllegalStateExceptionwhenever 2 or more elements are present in a stream. Null elements are mapped toOptional.empty().- Type Parameters:
T- the collected type- Returns:
- a
Collectorwhich collects 0 or 1 input elements into anOptional<T>.
-
toOptionalInt
Returns aCollectorthat accumulates 0 or 1 inputIntegerelements into anOptionalInt. The returned collector will throwIllegalStateExceptionwhenever 2 or more elements are present in a stream. Null elements are mapped toOptionalInt.empty().- Returns:
- a
Collectorwhich collects 0 or 1 inputIntegerelements into anOptionalInt.
-
toOptionalLong
Returns aCollectorthat accumulates 0 or 1 inputLongelements into anOptionalLong. The returned collector will throwIllegalStateExceptionwhenever 2 or more elements are present in a stream. Null elements are mapped toOptionalLong.empty().- Returns:
- a
Collectorwhich collects 0 or 1 inputLongelements into anOptionalLong.
-
toOptionalDouble
Returns aCollectorthat accumulates 0 or 1 inputDoubleelements into anOptionalDouble. The returned collector will throwIllegalStateExceptionwhenever 2 or more elements are present in a stream. Null elements are mapped toOptionalDouble.empty().- Returns:
- a
Collectorwhich collects 0 or 1 inputDoubleelements into anOptionalDouble.
-
toOptional
Returns aCollectorthat accumulates 0 or 1 input elements into an arbitrary optional-style container type. The returned collector will throwIllegalStateExceptionwhenever 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 theTgeneric 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
Collectorwhich collects 0 or 1 input elements into an arbitrary optional-style container type.
-