- All Known Subinterfaces:
Config
See ConfigValue
.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Object 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 childConfig
nodes if the node isType#OBJECT
.default ConfigValue
<String> asString()
String typed value.detach()
Returns a copy of theConfig
node with no parent.static Config
empty()
Empty instance ofConfig
.boolean
exists()
Returnstrue
if the node exists, whether an object, a list, a value node, etc.default Config
get
(Config.Key key) Returns the single sub-node for the specified sub-key.Returns the single sub-node for the specified sub-key.boolean
hasValue()
Returnstrue
if this configuration node has a direct value.boolean
isLeaf()
Returnstrue
if this node exists and is a leaf node (has no children).boolean
isList()
Returnstrue
if this node exists and is Type#List.boolean
isObject()
Returnstrue
if this node exists and is Type#Object.key()
Returns the fully-qualified key of theConfig
node.<T> ConfigValue
<T> Typed value as aConfigValue
created from factory method.<T> ConfigValue
<List<T>> Returns this node as a list mapping each list value using the provided mapper.default String
name()
Returns the last token of the fully-qualified key for theConfig
node.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 theConfig
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). 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 theConfig
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:- 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 ofdetached
tree, 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 theConfig
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
TheConfig
instancesname1
andname2
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 asMap() for example of config detaching.
- Returns:
- returns detached Config instance of same config node
- Throws:
ConfigException
- if not defined
-
exists
boolean exists()Returnstrue
if the node exists, whether an object, a list, a value node, etc.- Returns:
true
if the node exists
-
isLeaf
boolean isLeaf()Returnstrue
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.
- Returns:
true
if the node is existing leaf node,false
otherwise.
-
isObject
boolean isObject()Returnstrue
if this node exists and is Type#Object.- Returns:
true
if the node exists and is Type#Object,false
otherwise.
-
isList
boolean isList()Returnstrue
if this node exists and is Type#List.- Returns:
true
if the node exists and is Type#List,false
otherwise.
-
hasValue
boolean hasValue()Returnstrue
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.- Returns:
true
if the node has direct value,false
otherwise.
-
as
Typed value as aConfigValue
.- Type Parameters:
T
- type- Parameters:
type
- type class- Returns:
- typed value
- See Also:
-
map
Typed value as aConfigValue
created 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 childConfig
nodes if the node isType#OBJECT
. Returns a list of element nodes if the node isType#LIST
. ThrowsMissingValueException
if the node isType#MISSING
. Otherwise, if node isType#VALUE
, it throwsConfigMappingException
.- Type Parameters:
C
- the common config derived type- Returns:
- a list of
Type#OBJECT
members or a list ofType#LIST
members - 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
-