public interface ISettingsMap extends Map<String,Object>
This is especiallly important because the punchplatform relies heavily on configuration files, not transformed into pojos but used with a dynamic API. It would be way too tedious to create tons of pojos corresponding to the various json or yml files we deal with.
| 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 key)
Whatever be the type of the child, return a json representation of it.
|
default List<String> |
childAsListOfString(String key)
Return a child node of your map, expecting a list of string.
|
default List<Map.Entry<String,ISettingsMap>> |
childAsMapEntries(String key)
Make it easier to iterate over child map entries.
|
default List<ISettingsMap> |
childAsMapValues(String key)
Make it easier to iterate over child map values.
|
byte[] |
childAsRawContent(String key)
Retrieve the content of a file node.
|
default List<String> |
childAsRequiredListOfString(String key)
Return a required child node of your map, expecting a list of string.
|
default String |
childAsRequiredString(String key)
Return a child node of your map, expecting a String.
|
default String |
childAsString(String key)
Return a child node of your map, expecting a String.
|
default String |
childAsStringContent(String key)
Retrieve the content of a file node as a String.
|
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<? extends Object> 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
|
default List<ISettingsMap> |
getCreateAsListOfMap(String key)
Return a child node of your map, expecting a list of map.
|
ISettingsMap |
getCreateMap(String key)
Deprecated.
use instead getMapOrEmpty
|
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
|
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.
|
void |
overrideWith(ISettingsMap otherSettings)
Recursively import/override settings in this map with settings from another map.
|
ISettingsMap |
putUsingDottedPath(String path,
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 path)
Remove a leaf node using a dotted path.
|
ISettingsMap |
removeUsingSlashPath(String path)
Remove a leaf node using a dotted path.
|
ISettingsMap |
setNestedProperty(Object value,
String... keys)
Add a nested property.
|
ISettingsMap |
setOriginatorName(String originatorName)
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, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valueslong getAsMsDuration(String key, long defaultValue)
key - the property keydefaultValue - the default valueBoolean getAsBoolean(String key)
key - the key of what you look forUnexpectedSettingTypeException - runtime exception if requested type is not actual type of non-null propertyString getAsString(String key)
key - the key of what you look forUnexpectedSettingTypeException - runtime exception if requested type is not actual type of non-null propertyLong getAsLong(String key)
key - the key of what you look forUnexpectedSettingTypeException - runtime exception if requested type is not actual type of non-null propertyDouble getAsDouble(String key, Double defaultValue)
key - the keydefaultValue - a double default value returned of the key is not foundInteger getAsInteger(String key)
key - the key of what you look forUnexpectedSettingTypeException - runtime exception if requested type is not actual type of non-null propertyISettingsList getAsSettingsList(String key)
key - the key of what you look forUnexpectedSettingTypeException - runtime exception if requested type is not actual type of non-null propertyISettingsMap getAsSettingsMap(String key)
key - the key of what you look forUnexpectedSettingTypeException - runtime exception if requested type is not actual type of non-null propertyBoolean getAsBoolean(String key, Boolean defaultValue)
key - the key of what you look fordefaultValue - the default valueUnexpectedSettingTypeException - runtime exception if requested type is not actual type of non-null propertyString getAsString(String key, String defaultValue)
key - the key of what you look fordefaultValue - the default valueUnexpectedSettingTypeException - runtime exception if requested type is not actual type of non-null propertyLong getAsLong(String key, Long defaultValue)
key - the key of what you look fordefaultValue - the default valueUnexpectedSettingTypeException - runtime exception if requested type is not actual type of non-null propertyInteger getAsInteger(String key, Integer defaultValue)
key - the key of what you look fordefaultValue - the default valueUnexpectedSettingTypeException - runtime exception if requested type is not actual type of non-null propertyISettingsList getAsSettingsList(String key, ISettingsList defaultValue)
key - the key of what you look fordefaultValue - the default valueUnexpectedSettingTypeException - runtime exception if requested type is not actual type of non-null propertyISettingsMap getAsSettingsMap(String key, ISettingsMap defaultValue)
key - the key of what you look fordefaultValue - the default valueUnexpectedSettingTypeException - runtime exception if requested type is not actual type of non-null propertyBoolean getAsRequiredBoolean(String key)
key - the key of what you look forUnexpectedSettingTypeException - runtime exception if requested type is not actual type of non-null propertyIllegalArgumentException - runtime exception if requested property is missingLong getAsRequiredLong(String key)
key - the key of what you look forUnexpectedSettingTypeException - runtime exception if requested type is not actual type of non-null propertyIllegalArgumentException - runtime exception if requested property is missingDouble getAsRequiredDouble(String key)
key - the key of what you look forUnexpectedSettingTypeException - runtime exception if requested type is not actual type of non-null propertyIllegalArgumentException - runtime exception if requested property is missingInteger getAsRequiredInteger(String key)
key - the key of what you look forUnexpectedSettingTypeException - runtime exception if requested type is not actual type of non-null propertyIllegalArgumentException - runtime exception if requested property is missingString getAsRequiredString(String key)
key - the property keyUnexpectedSettingTypeException - runtime exception if the property exists but is not a String.IllegalArgumentException - runtime exception if the property is missingString getStringOrFail(String key) throws ConfigurationException
key - the property keyConfigurationException - if the property is missing or is not a stringString getStringOrFail(String key, String defaultValue) throws ConfigurationException
key - the property keydefaultValue - the default valueConfigurationExceptionObject getAsRequiredObject(String key)
key - the property keyIllegalArgumentException - runtime exception if the property is missingObject getAsRequiredObjectOfClass(String key, Class<? extends Object> expectedClass)
key - the property key to retrieveexpectedClass - the class of which the property must be checked an instance ofUnexpectedSettingTypeException - runtime exception if requested type is not actual type of non-null propertyIllegalArgumentException - runtime exception if requested property is missingISettingsList getAsRequiredSettingsList(String key)
key - the key you look forUnexpectedSettingTypeException - runtime exception if requested type is not actual type of non-null propertyIllegalArgumentException - runtime exception if requested property is missingISettingsMap getAsRequiredSettingsMap(String key)
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.
key - the sub-map key nameUnexpectedSettingTypeException - runtime exception if requested type is not actual type of non-null propertyIllegalArgumentException - runtime exception if requested property is missingISettingsMap setOriginatorName(String originatorName)
originatorName - the name to associateString getOriginatorName()
TimeValue getAsTimeValue(String key, TimeValue defaultValue)
key - the timeValue keydefaultValue - a default TimeValueTimeValue getAsRequiredTimeValue(String key)
key - the timeValue keyorg.joda.time.DateTime getAsRequiredIsoDateTime(String key)
key - the key of the timestamporg.joda.time.DateTime getAsIsoDateTime(String key, org.joda.time.DateTime defaultValue)
key - the key of the timestampdefaultValue - the default valueZonedDateTime getAsRequiredZonedDateTime(String key)
key - the key of the timestampvoid overrideWith(ISettingsMap otherSettings)
otherSettings - the new settingsISettingsMap putUsingDottedPath(String path, Object value)
path - dot-separated settings pathvalue - the valueISettingsMap putUsingSlashPath(String path, Object value)
dottedPath - dot-separated settings path allowing to navigate in a tree of settings map down to the leaf or node that has to be putvalue - the valueString asJsonString()
String asHjsonString()
String asYamlString()
Map<String,Object> asFlatValuesMap()
Map<String,Object> asFlatValuesMap(String indexedBy)
indexedBy - the character to use as seperatorMap<String,Object> asFlatValuesMapIgnoreSettingsList(String indexedBy)
indexedBy - the character to use as seperatorList<Map<String,Object>> asListFlatValuesMapIgnoreSettingsList(String indexedBy)
indexedBy - the character to use as seperatorString asJsonString(IJsonSerializer s)
s - your external serializerISettingsMap childFileAsMap(String key)
This method lets you easily check if a file is a valid YAML JSON or HJSON file.
key - tfile name; relative to where you are.IllegalArgumentException - if the child cannot be converted into or is not a map.@Deprecated ISettingsMap getCreateMap(String key)
key - the sub map key.byte[] childAsRawContent(String key)
key - the property keyIllegalArgumentException - if the child node is not of the expected typeboolean childIsFile(String key)
key - the name of a child propertyboolean childIsDir(String key)
key - the name of a child propertybyte[] childAsTarGz(String dirName)
dirName - the child directory namedefault String childAsStringContent(String key) throws IllegalArgumentException
To speak clearly if your settings map is backed by zookeeper, the content comes from zookeeper.
key - the property keyIllegalArgumentException - if the child node is not of the expected typedefault List<Map.Entry<String,ISettingsMap>> childAsMapEntries(String key)
key - the expected child namedefault List<ISettingsMap> childAsMapValues(String key)
key - the expected child namedefault List<ISettingsMap> getCreateAsListOfMap(String key)
key - key the expected child namedefault String childAsString(String key)
key - the expected child namedefault String childAsRequiredString(String key)
key - the expected child nameUnexpectedSettingTypeException - runtime exception if the property exists but is not a String.IllegalArgumentException - runtime exception if the property is missingdefault List<String> childAsListOfString(String key)
key - key the expected child namedefault List<String> childAsRequiredListOfString(String key)
key - key the expected child nameUnexpectedSettingTypeException - runtime exception if requested child is not actual type of non-null propertyString childAsJson(String key)
key - the child key.ISettingsMap setPropertyIfMissing(String key, Object value)
key - the property keyvalue - the property valuelong getTimeValueMs(String key, long defaultValue)
key - the property keydefaultValue - the defaultValueISettingsMap setNestedProperty(Object value, String... keys)
This lets you add directly an inner property. For example:
map.addNestedProperty(23, "user", "bob", "age");
value - the valuekeys - the list of keysObject getNestedProperty(Object defaultValue, String... keys)
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.Object getRequiredNestedProperty(String... keys)
keys - the list of keys that will be used to navigate into the settings tree.ISettingsMap getOrCreateNestedSettingsMap(String... keys)
keys - the list of keys that will be used to navigate into the settings tree.ISettingsMap getDeepCopy()
ISettingsMap removeUsingDottedPath(String path)
string - the dotted pathISettingsMap removeUsingSlashPath(String path)
string - the dotted pathString asKvString()
ISettingsMap getMapOrEmpty(String key)
getAsSettingsMap(key, new SettingsMapBuilder().build());
It is useful to deal with optional settings.key - the sub map keyISettingsList getAsSettingsListOrEmpty(String key)
getAsSettingsList(key, new SettingsListBuilder().build());
It is useful to deal with optional settings.key - the sub list keyCopyright © 2014–2023. All rights reserved.