Class OptionalCollectors

java.lang.Object
org.jdbi.v3.core.collector.OptionalCollectors

public class OptionalCollectors extends Object
Factory methods for collectors of optional types.
  • Method Details

    • toOptional

      public static <T> Collector<T,​?,​Optional<T>> toOptional()
      Returns a Collector that accumulates 0 or 1 input elements into an Optional<T>. The returned collector will throw IllegalStateException whenever 2 or more elements are present in a stream. Null elements are mapped to Optional.empty().
      Type Parameters:
      T - the collected type
      Returns:
      a Collector which collects 0 or 1 input elements into an Optional<T>.
    • toOptionalInt

      public static Collector<Integer,​?,​OptionalInt> toOptionalInt()
      Returns a Collector that accumulates 0 or 1 input Integer elements into an OptionalInt. The returned collector will throw IllegalStateException whenever 2 or more elements are present in a stream. Null elements are mapped to OptionalInt.empty().
      Returns:
      a Collector which collects 0 or 1 input Integer elements into an OptionalInt.
    • toOptionalLong

      public static Collector<Long,​?,​OptionalLong> toOptionalLong()
      Returns a Collector that accumulates 0 or 1 input Long elements into an OptionalLong. The returned collector will throw IllegalStateException whenever 2 or more elements are present in a stream. Null elements are mapped to OptionalLong.empty().
      Returns:
      a Collector which collects 0 or 1 input @{code Long} elements into an OptionalLong.
    • toOptionalDouble

      public static Collector<Double,​?,​OptionalDouble> toOptionalDouble()
      Returns a Collector that accumulates 0 or 1 input Double elements into an OptionalDouble. The returned collector will throw IllegalStateException whenever 2 or more elements are present in a stream. Null elements are mapped to OptionalDouble.empty().
      Returns:
      a Collector which collects 0 or 1 input @{code Double} elements into an OptionalDouble.
    • toOptional

      public static <T,​ O> Collector<T,​?,​O> toOptional(Supplier<O> empty, Function<T,​O> factory)
      Returns a Collector that accumulates 0 or 1 input elements into an arbitrary optional-style container type. The returned collector will throw IllegalStateException 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 the T 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.