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, valuesequals, hashCode, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitchildAsListOfString, childAsMapEntries, childAsMapValues, childAsRequiredListOfString, childAsRequiredString, childAsString, childAsStringContent, getCreateAsListOfMapclear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesprotected String originatorName
protected SettingsMapImpl()
public Boolean getAsBoolean(String key)
getAsBoolean in interface ISettingsMapkey - the key of what you look forpublic String getAsString(String key)
getAsString in interface ISettingsMapkey - the key of what you look forpublic Long getAsLong(String key)
getAsLong in interface ISettingsMapkey - the key of what you look forpublic Integer getAsInteger(String key)
getAsInteger in interface ISettingsMapkey - the key of what you look forpublic ISettingsList getAsSettingsList(String key)
getAsSettingsList in interface ISettingsMapkey - the key of what you look forpublic ISettingsMap getAsSettingsMap(String key)
getAsSettingsMap in interface ISettingsMapkey - the key of what you look forpublic Boolean getAsBoolean(String key, Boolean defaultValue)
getAsBoolean in interface ISettingsMapkey - the key of what you look fordefaultValue - the default valuepublic String getAsString(String key, String defaultValue)
getAsString in interface ISettingsMapkey - the key of what you look fordefaultValue - the default valuepublic Double getAsDouble(String key, Double defaultValue)
getAsDouble in interface ISettingsMapkey - the keydefaultValue - a double default value returned of the key is not foundpublic Long getAsLong(String key, Long defaultValue)
getAsLong in interface ISettingsMapkey - the key of what you look fordefaultValue - the default valuepublic Integer getAsInteger(String key, Integer defaultValue)
getAsInteger in interface ISettingsMapkey - the key of what you look fordefaultValue - the default valuepublic ISettingsList getAsSettingsList(String key, ISettingsList defaultValue)
getAsSettingsList in interface ISettingsMapkey - 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 ISettingsMapkey - the key of what you look fordefaultValue - the default valuepublic Object getAsRequiredObject(String key)
ISettingsMapgetAsRequiredObject in interface ISettingsMapkey - the property keypublic Object getAsRequiredObjectOfClass(String key, Class<?> expectedClass)
getAsRequiredObjectOfClass in interface ISettingsMapkey - the property key to retrieveexpectedClass - the class of which the property must be checked an instance ofpublic Boolean getAsRequiredBoolean(String key)
getAsRequiredBoolean in interface ISettingsMapkey - the key of what you look forpublic Long getAsRequiredLong(String key)
getAsRequiredLong in interface ISettingsMapkey - the key of what you look forpublic Double getAsRequiredDouble(String key)
getAsRequiredDouble in interface ISettingsMapkey - the key of what you look forpublic Integer getAsRequiredInteger(String key)
getAsRequiredInteger in interface ISettingsMapkey - the key of what you look forpublic String getStringOrFail(String key) throws ConfigurationException
ISettingsMapgetStringOrFail in interface ISettingsMapkey - the property keyConfigurationException - if the property is missing or is not a stringpublic String getStringOrFail(String key, String defaultValue) throws ConfigurationException
ISettingsMapgetStringOrFail in interface ISettingsMapkey - the property keydefaultValue - the default valueConfigurationExceptionpublic String getAsRequiredString(String key)
ISettingsMapgetAsRequiredString in interface ISettingsMapkey - the property keypublic org.joda.time.DateTime getAsRequiredIsoDateTime(String key)
getAsRequiredIsoDateTime in interface ISettingsMapkey - the key of the timestamppublic org.joda.time.DateTime getAsIsoDateTime(String key, org.joda.time.DateTime defaultValue)
getAsIsoDateTime in interface ISettingsMapkey - the key of the timestampdefaultValue - the default valuepublic ZonedDateTime getAsRequiredZonedDateTime(String key)
getAsRequiredZonedDateTime in interface ISettingsMapkey - the key of the timestamppublic ISettingsList getAsRequiredSettingsList(String key)
getAsRequiredSettingsList in interface ISettingsMapkey - 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 ISettingsMapkey - the sub list keypublic ISettingsMap getAsRequiredSettingsMap(String key)
ISettingsMapThe 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 ISettingsMapkey - the sub-map key nameprotected String getChildName(String key)
key - a keypublic ISettingsMap setOriginatorName(String name)
ISettingsMapsetOriginatorName in interface ISettingsMapname - the name to associatepublic String getOriginatorName()
getOriginatorName in interface ISettingsMappublic TimeValue getAsTimeValue(String key, TimeValue defaultValue)
ISettingsMapgetAsTimeValue in interface ISettingsMapkey - the timeValue keydefaultValue - a default TimeValuepublic TimeValue getAsRequiredTimeValue(String key)
ISettingsMapgetAsRequiredTimeValue in interface ISettingsMapkey - the timeValue keypublic void overrideWith(ISettingsMap otherSettings)
ISettingsMapoverrideWith in interface ISettingsMapotherSettings - the new settingspublic ISettingsMap putUsingDottedPath(String dottedPath, Object value)
ISettingsMapputUsingDottedPath in interface ISettingsMapdottedPath - dot-separated settings pathvalue - the valuepublic ISettingsMap putUsingSlashPath(String path, Object value)
ISettingsMapputUsingSlashPath in interface ISettingsMapvalue - the valuepublic ISettingsMap removeUsingDottedPath(String dottedPath)
ISettingsMapremoveUsingDottedPath in interface ISettingsMappublic ISettingsMap removeUsingSlashPath(String path)
ISettingsMapremoveUsingSlashPath in interface ISettingsMappublic String asJsonString()
asJsonString in interface ISettingsMappublic String asJsonString(IJsonSerializer s)
ISettingsMapasJsonString in interface ISettingsMaps - your external serializerpublic Map<String,Object> asFlatValuesMap()
asFlatValuesMap in interface ISettingsMappublic String asKvString()
asKvString in interface ISettingsMappublic Map<String,Object> asFlatValuesMap(String indexedBy)
asFlatValuesMap in interface ISettingsMapindexedBy - the character to use as seperatorpublic Map<String,Object> asFlatValuesMapIgnoreSettingsList(String indexedBy)
asFlatValuesMapIgnoreSettingsList in interface ISettingsMapindexedBy - the character to use as seperatorpublic List<Map<String,Object>> asListFlatValuesMapIgnoreSettingsList(String indexedBy)
asListFlatValuesMapIgnoreSettingsList in interface ISettingsMapindexedBy - the character to use as seperatorpublic String childAsJson(String s)
ISettingsMapchildAsJson in interface ISettingsMaps - the child key.public byte[] childAsTarGz(String dirName)
ISettingsMapchildAsTarGz in interface ISettingsMapdirName - the child directory namepublic boolean childIsFile(String key)
childIsFile in interface ISettingsMapkey - the name of a child propertypublic boolean childIsDir(String key)
childIsDir in interface ISettingsMapkey - the name of a child propertypublic byte[] childAsRawContent(String key)
ISettingsMapchildAsRawContent in interface ISettingsMapkey - the property keypublic ISettingsMap getMapOrEmpty(String key)
ISettingsMap
getAsSettingsMap(key, new SettingsMapBuilder().build());
It is useful to deal with optional settings.getMapOrEmpty in interface ISettingsMapkey - the sub map keypublic ISettingsMap getCreateMap(String key)
ISettingsMapgetCreateMap in interface ISettingsMapkey - the sub map key.public ISettingsMap childFileAsMap(String key)
ISettingsMapThis method lets you easily check if a file is a valid YAML JSON or HJSON file.
childFileAsMap in interface ISettingsMapkey - tfile name; relative to where you are.public ISettingsMap setPropertyIfMissing(String key, Object value)
ISettingsMapsetPropertyIfMissing in interface ISettingsMapkey - 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)
ISettingsMapgetTimeValueMs in interface ISettingsMapkey - the property keydefaultValue - the defaultValuepublic long getAsMsDuration(String key, long defaultValue)
ISettingsMapgetAsMsDuration in interface ISettingsMapkey - the property keydefaultValue - the default valuepublic ISettingsMap setNestedProperty(Object value, String... keys)
ISettingsMapThis lets you add directly an inner property. For example:
map.addNestedProperty(23, "user", "bob", "age");
setNestedProperty in interface ISettingsMapvalue - the valuekeys - the list of keyspublic ISettingsMap getDeepCopy()
ISettingsMapgetDeepCopy in interface ISettingsMappublic ISettingsMap getOrCreateNestedSettingsMap(String... keys)
ISettingsMapgetOrCreateNestedSettingsMap in interface ISettingsMapkeys - the list of keys that will be used to navigate into the settings tree.public Object getNestedProperty(Object defaultValue, String... keys)
ISettingsMapgetNestedProperty in interface ISettingsMapdefaultValue - 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)
ISettingsMapgetRequiredNestedProperty in interface ISettingsMapkeys - the list of keys that will be used to navigate into the settings tree.public String asHjsonString()
asHjsonString in interface ISettingsMappublic String asYamlString()
asYamlString in interface ISettingsMapCopyright © 2014–2023. All rights reserved.