public interface Config
create() method.
Config config = Config.create();
Use Config.Builder to construct a new Config instance
from one or more specific ConfigSources.
The application can affect the way the system loads configuration by
implementing interfaces defined in the SPI, by explicitly constructing the
Config.Builder which assembles the Config, and by using other
classes provided by the config system that influence loading.
| Class.Method | Application-implemented Interface | Purpose |
|---|---|---|
ConfigSources.from(io.helidon.config.Config) |
ConfigSource |
Loads configuration from a different type of origin. Each
ConfigSource implementation handles a type of location. Different
instances of a given ConfigSource implementation represent separate
sources of that location type. |
Config.Builder.addParser(io.helidon.config.spi.ConfigParser) |
ConfigParser |
Converts one format of config representation into the corresponding
Config tree.
|
Config.Builder.addFilter(io.helidon.config.spi.ConfigFilter) |
ConfigFilter |
Changes the String representation of each config value from one
String to another as the Config tree is built from its
sources. |
OverrideSources methods |
Replaces config String values during loading based on their keys.
Programs provide overrides in Java property file format on the classpath, at
a URL, or in a file, or by invoking OverrideSources.from(java.util.Map<java.lang.String, java.lang.String>) and passing
the name-matching expressions and the corresponding replacement value as a
Map. |
|
Config.Builder.addMapper(java.lang.Class<T>, io.helidon.config.ConfigMapper<T>) |
ConfigMapper |
Implements conversion from a Config node (typically with
children) to an application-specific Java type. |
Config objects. The
application can access an arbitrary node in the tree by passing its
fully-qualified name to get(java.lang.String):
Config greeting = config.get("greeting");
Method key() always returns fully-qualified
Config.Key of a config node.
assert greeting.key().toString().equals("greeting")
These are equivalent ways of obtaining the same Config
instance, and the two assertions will succeed:
Config name1 = config.get("app.services.svc1.name");
Config name2 = config.get("app").get("services.svc1.name");
Config name3 = config.get("app.services").get("svc1").get("name");
Config name4 = config.get("app").get("services").get("svc1").get("name");
assert name4.key().equals(Key.from("app.services.svc1.name"))
assert name1 == name2 == name3 == name4
The get(java.lang.String) method always returns a Config object, even
if no configuration is present using the corresponding key. The application
can invoke the type() method to find out the type of the node,
represented by one of the Config.Type enum values. The exists()
method tells whether or not the Config node represents existing
configuration.
if (!config.get("very.rare.prop42").exists()) {
// node 'very.rare.prop42' does NOT exist
}
The traverse() method visits all nodes in a subtree. This
example gathers all nodes with keys matching logging.**.level -- that
is, all nodes within the "logging" subtree that have a key ending in "level"
and also has a single value:
Map<String,String> loggingLevels = config.get("logging") // find "logging" subtree
.traverse() // traverse through logging' nodes
.filter(node -> node.isLeaf()) // filter leaf values
.filter(node -> node.name().equals("level")) // filter key suffix '.level'
.collect(Collectors.toMap(Config::key, Config::asString));
To retrieve children of a config node use
nodeList(), asNodeList() or asNodeList(List)
On a leaf value node get the String value using
value(), asString() or asString(String).
String the application can invoke one of these convenience methods:
as<typename> such as asBoolean, asDouble, asInt, etc.
which return Java primitive data values (boolean, double, int, etc.)
Each method has two variants: one without parameters that throws
MissingValueException if the config at the node does not exist, and
one that accepts the default value as a single parameter. For example:
long l1 = config.asLong();
long l2 = config.asLong(42L);
asOptional<typename> which returns the autoboxed datatype wrapped
in an Optional.
For example:
Optional<Long> l3 = config.asOptionalLong();
as(Class) or as(Class, defaultValue) or
asOptional(Class) which return an instance of the requested type.
For example:
Long l1 = config.as(Long.class);
Long l2 = config.as(Long.class, 42L);
Optional<Long> l3 = config.asOptional(Long.class);
as* method delegates to a ConfigMapper to convert a
config node to a type. The config system provides mappers for primitive
datatypes, Lists, and Maps, and automatically registers them
with each Config.Builder instance.
To deal with application-specific types, the application can provide its own mapping logic by:
map(java.util.function.Function<java.lang.String, ? extends T>) method variants, ConfigMapper implementations using the
Config.Builder.addMapper(java.lang.Class<T>, io.helidon.config.ConfigMapper<T>) method,ConfigMapper for details.)
Returning to the long example:
long l4 = config.map(ConfigMappers::toLong);
long l5 = config.map(ConfigMappers::toLong, 42L);
Optional<Long> l6 = config.mapOptional(ConfigMappers::toLong);
Note that the variants of map accept a Function or a
ConfigMapper. The ConfigMappers class implements many useful
conversions; check there before writing your own custom mapper.
If there is no explicitly registered ConfigMapper instance in a
Config.Builder for converting a given type then the config system uses
generic mapping. See ConfigMapperManager for details on how generic
mapping works.
Config instance, including the default Config returned by
create(), might be associated with multiple ConfigSources. The
config system deals with multiple sources as follows.
The ConfigSources.CompositeBuilder class handles multiple config
sources; in fact the config system uses an instance of that builder
automatically when your application invokes from(java.util.function.Supplier<io.helidon.config.spi.ConfigSource>...) and
withSources(java.util.function.Supplier<io.helidon.config.spi.ConfigSource>...), for example. Each such composite builder has a
merging strategy that controls how the config system will search the multiple
config sources for a given key. By default each CompositeBuilder uses
the FallbackMergingStrategy: configuration sources earlier in the
list have a higher priority than the later ones. The system behaves as if,
when resolving a value of a key, it checks each source in sequence order. As
soon as one source contains a value for the key the system returns that
value, ignoring any sources that fall later in the list.
Your application can set a different strategy by constructing its own
CompositeBuilder and invoking
ConfigSources.CompositeBuilder.mergingStrategy, passing the strategy
to be used:
Config.withSources(ConfigSources.from(source1, source2, source3)
.mergingStrategy(new MyMergingStrategy());
| Modifier and Type | Interface | Description |
|---|---|---|
static interface |
Config.Builder |
Config Builder. |
static interface |
Config.Context |
Context associated with specific
Config node that allows to access the last loaded instance of the node
or to request reloading of whole configuration. |
static interface |
Config.Key |
Object represents fully-qualified key of config node.
|
static interface |
Config.Transient |
Annotation used to exclude JavaBean property, method or constructor from JavaBean deserialization support.
|
static class |
Config.Type |
Configuration node types.
|
static interface |
Config.Value |
Annotation used to customize behaviour of JavaBean deserialization support, generic
ConfigMapper
implementation. |
| Modifier and Type | Method | Description |
|---|---|---|
default <T> T |
as(java.lang.Class<? extends T> type) |
Returns typed value as a specified type.
|
default <T> T |
as(java.lang.Class<? extends T> type,
T defaultValue) |
Returns typed value as a specified type.
|
default boolean |
asBoolean() |
Returns a
boolean value of configuration node if the node is Config.Type.VALUE
and original value() can be mapped to. |
default boolean |
asBoolean(boolean defaultValue) |
Returns a
boolean value of configuration node if the node is Config.Type.VALUE
and original value() can be mapped to. |
default java.util.function.Supplier<java.lang.Boolean> |
asBooleanSupplier() |
Returns a supplier of a
Boolean value of this configuration node. |
default java.util.function.Supplier<java.lang.Boolean> |
asBooleanSupplier(boolean defaultValue) |
Returns a supplier of a
Boolean value of this configuration node or a default value. |
default double |
asDouble() |
Returns a
double value of configuration node if the node is Config.Type.VALUE
and original value() can be mapped to. |
default double |
asDouble(double defaultValue) |
Returns a
double value of configuration node if the node is Config.Type.VALUE
and original value() can be mapped to. |
default java.util.function.Supplier<java.lang.Double> |
asDoubleSupplier() |
Returns a supplier of a
Double value of this configuration node. |
default java.util.function.Supplier<java.lang.Double> |
asDoubleSupplier(double defaultValue) |
Returns a supplier of a
Double value of this configuration node or a default value. |
default int |
asInt() |
Returns a
int value of configuration node if the node is Config.Type.VALUE
and original value() can be mapped to. |
default int |
asInt(int defaultValue) |
Returns a
int value of configuration node if the node is Config.Type.VALUE
and original value() can be mapped to. |
default java.util.function.Supplier<java.lang.Integer> |
asIntSupplier() |
Returns a supplier of a
Integer value of this configuration node. |
default java.util.function.Supplier<java.lang.Integer> |
asIntSupplier(int defaultValue) |
Returns a supplier of a
Integer value of this configuration node or a default value. |
default <T> java.util.List<T> |
asList(java.lang.Class<? extends T> type) |
Returns list of specified type.
|
default <T> java.util.List<T> |
asList(java.lang.Class<? extends T> type,
java.util.List<T> defaultValue) |
Returns list of specified type.
|
default <T> java.util.function.Supplier<java.util.List<T>> |
asListSupplier(java.lang.Class<? extends T> type) |
Returns a supplier of a list of specified type.
|
default <T> java.util.function.Supplier<java.util.List<T>> |
asListSupplier(java.lang.Class<? extends T> type,
java.util.List<T> defaultValue) |
Returns a supplier of a list of a specified type or a default value.
|
default long |
asLong() |
Returns a
long value of configuration node if the node is Config.Type.VALUE
and original value() can be mapped to. |
default long |
asLong(long defaultValue) |
Returns a
long value of configuration node if the node is Config.Type.VALUE
and original value() can be mapped to. |
default java.util.function.Supplier<java.lang.Long> |
asLongSupplier() |
Returns a supplier of a
Long value of this configuration node. |
default java.util.function.Supplier<java.lang.Long> |
asLongSupplier(long defaultValue) |
Returns a supplier of a
Long value of this configuration node or a default value. |
default java.util.Map<java.lang.String,java.lang.String> |
asMap() |
Transform all leaf nodes (values) into Map instance.
|
default java.util.Map<java.lang.String,java.lang.String> |
asMap(java.util.Map<java.lang.String,java.lang.String> defaultValue) |
Transform all leaf nodes (values) into Map instance.
|
default java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.String>> |
asMapSupplier() |
Returns a supplier of a map with transformed leaf nodes.
|
default java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.String>> |
asMapSupplier(java.util.Map<java.lang.String,java.lang.String> defaultValue) |
Returns a supplier of a map with transformed leaf nodes or a default value if this node is
Config.Type.MISSING. |
default java.util.List<Config> |
asNodeList() |
Returns a list of child
Config nodes if the node is Config.Type.OBJECT. |
default java.util.List<Config> |
asNodeList(java.util.List<Config> defaultValue) |
Returns a list of child
Config nodes if the node is Config.Type.OBJECT. |
default java.util.function.Supplier<java.util.List<Config>> |
asNodeListSupplier() |
Returns a supplier of a list of child nodes when this node is
Config.Type.OBJECT or a list of element nodes for Config.Type.LIST. |
default java.util.function.Supplier<java.util.List<Config>> |
asNodeListSupplier(java.util.List<Config> defaultValue) |
Returns a supplier of a list of child nodes when this node is
Config.Type.OBJECT, a list of element nodes for Config.Type.LIST or defaultValue if this node is Config.Type.MISSING. |
<T> java.util.Optional<T> |
asOptional(java.lang.Class<? extends T> type) |
Returns typed value as a specified type.
|
default java.util.Optional<java.lang.Boolean> |
asOptionalBoolean() |
Maps the node
value() to Optional. |
default java.util.function.Supplier<java.util.Optional<java.lang.Boolean>> |
asOptionalBooleanSupplier() |
Returns a supplier to a value typed as an
Optional. |
default java.util.OptionalDouble |
asOptionalDouble() |
Maps the node
value() to OptionalDouble. |
default java.util.function.Supplier<java.util.OptionalDouble> |
asOptionalDoubleSupplier() |
Returns a supplier to a value typed as an
OptionalDouble. |
default java.util.OptionalInt |
asOptionalInt() |
Maps the node
value() to OptionalInt. |
default java.util.function.Supplier<java.util.OptionalInt> |
asOptionalIntSupplier() |
Returns a supplier to a value typed as an
OptionalInt. |
<T> java.util.Optional<java.util.List<T>> |
asOptionalList(java.lang.Class<? extends T> type) |
Returns list of specified type (single values as well as objects).
|
default <T> java.util.function.Supplier<java.util.Optional<java.util.List<T>>> |
asOptionalListSupplier(java.lang.Class<? extends T> type) |
Returns a supplier of as optional list of typed values.
|
default java.util.OptionalLong |
asOptionalLong() |
Maps the node
value() to OptionalLong. |
default java.util.function.Supplier<java.util.OptionalLong> |
asOptionalLongSupplier() |
Returns a supplier to a value typed as an
OptionalLong. |
java.util.Optional<java.util.Map<java.lang.String,java.lang.String>> |
asOptionalMap() |
Transform all leaf nodes (values) into Map instance.
|
default java.util.function.Supplier<java.util.Optional<java.util.Map<java.lang.String,java.lang.String>>> |
asOptionalMapSupplier() |
Returns a
Supplier of a transformed leaf nodes (values) into a Map instance. |
default java.util.Optional<java.util.List<Config>> |
asOptionalNodeList() |
Returns a list of child
Config nodes if the node is Config.Type.OBJECT. |
default java.util.function.Supplier<java.util.Optional<java.util.List<Config>>> |
asOptionalNodeListSupplier() |
|
default java.util.Optional<java.lang.String> |
asOptionalString() |
|
default java.util.Optional<java.util.List<java.lang.String>> |
asOptionalStringList() |
Returns list of
String. |
default java.util.function.Supplier<java.util.Optional<java.util.List<java.lang.String>>> |
asOptionalStringListSupplier() |
Returns a supplier of as optional list of
String. |
default java.util.function.Supplier<java.util.Optional<java.lang.String>> |
asOptionalStringSupplier() |
Returns a
Supplier of an Optional<String> of the configuration node if the node is Config.Type.VALUE. |
default <T> java.util.function.Supplier<java.util.Optional<T>> |
asOptionalSupplier(java.lang.Class<? extends T> type) |
Returns a supplier of an optional typed value.
|
default java.lang.String |
asString() |
Returns a
String value of configuration node if the node is Config.Type.VALUE. |
default java.lang.String |
asString(java.lang.String defaultValue) |
Returns a
String value of configuration node if the node is Config.Type.VALUE. |
default java.util.List<java.lang.String> |
asStringList() |
|
default java.util.List<java.lang.String> |
asStringList(java.util.List<java.lang.String> defaultValue) |
|
default java.util.function.Supplier<java.util.List<java.lang.String>> |
asStringListSupplier() |
|
default java.util.function.Supplier<java.util.List<java.lang.String>> |
asStringListSupplier(java.util.List<java.lang.String> defaultValue) |
Returns a supplier to a list of
Strings mapped from Config.Type.LIST or Config.Type.OBJECT nodes or a default value. |
default java.util.function.Supplier<java.lang.String> |
asStringSupplier() |
Returns a supplier of a
String value of this configuration node. |
default java.util.function.Supplier<java.lang.String> |
asStringSupplier(java.lang.String defaultValue) |
Returns a supplier of a
String value of this configuration node or a default value. |
default <T> java.util.function.Supplier<T> |
asSupplier(java.lang.Class<? extends T> type) |
Returns a supplier of a typed value.
|
default <T> java.util.function.Supplier<T> |
asSupplier(java.lang.Class<? extends T> type,
T defaultValue) |
Returns a supplier of a typed value.
|
static Config.Builder |
builder() |
Provides a
Config.Builder for creating a Config instance. |
default Flow.Publisher<Config> |
changes() |
Deprecated.
|
default Config.Context |
context() |
Returns the
Context instance associated with the current
Config node that allows the application to access the last loaded
instance of the node or to request that the entire configuration be
reloaded. |
static Config |
create() |
Returns a new default
Config loaded using one of the
configuration files available on the classpath and/or using the runtime
environment. |
Config |
detach() |
Returns a copy of the
Config node with no parent. |
static Config |
empty() |
Returns empty instance of
Config. |
default boolean |
exists() |
Returns
true if the node exists, whether an object, a list, or a
value node. |
static Config |
from(java.util.function.Supplier<ConfigSource>... configSources) |
Creates a new
Config loaded from environment variables, system
properties, and the specified ConfigSources. |
Config |
get(Config.Key key) |
Returns the single sub-node for the specified sub-key.
|
default Config |
get(java.lang.String key) |
Returns the single sub-node for the specified sub-key.
|
boolean |
hasValue() |
Returns
true if this configuration node has a direct value. |
default void |
ifExists(java.util.function.Consumer<Config> action) |
Performs the given action with the config node if node
exists, otherwise does nothing. |
default void |
ifExistsOrElse(java.util.function.Consumer<Config> action,
java.lang.Runnable missingAction) |
Performs the given action with the config node if the node
exists, otherwise performs the specified "missing"
action. |
default boolean |
isLeaf() |
Returns
true if this node exists and is a leaf node (has no
children). |
Config.Key |
key() |
Returns the fully-qualified key of the
Config node. |
static Config.Builder |
loadSources(java.util.function.Supplier<ConfigSource>... metaSources) |
Provides a
Config.Builder for creating a Config based on the
specified ConfigSources representing meta-configurations. |
static Config |
loadSourcesFrom(java.util.function.Supplier<ConfigSource>... metaSources) |
Creates a new
Config loaded from the specified
ConfigSources representing meta-configurations. |
default <T> T |
map(ConfigMapper<? extends T> mapper) |
Returns typed value as a using specified config hierarchy mapper.
|
default <T> T |
map(ConfigMapper<? extends T> mapper,
T defaultValue) |
Returns typed value as a using specified config hierarchy mapper.
|
default <T> T |
map(java.util.function.Function<java.lang.String,? extends T> mapper) |
Returns typed value as a using specified type mapper.
|
default <T> T |
map(java.util.function.Function<java.lang.String,? extends T> mapper,
T defaultValue) |
Returns typed value as a using specified type mapper.
|
default <T> java.util.List<T> |
mapList(ConfigMapper<? extends T> mapper) |
Returns typed list of type provided by specified type mapper.
|
default <T> java.util.List<T> |
mapList(ConfigMapper<? extends T> mapper,
java.util.List<T> defaultValue) |
Returns typed list of type provided by specified type mapper.
|
default <T> java.util.List<T> |
mapList(java.util.function.Function<java.lang.String,? extends T> mapper) |
Returns typed list of type provided by specified config hierarchy mapper.
|
default <T> java.util.List<T> |
mapList(java.util.function.Function<java.lang.String,? extends T> mapper,
java.util.List<T> defaultValue) |
Returns typed list of type provided by specified config hierarchy mapper.
|
default <T> java.util.function.Supplier<java.util.List<T>> |
mapListSupplier(ConfigMapper<? extends T> mapper) |
Returns a supplier of a list of a type provided by a specified type mapper.
|
default <T> java.util.function.Supplier<java.util.List<T>> |
mapListSupplier(ConfigMapper<? extends T> mapper,
java.util.List<T> defaultValue) |
Returns a supplier of a list of a type provided by a specified type mapper or a default value.
|
default <T> java.util.function.Supplier<java.util.List<T>> |
mapListSupplier(java.util.function.Function<java.lang.String,? extends T> mapper) |
Returns a supplier of a list of a type provided by a specified type mapper.
|
default <T> java.util.function.Supplier<java.util.List<T>> |
mapListSupplier(java.util.function.Function<java.lang.String,? extends T> mapper,
java.util.List<T> defaultValue) |
Returns a supplier of a list of a type provided by a specified type mapper or a default value.
|
default <T> java.util.Optional<T> |
mapOptional(ConfigMapper<? extends T> mapper) |
Returns typed value as a using specified type mapper.
|
default <T> java.util.Optional<T> |
mapOptional(java.util.function.Function<java.lang.String,? extends T> mapper) |
Returns typed value as a using specified type mapper.
|
default <T> java.util.Optional<java.util.List<T>> |
mapOptionalList(ConfigMapper<? extends T> mapper) |
Returns typed list of type (single values as well as objects) provided by specified type mapper.
|
default <T> java.util.Optional<java.util.List<T>> |
mapOptionalList(java.util.function.Function<java.lang.String,? extends T> mapper) |
Returns typed list of type (single values as well as objects) provided by specified type mapper.
|
default <T> java.util.function.Supplier<java.util.Optional<java.util.List<T>>> |
mapOptionalListSupplier(ConfigMapper<? extends T> mapper) |
Returns a supplier of an optional typed list of a type (single values as well as objects) provided by a specified type
mapper.
|
default <T> java.util.function.Supplier<java.util.Optional<java.util.List<T>>> |
mapOptionalListSupplier(java.util.function.Function<java.lang.String,? extends T> mapper) |
Returns a supplier of an optional typed list of a type (single values as well as objects) provided by a specified type
mapper.
|
default <T> java.util.function.Supplier<java.util.Optional<T>> |
mapOptionalSupplier(ConfigMapper<? extends T> mapper) |
Returns a supplier of an optional value, typed using a specified type mapper.
|
default <T> java.util.function.Supplier<java.util.Optional<T>> |
mapOptionalSupplier(java.util.function.Function<java.lang.String,? extends T> mapper) |
Returns a supplier of an optional value, typed using a specified type mapper.
|
default <T> java.util.function.Supplier<T> |
mapSupplier(ConfigMapper<? extends T> mapper) |
Returns a supplier of a typed value, using a specified type mapper.
|
default <T> java.util.function.Supplier<T> |
mapSupplier(ConfigMapper<? extends T> mapper,
T defaultValue) |
Returns a supplier of a typed value, using a specified type mapper or a default value.
|
default <T> java.util.function.Supplier<T> |
mapSupplier(java.util.function.Function<java.lang.String,? extends T> mapper) |
Returns a supplier of a typed value, using a specified type mapper.
|
default <T> java.util.function.Supplier<T> |
mapSupplier(java.util.function.Function<java.lang.String,? extends T> mapper,
T defaultValue) |
Returns a supplier of a typed value, using a specified type mapper or a default value.
|
default java.lang.String |
name() |
Returns the last token of the fully-qualified key for the
Config
node. |
default java.util.Optional<Config> |
node() |
Returns existing current config node as a
Optional instance
or Optional.empty() in case of Config.Type.MISSING node. |
java.util.Optional<java.util.List<Config>> |
nodeList() |
Returns a list of child
Config nodes if the node is Config.Type.OBJECT. |
default java.util.function.Supplier<java.util.Optional<Config>> |
nodeSupplier() |
Returns a
Supplier of the configuration node as an Optional<Config> or Optional.empty() if the node is Config.Type.MISSING. |
default void |
onChange(java.util.function.Function<Config,java.lang.Boolean> onNextFunction) |
Directly subscribes
onNextFunction function on change on whole Config or on particular Config node. |
java.time.Instant |
timestamp() |
Returns when the configuration tree was created.
|
default java.util.stream.Stream<Config> |
traverse() |
Iterative deepening depth-first traversal of the node
and its subtree as a
Stream<Config>. |
java.util.stream.Stream<Config> |
traverse(java.util.function.Predicate<Config> predicate) |
Iterative deepening depth-first traversal of the node
and its subtree as a
Stream<Config>, qualified by the specified
predicate. |
Config.Type |
type() |
Provides the
Config.Type of the Config node. |
java.util.Optional<java.lang.String> |
value() |
|
static Config.Builder |
withSources(java.util.function.Supplier<ConfigSource>... configSources) |
static Config empty()
Config.Config.static Config create()
Config loaded using one of the
configuration files available on the classpath and/or using the runtime
environment.
The config system loads the default configuration using a default Config.Builder
which loads configuration data as described below. In contrast, the application can
control how and from where configuration is loaded by explicitly creating and fine-tuning
one or more Builder instances itself.
Meta-configuration specifies at least one ConfigSource or
Config.Builder from which the system can load configuration. The
config system searches for at most one of the following
meta-configuration locations on the classpath, in this order:
meta-config.yaml - meta configuration file in YAML
formatmeta-config.conf - meta configuration file in HOCON
formatmeta-config.json - meta configuration file in JSON
formatmeta-config.properties - meta configuration file in Java
Properties formatIn the absence of meta-configuration the config system loads the default configuration from all of the following sources:
environment variables;system propertiesapplication.yaml - configuration file in YAML formatapplication.conf - configuration file in HOCON formatapplication.json - configuration file in JSON formatapplication.properties - configuration file in Java
Properties formatapplication.* location it
finds for which it can locate a ConfigParser that supports the
corresponding media type.
When creating the default configuration the config system detects parsers
that were loaded using the ServiceLoader mechanism or,
if it finds none loaded, a built-in parser provided by the config system.
Config instance
which has neither a polling strategy nor
a retry policy. To set up these and other
behaviors the application should create explicitly a Config.Builder,
tailor it accordingly, and then use its build method to create the
Config instance as desired.ConfigloadSourcesFrom(Supplier[])@SafeVarargs static Config from(java.util.function.Supplier<ConfigSource>... configSources)
Config loaded from environment variables, system
properties, and the specified ConfigSources.
The resulting configuration uses the following sources, in order:
environment variables config sourceConfig.Builder.disableEnvironmentVariablesSource()system properties config source
Can disabled by Config.Builder.disableSystemPropertiesSource()configSources - ordered list of configuration sourcesConfigloadSourcesFrom(Supplier[]),
withSources(Supplier[]),
loadSources(Supplier[]),
Config.Builder.sources(List),
Config.Builder.disableEnvironmentVariablesSource(),
Config.Builder.disableSystemPropertiesSource(),
ConfigSources.from(Supplier[]),
ConfigSources.CompositeBuilder,
ConfigSources.MergingStrategy@SafeVarargs static Config loadSourcesFrom(java.util.function.Supplier<ConfigSource>... metaSources)
Config loaded from the specified
ConfigSources representing meta-configurations.
See ConfigSource.from(Config) for more information about the
format of meta-configuration.
metaSources - ordered list of meta sourcesConfigfrom(Supplier[]),
withSources(Supplier[]),
loadSources(Supplier[]),
ConfigSources.load(Supplier[])@SafeVarargs static Config.Builder withSources(java.util.function.Supplier<ConfigSource>... configSources)
Config.Builder for creating a Config
based on the specified ConfigSource instances.
The resulting configuration uses the following sources, in order:
environment variablesConfig.Builder.disableEnvironmentVariablesSource()system properties config sourceConfig.Builder.disableSystemPropertiesSource()configSources - ordered list of configuration sourcesbuilder(),
from(Supplier[]),
loadSourcesFrom(Supplier[]),
loadSources(Supplier[]),
Config.Builder.sources(List),
Config.Builder.disableEnvironmentVariablesSource(),
Config.Builder.disableSystemPropertiesSource(),
ConfigSources.from(Supplier[]),
ConfigSources.CompositeBuilder,
ConfigSources.MergingStrategy@SafeVarargs static Config.Builder loadSources(java.util.function.Supplier<ConfigSource>... metaSources)
Config.Builder for creating a Config based on the
specified ConfigSources representing meta-configurations.
Each meta-configuration source should set the sources property to
be an array of config sources. See ConfigSource.from(Config) for
more information about the format of meta-configuration.
metaSources - ordered list of meta sourcesbuilder(),
withSources(Supplier[]),
ConfigSources.load(Supplier[]),
loadSourcesFrom(Supplier[])static Config.Builder builder()
Config.Builder for creating a Config instance.default Config.Context context()
Context instance associated with the current
Config node that allows the application to access the last loaded
instance of the node or to request that the entire configuration be
reloaded.java.time.Instant timestamp()
Each config node of single Config tree returns same timestamp.
context(),
Config.Context.timestamp()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 java.lang.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()default Config get(java.lang.String key)
The format of the key is described on key() method.
key - sub-key of requested sub-nodenull.get(Key)Config get(Config.Key key)
key - sub-key of requested sub-nodenull.get(String)Config detach()
Config node with no parent.
The returned node acts as a root node for the subtree below it. Its key
is the empty string; "". The original config node is unchanged,
and the original and the copy point to the same children.
Consider the following configuration:
app:
name: Example 1
page-size: 20
logging:
app.level = INFO
level = WARNING
The Config instances name1 and name2 represents same data and
in fact refer to the same object:
Config name1 = config
.get("app")
.get("name");
Config name2 = config
.get("app")
.detach() //DETACHED node
.get("name");
assert name1.asString() == "Example 1";
assert name2.asString() == "Example 1"; //DETACHED node
The only difference is the key each node returns:
assert name1.key() == "app.name"; assert name2.key() == "name"; //DETACHED node
See asOptionalMap() for example of config detaching.
Config.Type type()
Config.Type of the Config node.Type of the configuration nodedefault boolean exists()
true if the node exists, whether an object, a list, or a
value node.true if the node existsdefault boolean isLeaf()
true if this node exists and is a leaf node (has no
children).
A leaf node has no nested configuration subtree and has a single value.
true if the node is existing leaf node, false
otherwise.boolean hasValue()
true if this configuration node has a direct value.
This may be a value node (e.g. a leaf) or object node or a list node
(e.g. a branch with value). The application can invoke methods such as
as(Class) on nodes that have value.
true if the node has direct value, false otherwise.default void ifExists(java.util.function.Consumer<Config> action)
exists, otherwise does nothing.default void ifExistsOrElse(java.util.function.Consumer<Config> action, java.lang.Runnable missingAction)
exists, otherwise performs the specified "missing"
action.default java.util.stream.Stream<Config> traverse()
Stream<Config>.
If the config node does not exist or is a leaf the returned stream is empty.
Depending on the structure of the configuration the returned stream can deliver a mix of object, list, and leaf value nodes. The stream will include and traverse through object members and list elements.
java.util.stream.Stream<Config> traverse(java.util.function.Predicate<Config> predicate)
Stream<Config>, qualified by the specified
predicate.
If the config node does not exist or is a leaf the returned stream is empty.
Depending on the structure of the configuration the returned stream can deliver a mix of object, list, and leaf value nodes. The stream will include and traverse through object members and list elements.
The traversal continues as long as the specified predicate
evaluates to true. When the predicate evaluates to false
the node being traversed and its subtree will be excluded from the
returned Stream<Config>.
predicate - predicate evaluated on each visited Config node
to continue or stop visiting the nodejava.util.Optional<java.lang.String> value()
throws ConfigMappingException
String value as Optional of configuration node if the node is Config.Type.VALUE.
Returns a empty if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.Optional, empty in case the node is Config.Type.MISSINGConfigMappingException - in case the node is Config.Type.OBJECT or Config.Type.LISTasOptionalString()default java.util.Optional<java.lang.String> asOptionalString()
throws ConfigMappingException
String value as Optional of configuration node if the node is Config.Type.VALUE.
Returns a empty if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.Optional, empty in case the node is Config.Type.MISSINGConfigMappingException - in case the node is Config.Type.OBJECT or Config.Type.LISTvalue(),
asOptionalStringSupplier()default java.util.function.Supplier<java.util.Optional<java.lang.String>> asOptionalStringSupplier()
Supplier of an Optional<String> of the configuration node if the node is Config.Type.VALUE.
Supplier returns a empty if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.Optional typed instance, empty in case the node is
Config.Type.MISSINGasOptionalString()default java.util.Optional<Config> node()
Optional instance
or Optional.empty() in case of Config.Type.MISSING node.Optional instance
or Optional.empty() in case of Config.Type.MISSING node.nodeSupplier()default java.util.function.Supplier<java.util.Optional<Config>> nodeSupplier()
Supplier of the configuration node as an Optional<Config> or Optional.empty() if the node is Config.Type.MISSING.Supplier of the configuration node as an Optional<Config> or Optional.empty() if the node is Config.Type.MISSINGasOptionalStringSupplier(),
node()java.util.Optional<java.util.List<Config>> nodeList() throws ConfigMappingException
Config nodes if the node is Config.Type.OBJECT.
Returns a list of element nodes if the node is Config.Type.LIST.
Returns an Optional.empty() if the node is Config.Type.MISSING.
Otherwise, if node is Config.Type.VALUE, it throws ConfigMappingException.Config.Type.OBJECT members, list of Config.Type.LIST members
or empty list in case of Config.Type.MISSINGConfigMappingException - in case the node is Config.Type.VALUEasOptionalNodeList()default java.util.Optional<java.util.List<Config>> asOptionalNodeList() throws ConfigMappingException
Config nodes if the node is Config.Type.OBJECT.
Returns a list of element nodes if the node is Config.Type.LIST.
Returns an empty list if the node is Config.Type.MISSING.
Otherwise, if node is Config.Type.VALUE, it throws ConfigMappingException.Config.Type.OBJECT members, list of Config.Type.LIST members
or empty list in case of Config.Type.MISSINGConfigMappingException - in case the node is Config.Type.VALUEnodeList(),
asOptionalNodeListSupplier()default java.util.function.Supplier<java.util.Optional<java.util.List<Config>>> asOptionalNodeListSupplier()
Supplier of a list of child Config nodes if the node is Config.Type.OBJECT.
Returns a Supplier of a list of element nodes if the node is Config.Type.LIST.
Returns a Supplier of an empty list if the node is Config.Type.MISSING.
Otherwise, if node is Config.Type.VALUE, a calling of Supplier.get() causes ConfigMappingException.Config.Type.OBJECT members, a list of Config.Type.LIST members
or an empty list in case of Config.Type.MISSINGnodeList(),
asOptionalNodeList()java.util.Optional<java.util.Map<java.lang.String,java.lang.String>> asOptionalMap()
Fully qualified key of config node is used as a key in returned Map.
Detach config node before transforming to Map in case you want to cut
current Config node key prefix.
Let's say we work with following configuration:
app:
name: Example 1
page-size: 20
logging:
app.level = INFO
level = WARNING
Map app1 contains two keys: app.name, app.page-size.
Map<String, String> app1 = config.get("app").asOptionalMap().get();
Detaching app config node returns new Config instance with "reset" local root.
Map<String, String> app2 = config.get("app").detach().asOptionalMap().get();
Map app2 contains two keys without app prefix: name, page-size.Optional, empty in case of Config.Type.MISSING nodeasMap(),
asMap(Map),
traverse(),
detach()default java.util.function.Supplier<java.util.Optional<java.util.Map<java.lang.String,java.lang.String>>> asOptionalMapSupplier()
Supplier of a transformed leaf nodes (values) into a Map instance.
See asOptionalMap() to more detailed about the result.
asOptionalMap()<T> java.util.Optional<T> asOptional(java.lang.Class<? extends T> type)
throws ConfigMappingException
T - typetype - type classOptional, empty if entry does not have set valueConfigMappingException - in case of problem to map property value.default <T> java.util.function.Supplier<java.util.Optional<T>> asOptionalSupplier(java.lang.Class<? extends T> type)
T - a typetype - a type classOptional, empty if entry does not
have set valueasOptional(Class)<T> java.util.Optional<java.util.List<T>> asOptionalList(java.lang.Class<? extends T> type)
throws ConfigMappingException
T - typetype - type classOptional, empty if entry does not have set valueConfigMappingException - in case of problem to map property value.default <T> java.util.function.Supplier<java.util.Optional<java.util.List<T>>> asOptionalListSupplier(java.lang.Class<? extends T> type)
T - a typetype - a type classasOptionalList(Class)default java.util.Optional<java.util.List<java.lang.String>> asOptionalStringList()
throws ConfigMappingException
String.Optional, empty if entry does not have set valueConfigMappingException - in case of problem to map property value.default java.util.function.Supplier<java.util.Optional<java.util.List<java.lang.String>>> asOptionalStringListSupplier()
String.StringasOptionalStringList()default <T> java.util.Optional<T> mapOptional(java.util.function.Function<java.lang.String,? extends T> mapper)
throws ConfigMappingException
T - typemapper - type mapperOptional, empty if entry does not have set valueConfigMappingException - in case of problem to map property value.default <T> java.util.function.Supplier<java.util.Optional<T>> mapOptionalSupplier(java.util.function.Function<java.lang.String,? extends T> mapper)
T - a typemapper - a type mappermapOptional(Function)default <T> java.util.Optional<T> mapOptional(ConfigMapper<? extends T> mapper) throws ConfigMappingException
T - expected Java typemapper - configuration hierarchy mapper.Optional, empty if entry does not represent an existing
configuration node.ConfigMappingException - in case of problem to map property value.default <T> java.util.function.Supplier<java.util.Optional<T>> mapOptionalSupplier(ConfigMapper<? extends T> mapper)
T - an expected Java typemapper - a configuration mappermapOptional(ConfigMapper)default java.util.Optional<java.lang.Boolean> asOptionalBoolean()
throws ConfigMappingException
value() to Optional.OptionalConfigMappingException - in case it is not possible map the valuedefault java.util.function.Supplier<java.util.Optional<java.lang.Boolean>> asOptionalBooleanSupplier()
Optional.OptionalIntasOptionalBoolean()default java.util.OptionalInt asOptionalInt()
throws ConfigMappingException
value() to OptionalInt.OptionalIntConfigMappingException - in case it is not possible map the valuedefault java.util.function.Supplier<java.util.OptionalInt> asOptionalIntSupplier()
OptionalInt.OptionalIntasOptionalInt()default java.util.OptionalLong asOptionalLong()
throws ConfigMappingException
value() to OptionalLong.OptionalLongConfigMappingException - in case it is not possible map the valuedefault java.util.function.Supplier<java.util.OptionalLong> asOptionalLongSupplier()
OptionalLong.OptionalLongasOptionalLong()default java.util.OptionalDouble asOptionalDouble()
throws ConfigMappingException
value() to OptionalDouble.OptionalDoubleConfigMappingException - in case it is not possible map the valuedefault java.util.function.Supplier<java.util.OptionalDouble> asOptionalDoubleSupplier()
OptionalDouble.OptionalDoubleasOptionalDouble()default <T> java.util.Optional<java.util.List<T>> mapOptionalList(java.util.function.Function<java.lang.String,? extends T> mapper)
throws ConfigMappingException
T - single item typemapper - type mapperOptional, empty if entry does not have set valueConfigMappingException - in case of problem to map property value.default <T> java.util.function.Supplier<java.util.Optional<java.util.List<T>>> mapOptionalListSupplier(java.util.function.Function<java.lang.String,? extends T> mapper)
T - single item typemapper - type mappermapOptionalList(Function)default <T> java.util.Optional<java.util.List<T>> mapOptionalList(ConfigMapper<? extends T> mapper) throws ConfigMappingException
T - single item typemapper - type mapperOptional, empty if entry does not have set valueConfigMappingException - in case of problem to map property value.default <T> java.util.function.Supplier<java.util.Optional<java.util.List<T>>> mapOptionalListSupplier(ConfigMapper<? extends T> mapper)
T - single item typemapper - type mappermapOptionalList(ConfigMapper)default <T> T as(java.lang.Class<? extends T> type)
throws MissingValueException,
ConfigMappingException
T - typetype - type classMissingValueException - in case of the missing value for the key represented by this configuration.ConfigMappingException - in case of problem to map property value.default <T> java.util.function.Supplier<T> asSupplier(java.lang.Class<? extends T> type)
T - typetype - type classas(Class)default <T> T as(java.lang.Class<? extends T> type,
T defaultValue)
throws ConfigMappingException
T - typetype - type classdefaultValue - default valueConfigMappingException - in case of problem to map property value.default <T> java.util.function.Supplier<T> asSupplier(java.lang.Class<? extends T> type,
T defaultValue)
T - a typetype - a type classdefaultValue - a default valueas(Class, Object)default <T> T map(java.util.function.Function<java.lang.String,? extends T> mapper)
throws MissingValueException,
ConfigMappingException
T - typemapper - type mapperMissingValueException - in case of the missing value for the key represented by this configuration.ConfigMappingException - in case of problem to map property value.default <T> java.util.function.Supplier<T> mapSupplier(java.util.function.Function<java.lang.String,? extends T> mapper)
T - a typemapper - a type mappermap(Function)default <T> T map(ConfigMapper<? extends T> mapper) throws MissingValueException, ConfigMappingException
T - typemapper - config hierarchy mapperMissingValueException - in case of the missing value for the key represented by this configuration.ConfigMappingException - in case of problem to map property value.default <T> java.util.function.Supplier<T> mapSupplier(ConfigMapper<? extends T> mapper)
T - a typemapper - a type mappermap(ConfigMapper)default <T> T map(java.util.function.Function<java.lang.String,? extends T> mapper,
T defaultValue)
throws ConfigMappingException
T - typemapper - type mapperdefaultValue - default valueConfigMappingException - in case of problem to map property value.default <T> java.util.function.Supplier<T> mapSupplier(java.util.function.Function<java.lang.String,? extends T> mapper,
T defaultValue)
T - a typemapper - a type mapperdefaultValue - a default valuemap(Function, Object)default <T> T map(ConfigMapper<? extends T> mapper, T defaultValue) throws ConfigMappingException
T - typemapper - config hierarchy mapperdefaultValue - default valueConfigMappingException - in case of problem to map property value.default <T> java.util.function.Supplier<T> mapSupplier(ConfigMapper<? extends T> mapper, T defaultValue)
T - a typemapper - a type mapperdefaultValue - a default valuemap(ConfigMapper, Object)default <T> java.util.List<T> asList(java.lang.Class<? extends T> type)
throws MissingValueException,
ConfigMappingException
T - typetype - type classMissingValueException - in case of the missing value for the key represented by this configuration.ConfigMappingException - in case of problem to map property value.default <T> java.util.function.Supplier<java.util.List<T>> asListSupplier(java.lang.Class<? extends T> type)
T - a typetype - a type classasList(Class)default <T> java.util.List<T> asList(java.lang.Class<? extends T> type,
java.util.List<T> defaultValue)
throws ConfigMappingException
T - typetype - type classdefaultValue - default valueConfigMappingException - in case of problem to map property value.default <T> java.util.function.Supplier<java.util.List<T>> asListSupplier(java.lang.Class<? extends T> type,
java.util.List<T> defaultValue)
T - a typetype - a type classdefaultValue - a default valueasList(Class, List)default <T> java.util.List<T> mapList(ConfigMapper<? extends T> mapper) throws MissingValueException, ConfigMappingException
T - mapped Java typemapper - type mapperMissingValueException - in case of the missing value for the key represented by this configuration.ConfigMappingException - in case of problem to map property value.default <T> java.util.function.Supplier<java.util.List<T>> mapListSupplier(ConfigMapper<? extends T> mapper)
T - a typemapper - a type classmapList(ConfigMapper)default <T> java.util.List<T> mapList(ConfigMapper<? extends T> mapper, java.util.List<T> defaultValue) throws ConfigMappingException
T - mapped Java typemapper - type mapperdefaultValue - default valueConfigMappingException - in case of problem to map property value.default <T> java.util.function.Supplier<java.util.List<T>> mapListSupplier(ConfigMapper<? extends T> mapper, java.util.List<T> defaultValue)
T - a typemapper - a type classdefaultValue - a default valuemapList(ConfigMapper, List)default <T> java.util.List<T> mapList(java.util.function.Function<java.lang.String,? extends T> mapper)
throws MissingValueException,
ConfigMappingException
T - mapped Java typemapper - config hierarchy mapperMissingValueException - in case of the missing value for the key represented by this configuration.ConfigMappingException - in case of problem to map property value.default <T> java.util.function.Supplier<java.util.List<T>> mapListSupplier(java.util.function.Function<java.lang.String,? extends T> mapper)
T - a typemapper - a type classmapList(Function)default <T> java.util.List<T> mapList(java.util.function.Function<java.lang.String,? extends T> mapper,
java.util.List<T> defaultValue)
throws ConfigMappingException
T - mapped Java typemapper - config hierarchy mapperdefaultValue - default valueConfigMappingException - in case of problem to map property value.default <T> java.util.function.Supplier<java.util.List<T>> mapListSupplier(java.util.function.Function<java.lang.String,? extends T> mapper,
java.util.List<T> defaultValue)
T - a typemapper - a type classdefaultValue - a default valuemapList(Function, List)default java.lang.String asString()
throws MissingValueException,
ConfigMappingException
String value of configuration node if the node is Config.Type.VALUE.
Throws MissingValueException if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.Config.Type.VALUE.MissingValueException - in case the node is Config.Type.MISSING.ConfigMappingException - in case the node is Config.Type.OBJECT or Config.Type.LISTdefault java.util.function.Supplier<java.lang.String> asStringSupplier()
String value of this configuration node.
Calling Supplier.get() returns String value when the node is Config.Type.VALUE.
Throws MissingValueException if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.
Config.Type.VALUE.asString()default java.lang.String asString(java.lang.String defaultValue)
throws ConfigMappingException
String value of configuration node if the node is Config.Type.VALUE.
Returns defaultValue if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.defaultValue - default valueConfig.Type.VALUE or defaultValue if the node is Config.Type.MISSING.ConfigMappingException - in case the node is Config.Type.OBJECT or Config.Type.LISTdefault java.util.function.Supplier<java.lang.String> asStringSupplier(java.lang.String defaultValue)
String value of this configuration node or a default value.
Calling Supplier.get() returns String value when the node is Config.Type.VALUE.
Returns a defaultValue if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.
defaultValue - a default valueConfig.Type.VALUE or defaultValue.asString(String)default boolean asBoolean()
throws MissingValueException,
ConfigMappingException
boolean value of configuration node if the node is Config.Type.VALUE
and original value() can be mapped to.
Throws MissingValueException if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.Config.Type.VALUE and can be mappedMissingValueException - in case the node is Config.Type.MISSING.ConfigMappingException - in case the node is Config.Type.OBJECT or Config.Type.LIST, or value cannot be mapped
to.default java.util.function.Supplier<java.lang.Boolean> asBooleanSupplier()
Boolean value of this configuration node.
Calling Supplier.get() returns Boolean value when the node is Config.Type.VALUE.
Throws MissingValueException if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.
Config.Type.VALUE.asBoolean()default boolean asBoolean(boolean defaultValue)
throws ConfigMappingException
boolean value of configuration node if the node is Config.Type.VALUE
and original value() can be mapped to.
Returns defaultValue if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.defaultValue - a default valueConfig.Type.VALUE or defaultValue if the node is Config.Type.MISSING.ConfigMappingException - in case the node is Config.Type.OBJECT or Config.Type.LIST, or value cannot be mapped
to.default java.util.function.Supplier<java.lang.Boolean> asBooleanSupplier(boolean defaultValue)
Boolean value of this configuration node or a default value.
Calling Supplier.get() returns Boolean value when the node is Config.Type.VALUE.
Returns a defaultValue if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.
defaultValue - a default valueConfig.Type.VALUE or defaultValue.asBoolean(boolean)default int asInt()
throws MissingValueException,
ConfigMappingException
int value of configuration node if the node is Config.Type.VALUE
and original value() can be mapped to.
Throws MissingValueException if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.Config.Type.VALUE and can be mappedMissingValueException - in case the node is Config.Type.MISSING.ConfigMappingException - in case the node is Config.Type.OBJECT or Config.Type.LIST, or value cannot be mapped
to.default java.util.function.Supplier<java.lang.Integer> asIntSupplier()
Integer value of this configuration node.
Calling Supplier.get() returns Integer value when the node is Config.Type.VALUE.
Throws MissingValueException if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.
Config.Type.VALUE.asInt()default int asInt(int defaultValue)
throws ConfigMappingException
int value of configuration node if the node is Config.Type.VALUE
and original value() can be mapped to.
Returns defaultValue if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.defaultValue - a default valueConfig.Type.VALUE or defaultValue if the node is Config.Type.MISSING.ConfigMappingException - in case the node is Config.Type.OBJECT or Config.Type.LIST, or value cannot be mapped
to.default java.util.function.Supplier<java.lang.Integer> asIntSupplier(int defaultValue)
Integer value of this configuration node or a default value.
Calling Supplier.get() returns Integer value when the node is Config.Type.VALUE.
Returns a defaultValue if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.
defaultValue - a default valueConfig.Type.VALUE or defaultValue.asInt(int)default long asLong()
throws MissingValueException,
ConfigMappingException
long value of configuration node if the node is Config.Type.VALUE
and original value() can be mapped to.
Throws MissingValueException if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.Config.Type.VALUE and can be mappedMissingValueException - in case the node is Config.Type.MISSING.ConfigMappingException - in case the node is Config.Type.OBJECT or Config.Type.LIST, or value cannot be mapped
to.default java.util.function.Supplier<java.lang.Long> asLongSupplier()
Long value of this configuration node.
Calling Supplier.get() returns Long value when the node is Config.Type.VALUE.
Throws MissingValueException if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.
Config.Type.VALUE.asLong()default long asLong(long defaultValue)
throws ConfigMappingException
long value of configuration node if the node is Config.Type.VALUE
and original value() can be mapped to.
Returns a defaultValue if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.defaultValue - a default valueConfig.Type.VALUE or defaultValue if the node is Config.Type.MISSING.ConfigMappingException - in case the node is Config.Type.OBJECT or Config.Type.LIST, or value cannot be mapped
to.default java.util.function.Supplier<java.lang.Long> asLongSupplier(long defaultValue)
Long value of this configuration node or a default value.
Calling Supplier.get() returns Long value when the node is Config.Type.VALUE.
Returns a defaultValue if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.
defaultValue - a default valueConfig.Type.VALUE or defaultValue.asLong(long)default double asDouble()
throws MissingValueException,
ConfigMappingException
double value of configuration node if the node is Config.Type.VALUE
and original value() can be mapped to.
Throws MissingValueException if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.Config.Type.VALUE and can be mappedMissingValueException - in case the node is Config.Type.MISSING.ConfigMappingException - in case the node is Config.Type.OBJECT or Config.Type.LIST, or value cannot be mapped
to.default java.util.function.Supplier<java.lang.Double> asDoubleSupplier()
Double value of this configuration node.
Calling Supplier.get() returns Double value when the node is Config.Type.VALUE.
Throws MissingValueException if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.
Config.Type.VALUE.asDouble()default double asDouble(double defaultValue)
throws ConfigMappingException
double value of configuration node if the node is Config.Type.VALUE
and original value() can be mapped to.
Returns a defaultValue if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.defaultValue - a default valueConfig.Type.VALUE or defaultValue if the node is Config.Type.MISSING.ConfigMappingException - in case the node is Config.Type.OBJECT or Config.Type.LIST, or value cannot be mapped
to.default java.util.function.Supplier<java.lang.Double> asDoubleSupplier(double defaultValue)
Double value of this configuration node or a default value.
Calling Supplier.get() returns Double value when the node is Config.Type.VALUE.
Returns a defaultValue if the node is Config.Type.MISSING type.
Otherwise, if node is Config.Type.OBJECT or Config.Type.LIST, it throws ConfigMappingException.
defaultValue - a default valueConfig.Type.VALUE or defaultValue.asDouble(double)default java.util.List<java.lang.String> asStringList()
throws MissingValueException,
ConfigMappingException
Strings of it is possible to map elementary sub-nodes into StringMissingValueException - in case the node is Config.Type.MISSING.ConfigMappingException - in case the node is Config.Type.VALUE, or list of nodes cannot be mapped
to list of Stringsdefault java.util.function.Supplier<java.util.List<java.lang.String>> asStringListSupplier()
Strings mapped from Config.Type.LIST or Config.Type.OBJECT nodes.
Calling Supplier.get() throws MissingValueException if this node is Config.Type.MISSING or ConfigMappingException if this node is Config.Type.VALUE or a list of nodes cannot be mapped to list of Strings.
Strings of it is possible to map elementary sub-nodes into
StringasStringList()default java.util.List<java.lang.String> asStringList(java.util.List<java.lang.String> defaultValue)
throws ConfigMappingException
Strings mapped from Config.Type.LIST or Config.Type.OBJECT nodes.
Returns a defaultValue if the node is Config.Type.MISSING type.defaultValue - a default valueStrings of it is possible to map elementary sub-nodes into String
or defaultValue if the node is Config.Type.MISSING.ConfigMappingException - in case the node is Config.Type.VALUE, or list of nodes cannot be mapped
to list of Stringsdefault java.util.function.Supplier<java.util.List<java.lang.String>> asStringListSupplier(java.util.List<java.lang.String> defaultValue)
Strings mapped from Config.Type.LIST or Config.Type.OBJECT nodes or a default value.
Calling Supplier.get() throws ConfigMappingException if this node is Config.Type.VALUE or a list of nodes
cannot be mapped to list of Strings.
defaultValue - a default valueStrings of it is possible to map elementary sub-nodes into
String or a defaultValueasStringList(List)default java.util.List<Config> asNodeList() throws MissingValueException, ConfigMappingException
Config nodes if the node is Config.Type.OBJECT.
Returns a list of element nodes if the node is Config.Type.LIST.
Throws MissingValueException if the node is Config.Type.MISSING.
Otherwise, if node is Config.Type.VALUE, it throws ConfigMappingException.Config.Type.OBJECT members or a list of Config.Type.LIST membersMissingValueException - in case the node is Config.Type.MISSING.ConfigMappingException - in case the node is Config.Type.VALUEdefault java.util.function.Supplier<java.util.List<Config>> asNodeListSupplier()
Config.Type.OBJECT or a list of element nodes for Config.Type.LIST.
Calling Supplier.get() may throw MissingValueException if this node is Config.Type.MISSING or ConfigMappingException for nodes of type Config.Type.VALUE.
Config.Type.OBJECT members or a list of Config.Type.LIST membersasNodeList()default java.util.List<Config> asNodeList(java.util.List<Config> defaultValue) throws ConfigMappingException
Config nodes if the node is Config.Type.OBJECT.
Returns a list of element nodes if the node is Config.Type.LIST.
Returns a defaultValue if the node is Config.Type.MISSING.
Otherwise, if node is Config.Type.VALUE, it throws ConfigMappingException.defaultValue - a default valueConfig.Type.OBJECT members, list of Config.Type.LIST members
or defaultValue in case of Config.Type.MISSINGConfigMappingException - in case the node is Config.Type.VALUEdefault java.util.function.Supplier<java.util.List<Config>> asNodeListSupplier(java.util.List<Config> defaultValue)
Config.Type.OBJECT, a list of element nodes for Config.Type.LIST or defaultValue if this node is Config.Type.MISSING.
Calling Supplier.get() may throw ConfigMappingException for nodes of type Config.Type.VALUE.
defaultValue - a default valueConfig.Type.OBJECT members or a list of Config.Type.LIST members
or defaultValue in case of Config.Type.MISSINGasNodeList(List)default java.util.Map<java.lang.String,java.lang.String> asMap()
throws MissingValueException
Fully qualified key of config node is used as a key in returned Map.
Detach config node before transforming to Map in case you want to cut
current Config node key prefix.
Let's say we work with following configuration:
app:
name: Example 1
page-size: 20
logging:
app.level = INFO
level = WARNING
Map app1 contains two keys: app.name, app.page-size.
Map<String, String> app1 = config.get("app").asMap();
Detaching app config node returns new Config instance with "reset" local root.
Map<String, String> app2 = config.get("app").detach().asMap();
Map app2 contains two keys without app prefix: name, page-size.MissingValueException - in case the node is Config.Type.MISSING.asOptionalMap(),
asMap(Map),
traverse(),
detach()default java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.String>> asMapSupplier()
For detail see asMap().
asMap()default java.util.Map<java.lang.String,java.lang.String> asMap(java.util.Map<java.lang.String,java.lang.String> defaultValue)
Fully qualified key of config node is used as a key in returned Map.
Detach config node before transforming to Map in case you want to cut
current Config node key prefix.
Let's say we work with following configuration:
app:
name: Example 1
page-size: 20
logging:
app.level = INFO
level = WARNING
Map app1 contains two keys: app.name, app.page-size.
Map<String, String> app1 = config.get("app").asMap(CollectionsHelper.mapOf());
Detaching app config node returns new Config instance with "reset" local root.
Map<String, String> app2 = config.get("app").detach().asMap(CollectionsHelper.mapOf());
Map app2 contains two keys without app prefix: name, page-size.defaultValue - a default valuedefaultValue in case of Config.Type.MISSINGasOptionalMap(),
asMap(),
traverse(),
detach()default java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.String>> asMapSupplier(java.util.Map<java.lang.String,java.lang.String> defaultValue)
Config.Type.MISSING.
For detail see asMap(Map).
defaultValue - a default valueasMap(Map)@Deprecated default Flow.Publisher<Config> changes()
A user can subscribe on root Config node and than will be notified on any change of Configuration. You can also subscribe on any sub-node, i.e. you will receive notification events just about sub-configuration. No matter how much the sub-configuration has changed you will receive just one notification event that is associated with a node you are subscribed on. If a user subscribes on older instance of Config and ones has already been published the last one is automatically submitted to new-subscriber.
The Config notification support is based on ConfigSource changes support.
Method Flow.Subscriber.onError(Throwable) is never called.
Method Flow.Subscriber.onComplete() is called in case an associated
ConfigSource's changes Publisher signals onComplete as well.
Note: It does not matter what instance version of Config (related to single Config.Builder initialization)
a user subscribes on. It is enough to subscribe just on single (e.g. on the first) Config instance.
There is no added value to subscribe again on new Config instance.
Flow.Publisher to be subscribed in. Never returns null.onChange(Function)default void onChange(java.util.function.Function<Config,java.lang.Boolean> onNextFunction)
onNextFunction function on change on whole Config or on particular Config node.
It automatically creates Flow.Subscriber that will
delegate Flow.Subscriber.onNext(Object) to specified onNextFunction function.
Created subscriber automatically requests all events
in it's Flow.Subscriber.onSubscribe(Flow.Subscription) method.
Function onNextFunction returns false in case user wants to cancel
current subscription.
A user can subscribe on root Config node and than will be notified on any change of Configuration. You can also subscribe on any sub-node, i.e. you will receive notification events just about sub-configuration. No matter how much the sub-configuration has changed you will receive just one notification event that is associated with a node you are subscribed on. If a user subscribes on older instance of Config and ones has already been published the last one is automatically submitted to new-subscriber.
The Config notification support is based on ConfigSource changes support.
Note: It does not matter what instance version of Config (related to single Config.Builder initialization)
a user subscribes on. It is enough to subscribe just on single (e.g. on the first) Config instance.
There is no added value to subscribe again on new Config instance.
onNextFunction - Flow.Subscriber.onNext(Object) functionalitychanges(),
ConfigHelper.subscriber(Function)Copyright © 2018, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.