public class SettingsMapImpl extends HashMap<String,Object> implements ISettingsMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Modifier and Type | Field and Description |
---|---|
protected String |
originatorName
The name is used to generate helpful error or exceptions, should a property
be wrong or missing.
|
Modifier | Constructor and Description |
---|---|
protected |
SettingsMapImpl()
Use new SettingsMapBuilder().build() if you use it from api.
|
protected |
SettingsMapImpl(Map<String,Object> map,
String name) |
Modifier and Type | Method and Description |
---|---|
Map<String,Object> |
asFlatValuesMap() |
Map<String,Object> |
asFlatValuesMap(String indexedBy) |
Map<String,Object> |
asFlatValuesMapIgnoreSettingsList(String indexedBy) |
String |
asHjsonString() |
String |
asJsonString() |
String |
asJsonString(IJsonSerializer s)
This variant relies on an external serializer to deal with unsupported classes found in
the SettingsMap.
|
String |
asKvString() |
List<Map<String,Object>> |
asListFlatValuesMapIgnoreSettingsList(String indexedBy) |
String |
asYamlString() |
String |
childAsJson(String s)
Whatever be the type of the child, return a json representation of it.
|
byte[] |
childAsRawContent(String key)
Retrieve the content of a file node.
|
byte[] |
childAsTarGz(String dirName)
Assuming the SettingsMap contains a folder, this method returns a tar gz byte array of all its content.
|
ISettingsMap |
childFileAsMap(String key)
Return a child file as a map.
|
boolean |
childIsDir(String key) |
boolean |
childIsFile(String key) |
Boolean |
getAsBoolean(String key) |
Boolean |
getAsBoolean(String key,
Boolean defaultValue) |
Double |
getAsDouble(String key,
Double defaultValue) |
Integer |
getAsInteger(String key) |
Integer |
getAsInteger(String key,
Integer defaultValue) |
org.joda.time.DateTime |
getAsIsoDateTime(String key,
org.joda.time.DateTime defaultValue) |
Long |
getAsLong(String key) |
Long |
getAsLong(String key,
Long defaultValue) |
long |
getAsMsDuration(String key,
long defaultValue)
Return a duration.
|
Boolean |
getAsRequiredBoolean(String key) |
Double |
getAsRequiredDouble(String key) |
Integer |
getAsRequiredInteger(String key) |
org.joda.time.DateTime |
getAsRequiredIsoDateTime(String key) |
Long |
getAsRequiredLong(String key) |
Object |
getAsRequiredObject(String key)
Return a mandatory property.
|
Object |
getAsRequiredObjectOfClass(String key,
Class<?> expectedClass) |
ISettingsList |
getAsRequiredSettingsList(String key) |
ISettingsMap |
getAsRequiredSettingsMap(String key)
Return a mandatory sub-map from a key.
|
String |
getAsRequiredString(String key)
Return a mandatory string property.
|
TimeValue |
getAsRequiredTimeValue(String key)
Return a mandatory TimeValue
|
ZonedDateTime |
getAsRequiredZonedDateTime(String key) |
ISettingsList |
getAsSettingsList(String key) |
ISettingsList |
getAsSettingsList(String key,
ISettingsList defaultValue) |
ISettingsList |
getAsSettingsListOrEmpty(String key)
Get a settings list or an empty one if nonefound.
|
ISettingsMap |
getAsSettingsMap(String key) |
ISettingsMap |
getAsSettingsMap(String key,
ISettingsMap defaultValue) |
String |
getAsString(String key) |
String |
getAsString(String key,
String defaultValue) |
TimeValue |
getAsTimeValue(String key,
TimeValue defaultValue)
Return a TimeValue
|
protected String |
getChildName(String key) |
ISettingsMap |
getCreateMap(String key)
Get a new map or create one if not found.
|
ISettingsMap |
getDeepCopy()
Get a deep copy object of this map.
|
ISettingsMap |
getMapOrEmpty(String key)
Get a map or an empty one if nout found.
|
Object |
getNestedProperty(Object defaultValue,
String... keys)
Get an optional nested property identified by a succession of keys to navigate into the properties tree
|
static SettingsMapImpl |
getNewInstance() |
ISettingsMap |
getOrCreateNestedSettingsMap(String... keys)
Get a nested settings map identified by a succession of keys to navigate into the properties tree
|
String |
getOriginatorName() |
Object |
getRequiredNestedProperty(String... keys)
Get a required nested property identified by a succession of keys to navigate into the properties tree
|
String |
getStringOrFail(String key)
Return a mandatory string property.
|
String |
getStringOrFail(String key,
String defaultValue)
Return a string property or a default value
|
long |
getTimeValueMs(String key,
long defaultValue)
Given a "100ms" "10m" "1h" "2d" representation, return the corresponding value in ms.
|
protected ISettingsList |
newSettingsListChild(List<Object> list,
String name)
Returns a new instance of appropriate Settings list implementation for this settings tree
Initialized with same content as a provided list containing
The returned object has not been added to the THIS settings map
|
protected ISettingsMap |
newSettingsMapChild(Map<String,Object> map,
String name)
Returns a new instance of appropriate Settings map implementation for this settings tree
Initialized with same content as a provided map containing
The returned object has not been added to the THIS settings map
|
protected ISettingsMap |
newSettingsMapChild(String name)
Returns a new instance of appropriate Settings map implementation for this settings tree
The returned object has not been added to the THIS settings map
|
void |
overrideWith(ISettingsMap otherSettings)
Recursively import/override settings in this map with settings from another map.
|
ISettingsMap |
putUsingDottedPath(String dottedPath,
Object value)
Put a nested value using the dotted notation for creating the path.
|
ISettingsMap |
putUsingSlashPath(String path,
Object value)
Put a nested value using the "/" filesystem notation for creating the path.
|
ISettingsMap |
removeUsingDottedPath(String dottedPath)
Remove a leaf node using a dotted path.
|
ISettingsMap |
removeUsingSlashPath(String path)
Remove a leaf node using a dotted path.
|
void |
setJsonDecoding(boolean b)
By default files loaded from (typically) zookeeper of from the local file system are automatically
decoded as json (if, of course, their content is json compatible).
|
ISettingsMap |
setNestedProperty(Object value,
String... keys)
Add a nested property.
|
ISettingsMap |
setOriginatorName(String name)
SettingsMap can be associated with a name referencing the original
file (typically0.
|
ISettingsMap |
setPropertyIfMissing(String key,
Object value)
Set a property only if it does not exists yet.
|
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
equals, hashCode, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
childAsListOfString, childAsMapEntries, childAsMapValues, childAsRequiredListOfString, childAsRequiredString, childAsString, childAsStringContent, getCreateAsListOfMap
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
protected String originatorName
protected SettingsMapImpl()
public Boolean getAsBoolean(String key)
getAsBoolean
in interface ISettingsMap
key
- the key of what you look forpublic String getAsString(String key)
getAsString
in interface ISettingsMap
key
- the key of what you look forpublic Long getAsLong(String key)
getAsLong
in interface ISettingsMap
key
- the key of what you look forpublic Integer getAsInteger(String key)
getAsInteger
in interface ISettingsMap
key
- the key of what you look forpublic ISettingsList getAsSettingsList(String key)
getAsSettingsList
in interface ISettingsMap
key
- the key of what you look forpublic ISettingsMap getAsSettingsMap(String key)
getAsSettingsMap
in interface ISettingsMap
key
- the key of what you look forpublic Boolean getAsBoolean(String key, Boolean defaultValue)
getAsBoolean
in interface ISettingsMap
key
- the key of what you look fordefaultValue
- the default valuepublic String getAsString(String key, String defaultValue)
getAsString
in interface ISettingsMap
key
- the key of what you look fordefaultValue
- the default valuepublic Double getAsDouble(String key, Double defaultValue)
getAsDouble
in interface ISettingsMap
key
- the keydefaultValue
- a double default value returned of the key is not foundpublic Long getAsLong(String key, Long defaultValue)
getAsLong
in interface ISettingsMap
key
- the key of what you look fordefaultValue
- the default valuepublic Integer getAsInteger(String key, Integer defaultValue)
getAsInteger
in interface ISettingsMap
key
- the key of what you look fordefaultValue
- the default valuepublic ISettingsList getAsSettingsList(String key, ISettingsList defaultValue)
getAsSettingsList
in interface ISettingsMap
key
- the key of what you look fordefaultValue
- the default valueprotected ISettingsMap newSettingsMapChild(Map<String,Object> map, String name)
map
- an Objects map containing settings, used to initialize the new settings mapname
- a nameprotected ISettingsList newSettingsListChild(List<Object> list, String name)
list
- a list of of type objectname
- a nameprotected ISettingsMap newSettingsMapChild(String name)
name
- a namepublic ISettingsMap getAsSettingsMap(String key, ISettingsMap defaultValue)
getAsSettingsMap
in interface ISettingsMap
key
- the key of what you look fordefaultValue
- the default valuepublic Object getAsRequiredObject(String key)
ISettingsMap
getAsRequiredObject
in interface ISettingsMap
key
- the property keypublic Object getAsRequiredObjectOfClass(String key, Class<?> expectedClass)
getAsRequiredObjectOfClass
in interface ISettingsMap
key
- the property key to retrieveexpectedClass
- the class of which the property must be checked an instance ofpublic Boolean getAsRequiredBoolean(String key)
getAsRequiredBoolean
in interface ISettingsMap
key
- the key of what you look forpublic Long getAsRequiredLong(String key)
getAsRequiredLong
in interface ISettingsMap
key
- the key of what you look forpublic Double getAsRequiredDouble(String key)
getAsRequiredDouble
in interface ISettingsMap
key
- the key of what you look forpublic Integer getAsRequiredInteger(String key)
getAsRequiredInteger
in interface ISettingsMap
key
- the key of what you look forpublic String getStringOrFail(String key) throws ConfigurationException
ISettingsMap
getStringOrFail
in interface ISettingsMap
key
- the property keyConfigurationException
- if the property is missing or is not a stringpublic String getStringOrFail(String key, String defaultValue) throws ConfigurationException
ISettingsMap
getStringOrFail
in interface ISettingsMap
key
- the property keydefaultValue
- the default valueConfigurationException
public String getAsRequiredString(String key)
ISettingsMap
getAsRequiredString
in interface ISettingsMap
key
- the property keypublic org.joda.time.DateTime getAsRequiredIsoDateTime(String key)
getAsRequiredIsoDateTime
in interface ISettingsMap
key
- the key of the timestamppublic org.joda.time.DateTime getAsIsoDateTime(String key, org.joda.time.DateTime defaultValue)
getAsIsoDateTime
in interface ISettingsMap
key
- the key of the timestampdefaultValue
- the default valuepublic ZonedDateTime getAsRequiredZonedDateTime(String key)
getAsRequiredZonedDateTime
in interface ISettingsMap
key
- the key of the timestamppublic ISettingsList getAsRequiredSettingsList(String key)
getAsRequiredSettingsList
in interface ISettingsMap
key
- the key you look forpublic ISettingsList getAsSettingsListOrEmpty(String key)
ISettingsMap
getAsSettingsList(key, new SettingsListBuilder().build());
It is useful to deal with optional settings.getAsSettingsListOrEmpty
in interface ISettingsMap
key
- the sub list keypublic ISettingsMap getAsRequiredSettingsMap(String key)
ISettingsMap
The returned sub map is an instance of ISettingsMap, you can use it as a standard Mao or use the extra getters.
This method does not provide lazy loading of inner files. Use chiladAsMap if that is what you need.
getAsRequiredSettingsMap
in interface ISettingsMap
key
- the sub-map key nameprotected String getChildName(String key)
key
- a keypublic ISettingsMap setOriginatorName(String name)
ISettingsMap
setOriginatorName
in interface ISettingsMap
name
- the name to associatepublic String getOriginatorName()
getOriginatorName
in interface ISettingsMap
public TimeValue getAsTimeValue(String key, TimeValue defaultValue)
ISettingsMap
getAsTimeValue
in interface ISettingsMap
key
- the timeValue keydefaultValue
- a default TimeValuepublic TimeValue getAsRequiredTimeValue(String key)
ISettingsMap
getAsRequiredTimeValue
in interface ISettingsMap
key
- the timeValue keypublic void overrideWith(ISettingsMap otherSettings)
ISettingsMap
overrideWith
in interface ISettingsMap
otherSettings
- the new settingspublic ISettingsMap putUsingDottedPath(String dottedPath, Object value)
ISettingsMap
putUsingDottedPath
in interface ISettingsMap
dottedPath
- dot-separated settings pathvalue
- the valuepublic ISettingsMap putUsingSlashPath(String path, Object value)
ISettingsMap
putUsingSlashPath
in interface ISettingsMap
value
- the valuepublic ISettingsMap removeUsingDottedPath(String dottedPath)
ISettingsMap
removeUsingDottedPath
in interface ISettingsMap
public ISettingsMap removeUsingSlashPath(String path)
ISettingsMap
removeUsingSlashPath
in interface ISettingsMap
public String asJsonString()
asJsonString
in interface ISettingsMap
public String asJsonString(IJsonSerializer s)
ISettingsMap
asJsonString
in interface ISettingsMap
s
- your external serializerpublic Map<String,Object> asFlatValuesMap()
asFlatValuesMap
in interface ISettingsMap
public String asKvString()
asKvString
in interface ISettingsMap
public Map<String,Object> asFlatValuesMap(String indexedBy)
asFlatValuesMap
in interface ISettingsMap
indexedBy
- the character to use as seperatorpublic Map<String,Object> asFlatValuesMapIgnoreSettingsList(String indexedBy)
asFlatValuesMapIgnoreSettingsList
in interface ISettingsMap
indexedBy
- the character to use as seperatorpublic List<Map<String,Object>> asListFlatValuesMapIgnoreSettingsList(String indexedBy)
asListFlatValuesMapIgnoreSettingsList
in interface ISettingsMap
indexedBy
- the character to use as seperatorpublic String childAsJson(String s)
ISettingsMap
childAsJson
in interface ISettingsMap
s
- the child key.public byte[] childAsTarGz(String dirName)
ISettingsMap
childAsTarGz
in interface ISettingsMap
dirName
- the child directory namepublic boolean childIsFile(String key)
childIsFile
in interface ISettingsMap
key
- the name of a child propertypublic boolean childIsDir(String key)
childIsDir
in interface ISettingsMap
key
- the name of a child propertypublic byte[] childAsRawContent(String key)
ISettingsMap
childAsRawContent
in interface ISettingsMap
key
- the property keypublic ISettingsMap getMapOrEmpty(String key)
ISettingsMap
getAsSettingsMap(key, new SettingsMapBuilder().build());
It is useful to deal with optional settings.getMapOrEmpty
in interface ISettingsMap
key
- the sub map keypublic ISettingsMap getCreateMap(String key)
ISettingsMap
getCreateMap
in interface ISettingsMap
key
- the sub map key.public ISettingsMap childFileAsMap(String key)
ISettingsMap
This method lets you easily check if a file is a valid YAML JSON or HJSON file.
childFileAsMap
in interface ISettingsMap
key
- tfile name; relative to where you are.public ISettingsMap setPropertyIfMissing(String key, Object value)
ISettingsMap
setPropertyIfMissing
in interface ISettingsMap
key
- the property keyvalue
- the property valuepublic static SettingsMapImpl getNewInstance()
public void setJsonDecoding(boolean b)
Use this to request no decoding. You will then get FileHandle instead.
b
- true or falsepublic long getTimeValueMs(String key, long defaultValue)
ISettingsMap
getTimeValueMs
in interface ISettingsMap
key
- the property keydefaultValue
- the defaultValuepublic long getAsMsDuration(String key, long defaultValue)
ISettingsMap
getAsMsDuration
in interface ISettingsMap
key
- the property keydefaultValue
- the default valuepublic ISettingsMap setNestedProperty(Object value, String... keys)
ISettingsMap
This lets you add directly an inner property. For example:
map.addNestedProperty(23, "user", "bob", "age");
setNestedProperty
in interface ISettingsMap
value
- the valuekeys
- the list of keyspublic ISettingsMap getDeepCopy()
ISettingsMap
getDeepCopy
in interface ISettingsMap
public ISettingsMap getOrCreateNestedSettingsMap(String... keys)
ISettingsMap
getOrCreateNestedSettingsMap
in interface ISettingsMap
keys
- the list of keys that will be used to navigate into the settings tree.public Object getNestedProperty(Object defaultValue, String... keys)
ISettingsMap
getNestedProperty
in interface ISettingsMap
defaultValue
- the value that will be returned if at least one of the successive keys is missingkeys
- the list of keys that will be used to navigate into the settings tree.public Object getRequiredNestedProperty(String... keys)
ISettingsMap
getRequiredNestedProperty
in interface ISettingsMap
keys
- the list of keys that will be used to navigate into the settings tree.public String asHjsonString()
asHjsonString
in interface ISettingsMap
public String asYamlString()
asYamlString
in interface ISettingsMap
Copyright © 2014–2022. All rights reserved.