Interface Value<T>

Type Parameters:
T - type of the value
All Known Subinterfaces:
ConfigValue<T>, ConfigValue<T>, DbColumn, Header, HeaderWriteable, OptionalValue<T>
All Known Implementing Classes:
ContentDisposition, DbColumnBase, MongoDbColumn

public interface Value<T>
A typed value with support for mapping (conversion) to other types. For values not backed by an data, see OptionalValue.
  • Method Details

    • create

      static <T> Value<T> create(MapperManager mapperManager, String name, T value, String... qualifiers)
      Create a value backed by data. The type of the value is "guessed" from the instance provided.
      Type Parameters:
      T - type of the value
      Parameters:
      mapperManager - mapper manager to use for mapping types
      name - name of the value
      value - value, must not be null
      qualifiers - qualifiers of the mapper
      Returns:
      a value backed by data
    • create

      static <T> Value<T> create(MapperManager mapperManager, String name, T value, GenericType<T> type, String... qualifiers)
      Create a value backed by data.
      Type Parameters:
      T - type of the value
      Parameters:
      mapperManager - mapper manager to use for mapping types
      name - name of the value
      value - value, must not be null
      type - a more precise type that could be guessed form an instance
      qualifiers - qualifiers of the mapper
      Returns:
      a value backed by data
    • name

      String name()
      Name of this value, to potentially troubleshoot the source of it.
      Returns:
      name of this value, such as "QueryParam("param-name")"
    • get

      T get()
      Typed value.
      Returns:
      direct value
    • get

      default <N> N get(Class<N> type) throws MapperException, NoSuchElementException
      Convert this value to a different type using a mapper.
      Type Parameters:
      N - type we expect
      Parameters:
      type - type to convert to
      Returns:
      converted value
      Throws:
      MapperException - in case the value cannot be converted
      NoSuchElementException - in case the value does not exist
    • get

      default <N> N get(GenericType<N> type) throws MapperException, NoSuchElementException
      Convert this value to a different type using a mapper.
      Type Parameters:
      N - type we expect
      Parameters:
      type - type to convert to
      Returns:
      converted value
      Throws:
      MapperException
      NoSuchElementException
    • as

      <N> Value<N> as(Class<N> type) throws MapperException
      Convert this value to a different type using a mapper.
      Type Parameters:
      N - type we expect
      Parameters:
      type - type to convert to
      Returns:
      converted value
      Throws:
      MapperException - in case the value cannot be converted
    • as

      <N> Value<N> as(GenericType<N> type) throws MapperException
      Convert this value to a different type using a mapper.
      Type Parameters:
      N - type we expect
      Parameters:
      type - type to convert to
      Returns:
      converted value
      Throws:
      MapperException
    • as

      <N> Value<N> as(Function<? super T,? extends N> mapper)
      Convert this Value to a different type using a mapper function.
      Type Parameters:
      N - type of the returned Value
      Parameters:
      mapper - mapper to map the type of this Value to a type of the returned Value
      Returns:
      a new value with the new type
    • asOptional

      Optional<T> asOptional() throws MapperException
      Typed value as Optional. Returns a empty if this value does not have a backing value present. As this class implements all methods of Optional, this is only a utility method if an actual Optional instance is needed (Optional itself is {code final}).
      Returns:
      value as Optional, empty in case the value does not have a direct value
      Throws:
      MapperException - in case the value cannot be converted to the expected type
      See Also:
    • filter

      default Optional<T> filter(Predicate<? super T> predicate)
      If a value is present, and the value matches the given predicate, return an Optional describing the value, otherwise return an empty Optional.

      Parameters:
      predicate - a predicate to apply to the value, if present
      Returns:
      an Optional describing the value of this Optional if a value is present and the value matches the given predicate, otherwise an empty Optional
      Throws:
      NullPointerException - if the predicate is null
      See Also:
    • flatMap

      default <U> Optional<U> flatMap(Function<? super T,Optional<? extends U>> mapper)
      Apply the provided Optional-bearing mapping function to this value, return that result.
      Type Parameters:
      U - The type parameter to the Optional returned by
      Parameters:
      mapper - a mapping function to apply to the value, if present the mapping function
      Returns:
      the result of applying an Optional-bearing mapping function to this value
      Throws:
      NullPointerException - if the mapping function is null or returns a null result
      See Also:
    • stream

      default Stream<T> stream()
      If a value is present, returns a sequential Stream containing only that value, otherwise returns an empty Stream.
      Returns:
      the optional value as a Stream
    • asBoolean

      Value<Boolean> asBoolean()
      Boolean typed value.
      Returns:
      typed value
    • getBoolean

      default boolean getBoolean()
      Boolean typed value.
      Returns:
      boolean value
    • asString

      Value<String> asString()
      String typed value.
      Returns:
      typed value
    • getString

      default String getString()
      String typed value.
      Returns:
      string value
    • asInt

      Value<Integer> asInt()
      Integer typed value.
      Returns:
      typed value
    • getInt

      default int getInt()
      Integer typed value.
      Returns:
      integer value
    • asLong

      Value<Long> asLong()
      Long typed value.
      Returns:
      typed value
    • getLong

      default long getLong()
      Long typed value.
      Returns:
      long value
    • asDouble

      Value<Double> asDouble()
      Double typed value.
      Returns:
      typed value
    • getDouble

      default double getDouble()
      Double typed value.
      Returns:
      double value