public class Settings extends Object
Config
supplied by typesafe config.
Contains various boilerplate methods to safe- and quickly access the underlying config.
Constructor and Description |
---|
Settings(com.typesafe.config.Config config)
Creates a new wrapper for the given config.
|
Modifier and Type | Method and Description |
---|---|
Value |
get(String path)
Returns the
Value defined for the given key. |
com.typesafe.config.Config |
getConfig()
Provides access to the underlying config object.
|
com.typesafe.config.Config |
getConfig(String key)
Returns the sub config available for the given key.
|
List<? extends com.typesafe.config.Config> |
getConfigs(String key)
Returns all config objects underneath the given key.
|
Context |
getContext()
Returns all values defined in this extension as
Context . |
int |
getInt(String key)
Returns the integer value for the given key.
|
Map<String,String> |
getMap(String key)
Reads a embedded map.
|
long |
getMilliseconds(String path)
Returns the duration in milliseconds defined for the given key.
|
String |
getString(String key)
Returns the string for the given key.
|
List<String> |
getStringList(String key) |
boolean |
injectValueFromConfig(Object target,
Field field,
String key)
Injects the value selected by 'key' out of the given config into the given field of the given target.
|
public Settings(@Nonnull com.typesafe.config.Config config)
config
- the config to wrappublic com.typesafe.config.Config getConfig()
@Nonnull public Value get(String path)
Value
defined for the given key.
If this extension doesn't provide a value for this key, but there is an extension with the name default which provides a value, this is used.
If the value in the config file starts with a dollar sign, the value is treated as an i18n key and the returned value will contain the translation for the current language.
path
- the access path to retrieve the valueValue.isNull()
@Nonnull public Context getContext()
Context
.@Nullable public com.typesafe.config.Config getConfig(String key)
key
- name of the sub config to retrieve@Nonnull public List<? extends com.typesafe.config.Config> getConfigs(String key)
Assume we have the following config:
test { sub { a { ... } b { ... } } }
Then getConfigs("sub") for the extension "test" would return a list containing a and b wrapped as config.
The name of the config object is available as "id".
The list will be sorted by "priority". If no explicit priority is given, we try to sort elements along their natural order within the file. If multiple files are merged together, the behaviour of this approach is undefined and priority should be used.
key
- the path to the config object containing a list of sub object.public long getMilliseconds(String path)
If this extension doesn't provide a value for this key, but there is an extension with the name default which provides a value, this is used.
path
- the access path to retrieve the valueHandledException
- if an invalid value was given in the configpublic String getString(String key)
key
- the key used to lookup the string valuepublic int getInt(String key)
key
- the key used to lookup the valuepublic Map<String,String> getMap(String key)
key
- the key of the map to readpublic boolean injectValueFromConfig(Object target, Field field, String key)
target
- the target object to populatefield
- the field to fillkey
- the key to readCopyright © 2018. All rights reserved.