- Type Parameters:
T
- type of the value
- All Superinterfaces:
Value<T>
- All Known Subinterfaces:
ConfigValue<T>
,ConfigValue<T>
A typed value with support for mapping (conversion) to other types.
-
Method Summary
Modifier and TypeMethodDescription<N> OptionalValue
<N> as
(GenericType<N> type) Convert this value to a different type using a mapper.<N> OptionalValue
<N> Convert this value to a different type using a mapper.<N> OptionalValue
<N> Convert thisValue
to a different type using a mapper function.default OptionalValue
<Boolean> Boolean typed value.default OptionalValue
<Double> asDouble()
Double typed value.default OptionalValue
<Integer> asInt()
Integer typed value.default OptionalValue
<Long> asLong()
Long typed value.default OptionalValue
<String> asString()
String typed value.static <T> OptionalValue
<T> create
(MapperManager mapperManager, String name, GenericType<T> type, String... qualifiers) Create an empty value.static <T> OptionalValue
<T> create
(MapperManager mapperManager, String name, Class<T> type, String... qualifiers) Create an empty value.static <T> OptionalValue
<T> create
(MapperManager mapperManager, String name, T value, GenericType<T> type, String... qualifiers) Create a value backed by data.static <T> OptionalValue
<T> create
(MapperManager mapperManager, String name, T value, String... qualifiers) Create a value backed by data.get()
Typed value.default void
If a value is present, invoke the specified consumer with the value, otherwise do nothing.default void
ifPresentOrElse
(Consumer<T> action, Runnable emptyAction) If a value is present, performs the given action with the value, otherwise performs the given empty-based action.default boolean
isEmpty()
Returnfalse
if there is a value present, otherwisetrue
.default boolean
Returntrue
if there is a value present, otherwisefalse
.default <U> Optional
<U> If a value is present, apply the provided mapping function to it, and if the result is non-null, return anOptional
describing the result.If the underlyingOptional
does not have a value, set it to theOptional
produced by the supplying function.default T
Return the value if present, otherwise returnother
.default T
Return the value if present, otherwise invokeother
and return the result of that invocation.default T
If a value is present, returns the value, otherwise throwsNoSuchElementException
.orElseThrow
(Supplier<? extends X> exceptionSupplier) Return the contained value, if present, otherwise throw an exception to be created by the provided supplier.
-
Method Details
-
create
static <T> OptionalValue<T> create(MapperManager mapperManager, String name, Class<T> type, String... qualifiers) Create an empty value. Empty value is not backed by data and all of its methods consider it is empty.- Type Parameters:
T
- type of the value- Parameters:
mapperManager
- mapper manager to use for mapping typesname
- name of the valuetype
- type of the value, to correctly handle mapping exceptionsqualifiers
- qualifiers of the mapper- Returns:
- an empty value
-
create
static <T> OptionalValue<T> create(MapperManager mapperManager, String name, GenericType<T> type, String... qualifiers) Create an empty value. Empty value is not backed by data and all of its methods consider it is empty.- Type Parameters:
T
- type of the value- Parameters:
mapperManager
- mapper manager to use for mapping typesname
- name of the valuetype
- type of the value, to correctly handle mapping exceptionsqualifiers
- qualifiers of the mapper- Returns:
- an empty value
-
create
static <T> OptionalValue<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 typesname
- name of the valuevalue
- value, must not be nullqualifiers
- qualifiers of the mapper- Returns:
- a value backed by data
-
create
static <T> OptionalValue<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
-
as
Description copied from interface:Value
Convert this value to a different type using a mapper. -
as
Description copied from interface:Value
Convert this value to a different type using a mapper. -
as
Description copied from interface:Value
Convert thisValue
to a different type using a mapper function. -
get
T get()Typed value.- Specified by:
get
in interfaceValue<T>
- Returns:
- direct value converted to the expected type
- Throws:
NoSuchElementException
- or appropriate module specific exception if the value is not present
-
or
If the underlyingOptional
does not have a value, set it to theOptional
produced by the supplying function.- Parameters:
supplier
- the supplying function that produces anOptional
- Returns:
- returns current value using
Value.asOptional()
if present, otherwise value produced by the supplying function. - Throws:
NullPointerException
- if the supplying function isnull
or produces anull
result
-
isPresent
default boolean isPresent()Returntrue
if there is a value present, otherwisefalse
.Copied from
Optional
. You can get real optional fromValue.asOptional()
.- Returns:
true
if there is a value present, otherwisefalse
- See Also:
-
isEmpty
default boolean isEmpty()Returnfalse
if there is a value present, otherwisetrue
.Copied from
Optional
. You can get real optional fromValue.asOptional()
.- Returns:
false
if there is a value present, otherwisetrue
- See Also:
-
ifPresentOrElse
If a value is present, performs the given action with the value, otherwise performs the given empty-based action.- Parameters:
action
- the action to be performed, if a value is presentemptyAction
- the empty-based action to be performed, if no value is present- Throws:
NullPointerException
- if a value is present and the given action isnull
, or no value is present and the given empty-based action isnull
.
-
ifPresent
If a value is present, invoke the specified consumer with the value, otherwise do nothing.Copied from
Optional
. You can get real optional fromValue.asOptional()
.- Parameters:
consumer
- block to be executed if a value is present- Throws:
NullPointerException
- if value is present andconsumer
is null- See Also:
-
map
If a value is present, apply the provided mapping function to it, and if the result is non-null, return anOptional
describing the result. Otherwise return an emptyOptional
.- Type Parameters:
U
- The type of the result of the mapping function- Parameters:
mapper
- a mapping function to apply to the value, if present- Returns:
- an
Optional
describing the result of applying a mapping function to the value of thisOptional
, if a value is present, otherwise an emptyOptional
- Throws:
NullPointerException
- if the mapping function is nullCopied from
Optional
. You can get real optional fromValue.asOptional()
.- See Also:
-
orElse
Return the value if present, otherwise returnother
.Copied from
Optional
. You can get real optional fromValue.asOptional()
.- Parameters:
other
- the value to be returned if there is no value present, may be null- Returns:
- the value, if present, otherwise
other
- See Also:
-
orElseGet
Return the value if present, otherwise invokeother
and return the result of that invocation.Copied from
Optional
. You can get real optional fromValue.asOptional()
.- Parameters:
other
- aSupplier
whose result is returned if no value is present- Returns:
- the value if present otherwise the result of
other.get()
- Throws:
NullPointerException
- if value is not present andother
is null- See Also:
-
orElseThrow
Return the contained value, if present, otherwise throw an exception to be created by the provided supplier.Copied from
Optional
. You can get real optional fromValue.asOptional()
.- Type Parameters:
X
- Type of the exception to be thrown- Parameters:
exceptionSupplier
- The supplier which will return the exception to be thrown- Returns:
- the present value
- Throws:
X
- if there is no value presentNullPointerException
- if no value is present andexceptionSupplier
is null- See Also:
-
orElseThrow
If a value is present, returns the value, otherwise throwsNoSuchElementException
.- Returns:
- the non-
null
value described by this value - Throws:
NoSuchElementException
- if no value is present
-
asBoolean
Description copied from interface:Value
Boolean typed value. -
asString
Description copied from interface:Value
String typed value. -
asInt
Description copied from interface:Value
Integer typed value. -
asLong
Description copied from interface:Value
Long typed value. -
asDouble
Description copied from interface:Value
Double typed value.
-