Class SimpleConfigProperties
- java.lang.Object
-
- com.devonfw.module.basic.common.api.config.SimpleConfigProperties
-
- All Implemented Interfaces:
ConfigProperties
- Direct Known Subclasses:
MutableConfigPropertiesImpl
public class SimpleConfigProperties extends Object implements ConfigProperties
Simple implementation ofConfigProperties.- Since:
- 3.0.0
-
-
Field Summary
Fields Modifier and Type Field Description private Set<String>childKeysprivate Map<String,SimpleConfigProperties>childMapprivate StringnodeKeyprivate intnodeModificationsprivate Stringvalue-
Fields inherited from interface com.devonfw.module.basic.common.api.config.ConfigProperties
EMPTY, KEY_SEPARATOR
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedSimpleConfigProperties(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:
isEmptyin interfaceConfigProperties- Returns:
trueif this is an emptyConfigProperties-node that neither has avaluenoranychild.
-
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:
getChildKeysin interfaceConfigProperties- Returns:
- the
Setof thedirect child keysavailable 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:
getChildin interfaceConfigProperties- Parameters:
key- thechild keyof the requested configuration value.- Returns:
- the child
ConfigProperties. Will be anemptychild if undefined.
-
getChild
protected ConfigProperties getChild(String key, boolean create)
- Parameters:
key- the key of the requested child.create- -trueto create if not exits,falseotherwise.- 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- -trueto force creation,falseotherwise.- Returns:
- the new child or
null.
-
getChild
public ConfigProperties getChild(String... keys)
Description copied from interface:ConfigPropertiesRecursive variant ofConfigProperties.getChild(String)such thatis the same asconfig.getChild(key1, ..., keyN).config.getChild(key1)...getChild(keyN)- Specified by:
getChildin interfaceConfigProperties- Parameters:
keys- the keys to traverse recursively.- Returns:
- the descendant
childreached from recursively traversing the givenkeys.
-
getChild
protected ConfigProperties getChild(boolean create, String... keys)
- Parameters:
create- -trueto create if not exits,falseotherwise.keys- the key segments of the requested child.- Returns:
- the requested child.
-
getValue
public String getValue()
- Specified by:
getValuein interfaceConfigProperties- Returns:
- the value of this
ConfigProperties-node. May benull.
-
getValue
public <T> T getValue(Class<T> type)
- Specified by:
getValuein interfaceConfigProperties- Type Parameters:
T- the requestedtype- Parameters:
type- theClassreflecting the requested result type.- Returns:
- the value of this
ConfigProperties-node converted to the giventype. Will benullif undefined.
-
getValue
public <T> T getValue(Class<T> type, T defaultValue)
- Specified by:
getValuein interfaceConfigProperties- Type Parameters:
T- the requestedtype- Parameters:
type- theClassreflecting the requested result type.defaultValue- the value returned as default if the actualvalueis undefined.- Returns:
- the value of this
ConfigProperties-node converted to the giventype. Will bedefaultValueif undefined.
-
getValueAsBoolean
public boolean getValueAsBoolean()
- Specified by:
getValueAsBooleanin interfaceConfigProperties- Returns:
- the
ConfigProperties.getValue(Class, Object)asbooleanwithfalseas default.
-
setValue
protected void setValue(String value)
- Parameters:
value- new value ofgetValue().
-
getChildValue
public String getChildValue(String key)
Description copied from interface:ConfigPropertiesShortcut forgetChild(key).ConfigProperties.getValue().- Specified by:
getChildValuein 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:ConfigPropertiesShortcut forgetChild(keys).ConfigProperties.getValue().- Specified by:
getChildValuein interfaceConfigProperties- Parameters:
keys- the keys to traverse recursively.- Returns:
- the
valueof thedescendant childtraversed bykeys. May benull.
-
toFlatMap
public Map<String,String> toFlatMap()
- Specified by:
toFlatMapin interfaceConfigProperties- Returns:
- this
ConfigPropertiesconverted to aflatMap.
-
toFlatMap
public Map<String,String> toFlatMap(String rootKey)
- Specified by:
toFlatMapin interfaceConfigProperties- Parameters:
rootKey- the root key used as prefix for thekeysseparated with a dot if notempty. Typically the emptyString.- Returns:
- this
ConfigPropertiesconverted to aflatMap.
-
toHierarchicalMap
public Map<String,Object> toHierarchicalMap()
- Specified by:
toHierarchicalMapin interfaceConfigProperties- Returns:
- this
ConfigPropertiesconverted to ahierarchicalMap.
-
fromFlatMap
protected void fromFlatMap(Map<String,String> map)
- Parameters:
map- the flatMapof the configuration values.- See Also:
ofFlatMap(String, Map)
-
fromHierarchicalMap
protected void fromHierarchicalMap(Map<String,Object> map)
- Parameters:
map- the hierarchicalMapof the configuration values.- See Also:
ofHierarchicalMap(String, Map)
-
inherit
public MutableConfigProperties inherit(ConfigProperties parentNode)
- Specified by:
inheritin interfaceConfigProperties- Parameters:
parentNode- the parentConfigPropertiesto extend.- Returns:
- a new instance of
ConfigPropertieswith allchildrenandvalue(s) from thisConfigProperties-tree and allchildrenandvalue(s) inherited from the givenparentConfigProperties-tree if they are undefined in this tree.
-
ofFlatMap
public static ConfigProperties ofFlatMap(Map<String,String> map)
- Parameters:
map- the flatMapof the configuration values.- Returns:
- the root
ConfigProperties-node of the given flatMapconverted to hierarchicalConfigProperties. - See Also:
ofFlatMap(String, Map)
-
ofFlatMap
public static ConfigProperties ofFlatMap(String key, Map<String,String> map)
Converts a flatMapof configuration values to hierarchicalConfigProperties. E.g. the flat map{"foo.bar.some"="some-value", "foo.bar.other"="other-value"}would result inConfigPropertiesmyRootsuch 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 flatMapof the configuration values.- Returns:
- the root
ConfigProperties-node of the given flatMapconverted to hierarchicalConfigProperties.
-
ofHierarchicalMap
public static ConfigProperties ofHierarchicalMap(Map<String,Object> map)
- Parameters:
map- the hierarchicalMapof the configuration values.- Returns:
- the root
ConfigProperties-node of the given hierarchicalMapconverted toConfigProperties. - See Also:
ofHierarchicalMap(String, Map)
-
ofHierarchicalMap
public static ConfigProperties ofHierarchicalMap(String key, Map<String,Object> map)
Converts a hierarchicalMapof configuration values toConfigProperties. E.g. the hierarchical map{"foo"={"bar"={"some"="my-value", "other"="magic-value"}}}would result inConfigPropertiesmyRootsuch 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 hierarchicalMapof the configuration values.- Returns:
- the root
ConfigProperties-node of the given hierarchicalMapconverted 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
ConfigPropertiesasSimpleConfigPropertiesornullif no such instance.
-
-