public class SimpleConfigProperties extends Object implements ConfigProperties
ConfigProperties.| Modifier and Type | Field and Description |
|---|---|
private Set<String> |
childKeys |
private Map<String,SimpleConfigProperties> |
childMap |
private String |
nodeKey |
private int |
nodeModifications |
private String |
value |
EMPTY, KEY_SEPARATOR| Modifier | Constructor and Description |
|---|---|
protected |
SimpleConfigProperties(String key)
The constructor.
|
private final String nodeKey
private final Map<String,SimpleConfigProperties> childMap
private String value
private int nodeModifications
protected SimpleConfigProperties(String key)
key - the hierarchical key of this ConfigProperties-node.public boolean isEmpty()
isEmpty in interface ConfigPropertiestrue if this is an empty ConfigProperties-node that neither has a value
nor any child.protected String getNodeKey()
ConfigProperties-node.protected int getNodeModifications()
public Set<String> getChildKeys()
getChildKeys in interface ConfigPropertiesSet of the direct child keys available in the
ConfigProperties-node.protected void updateChildren()
public ConfigProperties getChild(String key)
getChild in interface ConfigPropertieskey - the child key of the requested configuration value.ConfigProperties. Will be an empty child if undefined.protected ConfigProperties getChild(String key, boolean create)
key - the key of the requested child.create - - true to create if not exits, false otherwise.getChild(String)protected SimpleConfigProperties createChild(String childKey, boolean create)
childKey - the key segment of the child to create.create - - true to force creation, false otherwise.null.public ConfigProperties getChild(String... keys)
ConfigPropertiesConfigProperties.getChild(String) such that
config.getChild(key1, ..., keyN) is the same as
config.getChild(key1)...getChild(keyN).getChild in interface ConfigPropertieskeys - the keys to traverse recursively.child reached from recursively traversing the given keys.protected ConfigProperties getChild(boolean create, String... keys)
create - - true to create if not exits, false otherwise.keys - the key segments of the requested child.public String getValue()
getValue in interface ConfigPropertiesConfigProperties-node. May be null.public <T> T getValue(Class<T> type)
getValue in interface ConfigPropertiesT - the requested typetype - the Class reflecting the requested result type.ConfigProperties-node converted to the given type. Will be null
if undefined.public <T> T getValue(Class<T> type, T defaultValue)
getValue in interface ConfigPropertiesT - the requested typetype - the Class reflecting the requested result type.defaultValue - the value returned as default if the actual value is undefined.ConfigProperties-node converted to the given type. Will be
defaultValue if undefined.public boolean getValueAsBoolean()
getValueAsBoolean in interface ConfigPropertiesConfigProperties.getValue(Class, Object) as boolean with false as default.protected void setValue(String value)
value - new value of getValue().public String getChildValue(String key)
ConfigPropertiesgetChild(key).ConfigProperties.getValue().getChildValue in interface ConfigPropertieskey - the key of the childConfigProperties-node. May be null.public String getChildValue(String... keys)
ConfigPropertiesgetChild(keys).ConfigProperties.getValue().getChildValue in interface ConfigPropertieskeys - the keys to traverse recursively.value of the descendant child traversed by
keys. May be null.public Map<String,String> toFlatMap()
toFlatMap in interface ConfigPropertiesConfigProperties converted to a flat Map.public Map<String,String> toFlatMap(String rootKey)
toFlatMap in interface ConfigPropertiesrootKey - the root key used as prefix for the keys separated with a dot
if not empty. Typically the empty String.ConfigProperties converted to a flat Map.public Map<String,Object> toHierarchicalMap()
toHierarchicalMap in interface ConfigPropertiesConfigProperties converted to a hierarchical
Map.protected void fromFlatMap(Map<String,String> map)
map - the flat Map of the configuration values.ofFlatMap(String, Map)protected void fromHierarchicalMap(Map<String,Object> map)
map - the hierarchical Map of the configuration values.ofHierarchicalMap(String, Map)public MutableConfigProperties inherit(ConfigProperties parentNode)
inherit in interface ConfigPropertiesparentNode - the parent ConfigProperties to extend.ConfigProperties with all children and
value(s) from this ConfigProperties-tree and all children and value(s) inherited from the given parent
ConfigProperties-tree if they are undefined in this tree.public static ConfigProperties ofFlatMap(Map<String,String> map)
map - the flat Map of the configuration values.ConfigProperties-node of the given flat Map converted to hierarchical
ConfigProperties.ofFlatMap(String, Map)public static ConfigProperties ofFlatMap(String key, Map<String,String> map)
Map of configuration values to hierarchical ConfigProperties. E.g. the flat map
{"foo.bar.some"="some-value", "foo.bar.other"="other-value"} would result in ConfigProperties
myRoot such that
myRoot.getChild("foo", "bar").getChildKeys() returns the
Collection {"some", "other"} and
myRoot.getValue("foo.bar.some") returns "my-value".key - the top-level key of the returned root ConfigProperties-node. Typically the empty string ("")
for root.map - the flat Map of the configuration values.ConfigProperties-node of the given flat Map converted to hierarchical
ConfigProperties.public static ConfigProperties ofHierarchicalMap(Map<String,Object> map)
map - the hierarchical Map of the configuration values.ConfigProperties-node of the given hierarchical Map converted to
ConfigProperties.ofHierarchicalMap(String, Map)public static ConfigProperties ofHierarchicalMap(String key, Map<String,Object> map)
Map of configuration values to ConfigProperties. E.g. the hierarchical map
{"foo"={"bar"={"some"="my-value", "other"="magic-value"}}} would result in ConfigProperties
myRoot such that
myRoot.getChild("foo", "bar").getChildKeys() returns the
Collection {"some", "other"} and
myRoot.getValue("foo.bar.some") returns "my-value".key - the top-level key of the returned root ConfigProperties-node. Typically the empty string ("")
for root.map - the hierarchical Map of the configuration values.ConfigProperties-node of the given hierarchical Map converted to
ConfigProperties.protected static String composeKey(String parentKey, String childKey)
parentKey - the parent key.childKey - the child key.protected static SimpleConfigProperties asSimple(ConfigProperties configProperties)
configProperties - the ConfigProperties.ConfigProperties as SimpleConfigProperties or null if no such instance.Copyright © 2014–2019 devon4j-Team. All rights reserved.