- 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 Summary
Modifier and TypeMethodDescription<N> Value
<N> as
(GenericType<N> type) Convert this value to a different type using a mapper.<N> Value
<N> Convert this value to a different type using a mapper.<N> Value
<N> Convert thisValue
to a different type using a mapper function.Boolean typed value.asDouble()
Double typed value.asInt()
Integer typed value.asLong()
Long typed value.Typed value asOptional
.asString()
String typed value.static <T> Value
<T> create
(MapperManager mapperManager, String name, T value, GenericType<T> type, String... qualifiers) Create a value backed by data.static <T> Value
<T> create
(MapperManager mapperManager, String name, T value, String... qualifiers) Create a value backed by data.If a value is present, and the value matches the given predicate, return anOptional
describing the value, otherwise return an emptyOptional
.default <U> Optional
<U> Apply the providedOptional
-bearing mapping function to this value, return that result.get()
Typed value.default <N> N
get
(GenericType<N> type) Convert this value to a different type using a mapper.default <N> N
Convert this value to a different type using a mapper.default boolean
Boolean typed value.default double
Double typed value.default int
getInt()
Integer typed value.default long
getLong()
Long typed value.default String
String typed value.name()
Name of this value, to potentially troubleshoot the source of it.stream()
If a value is present, returns a sequentialStream
containing only that value, otherwise returns an emptyStream
.
-
Method Details
-
create
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 typesname
- name of the valuevalue
- value, must not be nullqualifiers
- 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 typesname
- name of the valuevalue
- value, must not be nulltype
- a more precise type that could be guessed form an instancequalifiers
- 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
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 convertedNoSuchElementException
- in case the value does not exist
-
get
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
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
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
Convert thisValue
to a different type using a mapper function.- Type Parameters:
N
- type of the returnedValue
- Parameters:
mapper
- mapper to map the type of thisValue
to a type of the returnedValue
- Returns:
- a new value with the new type
-
asOptional
Typed value asOptional
. Returns aempty
if this value does not have a backing value present. As this class implements all methods ofOptional
, this is only a utility method if an actualOptional
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
If a value is present, and the value matches the given predicate, return anOptional
describing the value, otherwise return an emptyOptional
.- Parameters:
predicate
- a predicate to apply to the value, if present- Returns:
- an
Optional
describing the value of thisOptional
if a value is present and the value matches the given predicate, otherwise an emptyOptional
- Throws:
NullPointerException
- if the predicate is null- See Also:
-
flatMap
Apply the providedOptional
-bearing mapping function to this value, return that result.- Type Parameters:
U
- The type parameter to theOptional
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
If a value is present, returns a sequentialStream
containing only that value, otherwise returns an emptyStream
.- Returns:
- the optional value as a
Stream
-
asBoolean
Boolean typed value.- Returns:
- typed value
-
getBoolean
default boolean getBoolean()Boolean typed value.- Returns:
- boolean value
-
asString
String typed value.- Returns:
- typed value
-
getString
String typed value.- Returns:
- string value
-
asInt
Integer typed value.- Returns:
- typed value
-
getInt
default int getInt()Integer typed value.- Returns:
- integer value
-
asLong
Long typed value.- Returns:
- typed value
-
getLong
default long getLong()Long typed value.- Returns:
- long value
-
asDouble
Double typed value.- Returns:
- typed value
-
getDouble
default double getDouble()Double typed value.- Returns:
- double value
-