T - type of the valuepublic interface ConfigValue<T>
Config node.
You can use accessor methods on Config to obtain this value, such as Config.as(Class).
A typed value that has all the methods of Optional - including the ones added in JDK9 and newer.
In addition it has methods to access config values as supplier().
| Modifier and Type | Method and Description |
|---|---|
<N> ConfigValue<N> |
as(Function<T,N> mapper)
Convert this
ConfigValue to a different type using a mapper function. |
Optional<T> |
asOptional()
Returns a typed value as
Optional. |
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. |
default <U> Optional<U> |
flatMap(Function<? super T,Optional<U>> mapper)
If a value is present, apply the provided
Optional-bearing
mapping function to it, return that result, otherwise return an empty
Optional. |
default T |
get()
Typed value of the represented
Config node. |
default void |
ifPresent(Consumer<? super T> consumer)
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 |
isPresent()
Return
true if there is a value present, otherwise false. |
Config.Key |
key()
Returns the fully-qualified key of the originating
Config node. |
default <U> Optional<U> |
map(Function<? super T,? extends U> mapper)
If a value is present, apply the provided mapping function to it,
and if the result is non-null, return an
Optional describing the
result. |
default String |
name()
Returns the last token of the fully-qualified key for the originating
Config
node. |
Supplier<Optional<T>> |
optionalSupplier()
Returns a
Supplier of an Optional<T> of the configuration node. |
default Optional<T> |
or(Supplier<? extends Optional<T>> supplier)
If the underlying
Optional does not have a value, set it to the
Optional produced by the supplying function. |
default T |
orElse(T other)
Return the value if present, otherwise return
other. |
default T |
orElseGet(Supplier<? extends T> other)
Return the value if present, otherwise invoke
other and return
the result of that invocation. |
default <X extends Throwable> |
orElseThrow(Supplier<? extends X> exceptionSupplier)
Return the contained value, if present, otherwise throw an exception
to be created by the provided supplier.
|
default Stream<T> |
stream()
If a value is present, returns a sequential
Stream containing
only that value, otherwise returns an empty Stream. |
Supplier<T> |
supplier()
Returns a supplier of a typed value.
|
Supplier<T> |
supplier(T defaultValue)
Returns a supplier of a typed value with a default.
|
Config.Key key()
Config node.
The fully-qualified key is a sequence of tokens derived from the name of
each node along the path from the config root to the current node. Tokens
are separated by . (the dot character). See name() for
more information on the format of each token.
name()default String name()
Config
node.
The name of a node is the last token in its fully-qualified key.
The exact format of the name depends on the Type of the
containing node:
Config.Type.OBJECT node the token for a child is the
name of the object member;Config.Type.LIST node the token for a child is a zero-based
index of the element, an unsigned base-10 integer value
with no leading zeros.The ABNF syntax of config key is:
config-key = *1( key-token *( "." key-token ) )
key-token = *( unescaped / escaped )
unescaped = %x00-2D / %x2F-7D / %x7F-10FFFF
; %x2E ('.') and %x7E ('~') are excluded from 'unescaped'
escaped = "~" ( "0" / "1" )
; representing '~' and '.', respectively
key(),
Config.Key.name()Optional<T> asOptional() throws ConfigMappingException
Optional.
Returns a empty for nodes without a value.
As this class implements all methods of Optional, this is only a utility method if an actual Optional
instance is needed.Optional, empty in case the node does not have
a direct valueConfigMappingException - in case the value cannot be converted to the expected typeget()default T get() throws MissingValueException, ConfigMappingException
Config node.
Throws MissingValueException if the node is Config.Type.MISSING type.MissingValueException - in case the node is Config.Type.MISSING.ConfigMappingException - in case the value cannot be converted to the expected type<N> ConfigValue<N> as(Function<T,N> mapper)
ConfigValue to a different type using a mapper function.N - type of the returned ConfigValuemapper - mapper to map the type of this ConfigValue to a type of the returned ConfigValueSupplier<T> supplier()
get() would return the original value.
Note that Supplier.get() can throw a ConfigMappingException or MissingValueException as the
get() method.
Supplier<T> supplier(T defaultValue)
orElse(Object) would return the original value.
Note that Supplier.get() can throw a ConfigMappingException as the
orElse(Object) method.
defaultValue - a value to be returned if the supplied value represents a Config node that has no direct
valueSupplier<Optional<T>> optionalSupplier()
Supplier of an Optional<T> of the configuration node.
Supplier returns a empty if the node does not have a direct value.Optional typed instance, empty in case the node
does not have a direct valueasOptional(),
supplier()default Optional<T> or(Supplier<? extends Optional<T>> supplier)
Optional does not have a value, set it to the
Optional produced by the supplying function.supplier - the supplying function that produces an OptionalOptionalHelper with the same
the underlying Optional if a value is present, otherwise
with the Optional produced by the supplying function.NullPointerException - if the supplying function is null or
produces a null resultdefault boolean isPresent()
true if there is a value present, otherwise false.
Copied from Optional. You can get real optional from asOptional().
true if there is a value present, otherwise falseOptional.isPresent()default void ifPresentOrElse(Consumer<T> action, Runnable emptyAction)
action - the action to be performed, if a value is presentemptyAction - the empty-based action to be performed, if no value is
presentNullPointerException - if a value is present and the given action
is null, or no value is present and the given empty-based
action is null.default void ifPresent(Consumer<? super T> consumer)
Copied from Optional. You can get real optional from asOptional().
consumer - block to be executed if a value is presentNullPointerException - if value is present and consumer is
nullOptional.ifPresent(Consumer)default Optional<T> filter(Predicate<? super T> predicate)
Optional describing the value, otherwise return an
empty Optional.
Copied from Optional. You can get real optional from asOptional().
predicate - a predicate to apply to the value, if presentOptional describing the value of this Optional
if a value is present and the value matches the given predicate,
otherwise an empty OptionalNullPointerException - if the predicate is nullOptional.filter(Predicate)default <U> Optional<U> map(Function<? super T,? extends U> mapper)
Optional describing the
result. Otherwise return an empty Optional.U - The type of the result of the mapping functionmapper - a mapping function to apply to the value, if presentOptional describing the result of applying a mapping
function to the value of this Optional, if a value is present,
otherwise an empty OptionalNullPointerException - if the mapping function is null
Copied from Optional. You can get real optional from asOptional().
Optional.map(Function)default <U> Optional<U> flatMap(Function<? super T,Optional<U>> mapper)
Optional-bearing
mapping function to it, return that result, otherwise return an empty
Optional. This method is similar to map(Function),
but the provided mapper is one whose result is already an Optional,
and if invoked, flatMap does not wrap it with an additional
Optional.
Copied from Optional. You can get real optional from asOptional().
U - The type parameter to the Optional returned bymapper - a mapping function to apply to the value, if present
the mapping functionOptional-bearing mapping
function to the value of this Optional, if a value is present,
otherwise an empty OptionalNullPointerException - if the mapping function is null or returns
a null resultOptional.flatMap(Function)default T orElse(T other)
other.
Copied from Optional. You can get real optional from asOptional().
other - the value to be returned if there is no value present, may
be nullotherOptional.orElse(Object)default T orElseGet(Supplier<? extends T> other)
other and return
the result of that invocation.
Copied from Optional. You can get real optional from asOptional().
other - a Supplier whose result is returned if no value
is presentother.get()NullPointerException - if value is not present and other is
nullOptional.orElseGet(Supplier)default <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X extends Throwable
Copied from Optional. You can get real optional from asOptional().
X - Type of the exception to be thrownexceptionSupplier - The supplier which will return the exception to
be thrownX - if there is no value presentNullPointerException - if no value is present and
exceptionSupplier is nullX extends ThrowableOptional.orElseThrow(Supplier)Copyright © 2018–2019 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms.