Interface ConfigValue<T>
- Type Parameters:
T- type of the value
- All Superinterfaces:
OptionalValue<T>, Value<T>
Config node.
You can use accessor methods on Config to obtain this value, such as Config.as(Class).
It provides Optional-style access to the value.
In addition it has methods to access config values as supplier().
- See Also:
-
Method Summary
Modifier and TypeMethodDescription<N> ConfigValue<N> Convert thisConfigValueto a different type using a mapper function.default Tget()Typed value of the representedConfignode.key()Returns the fully-qualified key of the originatingConfignode.default Stringname()Returns the last token of the fully-qualified key for the originatingConfignode.Returns aSupplierof anOptional<T>of the configuration node.supplier()Returns a supplier of a typed value.Returns a supplier of a typed value with a default.Methods inherited from interface OptionalValue
as, as, asBoolean, asDouble, asInt, asLong, asString, ifPresent, ifPresentOrElse, isEmpty, isPresent, map, or, orElse, orElseGet, orElseThrow, orElseThrowModifier 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.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.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.Methods inherited from interface Value
asOptional, filter, flatMap, get, get, getBoolean, getDouble, getInt, getLong, getString, streamModifier and TypeMethodDescriptionTyped value asOptional.If a value is present, and the value matches the given predicate, return anOptionaldescribing the value, otherwise return an emptyOptional.default <U> Optional<U> Apply the providedOptional-bearing mapping function to this value, return that result.default <N> Nget(GenericType<N> type) Convert this value to a different type using a mapper.default <N> NConvert this value to a different type using a mapper.default booleanBoolean typed value.default doubleDouble typed value.default intgetInt()Integer typed value.default longgetLong()Long typed value.default StringString typed value.stream()If a value is present, returns a sequentialStreamcontaining only that value, otherwise returns an emptyStream.
-
Method Details
-
key
Config.Key key()Returns the fully-qualified key of the originatingConfignode.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). Seename()for more information on the format of each token.- Returns:
- current config node key
- See Also:
-
name
Returns the last token of the fully-qualified key for the originatingConfignode.The name of a node is the last token in its fully-qualified key.
The exact format of the name depends on the
Typeof the containing node:- from a
Config.Type.OBJECTnode the token for a child is the name of the object member; - from a
Config.Type.LISTnode 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 - from a
-
get
Typed value of the representedConfignode. ThrowsMissingValueExceptionif the node isConfig.Type.MISSINGtype.- Specified by:
getin interfaceOptionalValue<T>- Specified by:
getin interfaceValue<T>- Returns:
- direct value of this node converted to the expected type
- Throws:
MissingValueException- in case the node isConfig.Type.MISSING.ConfigMappingException- in case the value cannot be converted to the expected type
-
as
Convert thisConfigValueto a different type using a mapper function. -
supplier
Returns a supplier of a typed value. The value provided from the supplier is the latest value available. E.g. in case there is a file config source that is being watched and a value is changed, this supplier would return the latest value, whereasget()would return the original value.Note that
Supplier.get()can throw aConfigMappingExceptionorMissingValueExceptionas theget()method.- Returns:
- a supplier of a typed value
-
supplier
Returns a supplier of a typed value with a default. The value provided from the supplier is the latest value available. E.g. in case there is a file config source that is being watched and a value is changed, this supplier would return the latest value, whereasOptionalValue.orElse(Object)would return the original value.Note that
Supplier.get()can throw aConfigMappingExceptionas theOptionalValue.orElse(Object)method.- Parameters:
defaultValue- a value to be returned if the supplied value represents aConfignode that has no direct value- Returns:
- a supplier of a typed value
-
optionalSupplier
-