- All Known Subinterfaces:
Config
See ConfigValue.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceObject represents fully-qualified key of config node. -
Method Summary
Modifier and TypeMethodDescription<T> ConfigValue<T> Typed value as aConfigValue.default ConfigValue<Boolean> Boolean typed value.default ConfigValue<Double> asDouble()Double typed value.default ConfigValue<Integer> asInt()Integer typed value.<T> ConfigValue<List<T>> Returns list of specified type.default ConfigValue<Long> asLong()Long typed value.asMap()Transform all leaf nodes (values) into Map instance.default ConfigValue<? extends Config> asNode()Returns existing current config node asConfigValue.<C extends Config>
ConfigValue<List<C>> Returns a list of childConfignodes if the node isType#OBJECT.default ConfigValue<String> asString()String typed value.detach()Returns a copy of theConfignode with no parent.static Configempty()Empty instance ofConfig.booleanexists()Returnstrueif the node exists, whether an object, a list, a value node, etc.default Configget(Config.Key key) Returns the single sub-node for the specified sub-key.Returns the single sub-node for the specified sub-key.booleanhasValue()Returnstrueif this configuration node has a direct value.booleanisLeaf()Returnstrueif this node exists and is a leaf node (has no children).booleanisList()Returnstrueif this node exists and is Type#List.booleanisObject()Returnstrueif this node exists and is Type#Object.key()Returns the fully-qualified key of theConfignode.<T> ConfigValue<T> Typed value as aConfigValuecreated from factory method.<T> ConfigValue<List<T>> Returns this node as a list mapping each list value using the provided mapper.default Stringname()Returns the last token of the fully-qualified key for theConfignode.root()Get the root of the configuration tree.
-
Method Details
-
empty
Empty instance ofConfig.- Returns:
- empty instance of
Config.
-
key
Config.Key key()Returns 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). 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 theConfignode.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 Type#OBJECT node the token for a child is the name of the object member;
- from a 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- Returns:
- current config node key
- See Also:
-
get
Returns the single sub-node for the specified sub-key.The format of the key is described on
key()method.- Parameters:
key- sub-key of requested sub-node- Returns:
- config node for specified sub-key, never returns
null. - Throws:
ConfigException- if not defined- See Also:
-
root
Config root()Get the root of the configuration tree. In case this node is part ofdetachedtree, this method returns the node that was detached.- Returns:
- root of this configuration tree
-
get
Returns the single sub-node for the specified sub-key.- Parameters:
key- sub-key of requested sub-node- Returns:
- config node for specified sub-key, never returns
null. - See Also:
-
detach
Returns 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 asMap() for example of config detaching.
- Returns:
- returns detached Config instance of same config node
- Throws:
ConfigException- if not defined
-
exists
boolean exists()Returnstrueif the node exists, whether an object, a list, a value node, etc.- Returns:
trueif the node exists
-
isLeaf
boolean isLeaf()Returnstrueif this node exists and is a leaf node (has no children).A leaf node has no nested configuration subtree and has a single value.
- Returns:
trueif the node is existing leaf node,falseotherwise.
-
isObject
boolean isObject()Returnstrueif this node exists and is Type#Object.- Returns:
trueif the node exists and is Type#Object,falseotherwise.
-
isList
boolean isList()Returnstrueif this node exists and is Type#List.- Returns:
trueif the node exists and is Type#List,falseotherwise.
-
hasValue
boolean hasValue()Returnstrueif 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.- Returns:
trueif the node has direct value,falseotherwise.
-
as
Typed value as aConfigValue.- Type Parameters:
T- type- Parameters:
type- type class- Returns:
- typed value
- See Also:
-
map
Typed value as aConfigValuecreated from factory method. To convert from String, you can useconfig.asString().as(Function).- Type Parameters:
T- type- Parameters:
mapper- method to create an instance from config- Returns:
- typed value
-
asList
Returns list of specified type.- Type Parameters:
T- type of list elements- Parameters:
type- type class- Returns:
- a typed list with values
- Throws:
ConfigException- in case of problem to map property value.
-
mapList
Returns this node as a list mapping each list value using the provided mapper.- 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:
ConfigException- in case the mapper fails to map the values
-
asNodeList
Returns 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.- Type Parameters:
C- the common config derived type- Returns:
- a list of
Type#OBJECTmembers or a list ofType#LISTmembers - Throws:
ConfigException- in case the node isType#VALUE
-
asMap
Transform all leaf nodes (values) into Map instance.- Returns:
- new Map instance that contains all config leaf node values
- Throws:
ConfigException- in case the node is Type#MISSING.
-
asNode
Returns existing current config node asConfigValue.- Returns:
- current config node as
ConfigValue
-
asString
String typed value.- Returns:
- typed value
-
asBoolean
Boolean typed value.- Returns:
- typed value
-
asInt
Integer typed value.- Returns:
- typed value
-
asLong
Long typed value.- Returns:
- typed value
-
asDouble
Double typed value.- Returns:
- typed value
-