Class SimpleConfigProperties
- java.lang.Object
-
- com.devonfw.module.basic.common.api.config.SimpleConfigProperties
-
- All Implemented Interfaces:
ConfigProperties
public class SimpleConfigProperties extends Object implements ConfigProperties
Simple implementation ofConfigProperties
.- Since:
- 3.0.0
-
-
Field Summary
-
Fields inherited from interface com.devonfw.module.basic.common.api.config.ConfigProperties
EMPTY, KEY_SEPARATOR
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SimpleConfigProperties(String key)
The constructor.
-
Method Summary
-
-
-
Constructor Detail
-
SimpleConfigProperties
protected SimpleConfigProperties(String key)
The constructor.- Parameters:
key
- the hierarchical key of thisConfigProperties
-node.
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceConfigProperties
- Returns:
true
if this is an emptyConfigProperties
-node that neither has avalue
norany
child
.
-
getNodeKey
protected String getNodeKey()
- Returns:
- the absolute key of this
ConfigProperties
-node.
-
getNodeModifications
protected int getNodeModifications()
- Returns:
- the modification counter that gets incremented whenever a child node is added.
-
getChildKeys
public Set<String> getChildKeys()
- Specified by:
getChildKeys
in interfaceConfigProperties
- Returns:
- the
Set
of thedirect child keys
available in theConfigProperties
-node.
-
updateChildren
protected void updateChildren()
Updates the child-nodes in case of a mutable copy node.
-
getChild
public ConfigProperties getChild(String key)
- Specified by:
getChild
in interfaceConfigProperties
- Parameters:
key
- thechild key
of the requested configuration value.- Returns:
- the child
ConfigProperties
. Will be anempty
child if undefined.
-
getChild
protected ConfigProperties getChild(String key, boolean create)
- Parameters:
key
- the key of the requested child.create
- -true
to create if not exits,false
otherwise.- Returns:
- the requested child.
- See Also:
getChild(String)
-
createChild
protected SimpleConfigProperties createChild(String childKey, boolean create)
- Parameters:
childKey
- the key segment of the child to create.create
- -true
to force creation,false
otherwise.- Returns:
- the new child or
null
.
-
getChild
public ConfigProperties getChild(String... keys)
Description copied from interface:ConfigProperties
Recursive variant ofConfigProperties.getChild(String)
such that
is the same asconfig
.getChild
(key1, ..., keyN)
.config
.getChild
(key1)...getChild
(keyN)- Specified by:
getChild
in interfaceConfigProperties
- Parameters:
keys
- the keys to traverse recursively.- Returns:
- the descendant
child
reached from recursively traversing the givenkeys
.
-
getChild
protected ConfigProperties getChild(boolean create, String... keys)
- Parameters:
create
- -true
to create if not exits,false
otherwise.keys
- the key segments of the requested child.- Returns:
- the requested child.
-
getValue
public String getValue()
- Specified by:
getValue
in interfaceConfigProperties
- Returns:
- the value of this
ConfigProperties
-node. May benull
.
-
getValue
public <T> T getValue(Class<T> type)
- Specified by:
getValue
in interfaceConfigProperties
- Type Parameters:
T
- the requestedtype
- Parameters:
type
- theClass
reflecting the requested result type.- Returns:
- the value of this
ConfigProperties
-node converted to the giventype
. Will benull
if undefined.
-
getValue
public <T> T getValue(Class<T> type, T defaultValue)
- Specified by:
getValue
in interfaceConfigProperties
- Type Parameters:
T
- the requestedtype
- Parameters:
type
- theClass
reflecting the requested result type.defaultValue
- the value returned as default if the actualvalue
is undefined.- Returns:
- the value of this
ConfigProperties
-node converted to the giventype
. Will bedefaultValue
if undefined.
-
getValueAsBoolean
public boolean getValueAsBoolean()
- Specified by:
getValueAsBoolean
in interfaceConfigProperties
- Returns:
- the
ConfigProperties.getValue(Class, Object)
asboolean
withfalse
as default.
-
setValue
protected void setValue(String value)
- Parameters:
value
- new value ofgetValue()
.
-
getChildValue
public String getChildValue(String key)
Description copied from interface:ConfigProperties
Shortcut forgetChild(key)
.ConfigProperties.getValue()
.- Specified by:
getChildValue
in interfaceConfigProperties
- Parameters:
key
- thekey of the child
- Returns:
- the value of this
ConfigProperties
-node. May benull
.
-
getChildValue
public String getChildValue(String... keys)
Description copied from interface:ConfigProperties
Shortcut forgetChild(keys)
.ConfigProperties.getValue()
.- Specified by:
getChildValue
in interfaceConfigProperties
- Parameters:
keys
- the keys to traverse recursively.- Returns:
- the
value
of thedescendant child
traversed bykeys
. May benull
.
-
toFlatMap
public Map<String,String> toFlatMap()
- Specified by:
toFlatMap
in interfaceConfigProperties
- Returns:
- this
ConfigProperties
converted to aflat
Map
.
-
toFlatMap
public Map<String,String> toFlatMap(String rootKey)
- Specified by:
toFlatMap
in interfaceConfigProperties
- Parameters:
rootKey
- the root key used as prefix for thekeys
separated with a dot if notempty
. Typically the emptyString
.- Returns:
- this
ConfigProperties
converted to aflat
Map
.
-
toHierarchicalMap
public Map<String,Object> toHierarchicalMap()
- Specified by:
toHierarchicalMap
in interfaceConfigProperties
- Returns:
- this
ConfigProperties
converted to ahierarchical
Map
.
-
fromFlatMap
protected void fromFlatMap(Map<String,String> map)
- Parameters:
map
- the flatMap
of the configuration values.- See Also:
ofFlatMap(String, Map)
-
fromHierarchicalMap
protected void fromHierarchicalMap(Map<String,Object> map)
- Parameters:
map
- the hierarchicalMap
of the configuration values.- See Also:
ofHierarchicalMap(String, Map)
-
inherit
public MutableConfigProperties inherit(ConfigProperties parentNode)
- Specified by:
inherit
in interfaceConfigProperties
- Parameters:
parentNode
- the parentConfigProperties
to extend.- Returns:
- a new instance of
ConfigProperties
with allchildren
andvalue
(s) from thisConfigProperties
-tree and allchildren
andvalue
(s) inherited from the givenparent
ConfigProperties
-tree if they are undefined in this tree.
-
ofFlatMap
public static ConfigProperties ofFlatMap(Map<String,String> map)
- Parameters:
map
- the flatMap
of the configuration values.- Returns:
- the root
ConfigProperties
-node of the given flatMap
converted to hierarchicalConfigProperties
. - See Also:
ofFlatMap(String, Map)
-
ofFlatMap
public static ConfigProperties ofFlatMap(String key, Map<String,String> map)
Converts a flatMap
of configuration values to hierarchicalConfigProperties
. E.g. the flat map{"foo.bar.some"="some-value", "foo.bar.other"="other-value"}
would result inConfigProperties
myRoot
such thatmyRoot.
returns thegetChild
("foo", "bar").getChildKeys()
Collection
{"some", "other"} andmyRoot.
returns "my-value".getValue
("foo.bar.some")- Parameters:
key
- the top-level key of the returned rootConfigProperties
-node. Typically the empty string ("") for root.map
- the flatMap
of the configuration values.- Returns:
- the root
ConfigProperties
-node of the given flatMap
converted to hierarchicalConfigProperties
.
-
ofHierarchicalMap
public static ConfigProperties ofHierarchicalMap(Map<String,Object> map)
- Parameters:
map
- the hierarchicalMap
of the configuration values.- Returns:
- the root
ConfigProperties
-node of the given hierarchicalMap
converted toConfigProperties
. - See Also:
ofHierarchicalMap(String, Map)
-
ofHierarchicalMap
public static ConfigProperties ofHierarchicalMap(String key, Map<String,Object> map)
Converts a hierarchicalMap
of configuration values toConfigProperties
. E.g. the hierarchical map{"foo"={"bar"={"some"="my-value", "other"="magic-value"}}}
would result inConfigProperties
myRoot
such thatmyRoot.
returns thegetChild
("foo", "bar").getChildKeys()
Collection
{"some", "other"} andmyRoot.
returns "my-value".getValue
("foo.bar.some")- Parameters:
key
- the top-level key of the returned rootConfigProperties
-node. Typically the empty string ("") for root.map
- the hierarchicalMap
of the configuration values.- Returns:
- the root
ConfigProperties
-node of the given hierarchicalMap
converted toConfigProperties
.
-
composeKey
protected static String composeKey(String parentKey, String childKey)
- Parameters:
parentKey
- the parent key.childKey
- the child key.- Returns:
- the composed key.
-
asSimple
protected static SimpleConfigProperties asSimple(ConfigProperties configProperties)
- Parameters:
configProperties
- theConfigProperties
.- Returns:
- the given
ConfigProperties
asSimpleConfigProperties
ornull
if no such instance.
-
-