Config instances, primary and fallback.
When a property is not present in the primary configuration, fallback is used.
When a key is present in both the primary and fallback configurations,
the value from the primary configuration takes precedence.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.helidon.config.Config
Config.Builder, Config.Context, Config.Key, Config.Type -
Field Summary
Fields inherited from interface io.helidon.config.Config
GENERIC_TYPE -
Method Summary
Modifier and TypeMethodDescription<T> ConfigValue<T> as(GenericType<T> genericType) Typed value as aConfigValuefor a generic type.<T> ConfigValue<T> Typed value as aConfigValue.<T> ConfigValue<T> Typed value as aConfigValuecreated from factory method.<T> ConfigValue<List<T>> Returns list of specified type.<T> ConfigValue<List<T>> Returns this node as a list converting each list value using the provided mapper.asMap()Transform all leaf nodes (values) into Map instance.Returns a list of childConfignodes if the node isType#OBJECT.<T> TConvert a String to a specific type.static ConfigCreates a newMergedConfigthat merges the specified configurations.detach()Returns a copy of theConfignode with no parent.get(Config.Key key) Returns the single sub-node for the specified sub-key.booleanhasValue()Returnstrueif this configuration node has a direct value.key()Returns the fully-qualified key of theConfignode.mapper()Only mappers from the primary config are considered.root()Get the root of the configuration tree.Returns when the configuration tree was created.Traverses over merged configs likeConfig.traverse().type()Provides theConfig.Typeof theConfignode.
-
Method Details
-
create
Creates a newMergedConfigthat merges the specified configurations.- Parameters:
primary- the primary configuration, which has precedence in the case of duplicate keysfallback- the fallback configuration, queried for keys not found in the primary one- Returns:
- a merged
Configinstance
-
timestamp
Description copied from interface:ConfigReturns when the configuration tree was created.Each config node of single Config tree returns same timestamp.
-
key
Description copied from interface:ConfigReturns the fully-qualified key of theConfignode.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). SeeConfig.name()for more information on the format of each token. -
root
Description copied from interface:ConfigGet the root of the configuration tree. In case this node is part ofdetachedtree, this method returns the node that was detached. -
get
Description copied from interface:ConfigReturns the single sub-node for the specified sub-key. -
detach
Description copied from interface:ConfigReturns a copy of theConfignode 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 = WARNINGTheConfiginstancesname1andname2represents 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 nodeThe only difference is the key each node returns:assert name1.key() == "app.name"; assert name2.key() == "name"; //DETACHED node
See
Config.asMap()for example of config detaching. -
type
Description copied from interface:ConfigProvides theConfig.Typeof theConfignode. -
hasValue
public boolean hasValue()Description copied from interface:ConfigReturnstrueif 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
Config.as(Class)on nodes that have value. -
traverse
Traverses over merged configs likeConfig.traverse(). Every config node exising in both primary and fallback configs is merged. -
convert
Description copied from interface:ConfigConvert a String to a specific type. This is a helper method to allow for processing of default values that cannot be typed (e.g. in annotations).- Specified by:
convertin interfaceConfig- Type Parameters:
T- type- Parameters:
type- type of the propertyvalue- String value- Returns:
- instance of the correct type
- Throws:
ConfigMappingException- in case the String provided cannot be converted to the type expected- See Also:
-
mapper
Only mappers from the primary config are considered. -
as
Description copied from interface:ConfigTyped value as aConfigValuefor a generic type. If appropriate mapper exists, returns a properly typed generic instance.Example:
ConfigValue<Map<String, Integer>> myMapValue = config.as(new GenericType<Map<String, Integer>>(){}); myMapValue.ifPresent(map -> { Integer port = map.get("service.port"); } -
as
Description copied from interface:ConfigTyped value as aConfigValue. -
as
Description copied from interface:ConfigTyped value as aConfigValuecreated from factory method. To convert from String, you can useconfig.asString().as(Function). -
asList
Description copied from interface:ConfigReturns list of specified type.- Specified by:
asListin interfaceConfig- Specified by:
asListin interfaceConfig- Type Parameters:
T- type of list elements- Parameters:
type- type class- Returns:
- a typed list with values
- Throws:
ConfigMappingException- in case of problem to map property value.
-
asList
Description copied from interface:ConfigReturns this node as a list converting each list value using the provided mapper.- Specified by:
asListin interfaceConfig- Type Parameters:
T- type of list elements- Parameters:
mapper- mapper to convert each list node into a typed value- Returns:
- a typed list with values
- Throws:
ConfigMappingException- in case the mapper fails to map the values
-
asNodeList
Description copied from interface:ConfigReturns a list of childConfignodes if the node isType#OBJECT. Returns a list of element nodes if the node isType#LIST. ThrowsMissingValueExceptionif the node isType#MISSING. Otherwise, if node isType#VALUE, it throwsConfigMappingException.- Specified by:
asNodeListin interfaceConfig- Specified by:
asNodeListin interfaceConfig- Returns:
- a list of
Type#OBJECTmembers or a list ofType#LISTmembers - Throws:
ConfigMappingException
-
asMap
Description copied from interface:ConfigTransform all leaf nodes (values) into Map instance.Fully qualified key of config node is used as a key in returned Map.
Detachconfig 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 = WARNINGMapapp1contains two keys:app.name,app.page-size.Map<String, String> app1 = config.get("app").asMap();Detachingappconfig node returns new Config instance with "reset" local root.
MapMap<String, String> app2 = config.get("app").detach().asMap();app2contains two keys withoutappprefix:name,page-size.- Specified by:
asMapin interfaceConfig- Specified by:
asMapin interfaceConfig- Returns:
- new Map instance that contains all config leaf node values
- Throws:
MissingValueException- in case the node isConfig.Type.MISSING.- See Also:
-