- 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 thisValueto 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 voidIf a value is present, invoke the specified consumer with the value, otherwise do nothing.default voidifPresentOrElse(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 booleanisEmpty()Returnfalseif there is a value present, otherwisetrue.default booleanReturntrueif 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 anOptionaldescribing the result.If the underlyingOptionaldoes not have a value, set it to theOptionalproduced by the supplying function.default TReturn the value if present, otherwise returnother.default TReturn the value if present, otherwise invokeotherand return the result of that invocation.default TIf 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:ValueConvert this value to a different type using a mapper. -
as
Description copied from interface:ValueConvert this value to a different type using a mapper. -
as
Description copied from interface:ValueConvert thisValueto a different type using a mapper function. -
get
T get()Typed value.- Specified by:
getin 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 underlyingOptionaldoes not have a value, set it to theOptionalproduced 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 isnullor produces anullresult
-
isPresent
default boolean isPresent()Returntrueif there is a value present, otherwisefalse.Copied from
Optional. You can get real optional fromValue.asOptional().- Returns:
trueif there is a value present, otherwisefalse- See Also:
-
isEmpty
default boolean isEmpty()Returnfalseif there is a value present, otherwisetrue.Copied from
Optional. You can get real optional fromValue.asOptional().- Returns:
falseif 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 andconsumeris null- See Also:
-
map
If a value is present, apply the provided mapping function to it, and if the result is non-null, return anOptionaldescribing 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
Optionaldescribing 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 invokeotherand return the result of that invocation.Copied from
Optional. You can get real optional fromValue.asOptional().- Parameters:
other- aSupplierwhose 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 andotheris 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 andexceptionSupplieris null- See Also:
-
orElseThrow
If a value is present, returns the value, otherwise throwsNoSuchElementException.- Returns:
- the non-
nullvalue described by this value - Throws:
NoSuchElementException- if no value is present
-
asBoolean
Description copied from interface:ValueBoolean typed value. -
asString
Description copied from interface:ValueString typed value. -
asInt
Description copied from interface:ValueInteger typed value. -
asLong
Description copied from interface:ValueLong typed value. -
asDouble
Description copied from interface:ValueDouble typed value.
-