public class YConfiguration extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
YConfiguration.ConfigurationNotFoundException
Introduced to be able to detect when a configuration file was not specified (as opposed to when there's a
validation error inside).
|
static class |
YConfiguration.DefaultConfigurationResolver
Default config file resolver.
|
| Constructor and Description |
|---|
YConfiguration(String subsystem,
InputStream is,
String confpath)
Constructs a new configuration object parsing the input stream
|
YConfiguration(YConfiguration parent,
String parentKey,
Map<String,Object> root) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsKey(String key) |
boolean |
containsKey(String key,
String key1) |
static YConfiguration |
emptyConfig() |
Object |
get(String key) |
static boolean |
getBoolean(Map<String,Object> m,
String key) |
static boolean |
getBoolean(Map<String,Object> m,
String key,
boolean defaultValue)
Returns m.get(key) if it exists and is of type boolean, if m.get(key) exists and is not boolean, throw an
exception.
|
boolean |
getBoolean(String key) |
boolean |
getBoolean(String key,
boolean defaultValue) |
boolean |
getBoolean(String key,
String key1) |
YConfiguration |
getConfig(String key)
If the key is pointing to a map, creates and returns a configuration object out of that map
|
List<YConfiguration> |
getConfigList(String key) |
static YConfiguration |
getConfiguration(String subsystem)
Loads (if not already loaded) and returns a configuration corresponding to a file <subsystem>.yaml
This method does not reload the configuration file if it has changed.
|
static YConfiguration |
getConfiguration(String subsystem,
boolean reload)
Loads and returns a configuration corresponding to a file <subsystem>.yaml
This method reloads the configuration file always.
|
static double |
getDouble(Map<String,Object> m,
String key,
double v) |
double |
getDouble(String key) |
double |
getDouble(String key,
double defaultValue) |
static <T extends Enum<T>> |
getEnum(Map<String,Object> config,
String key,
Class<T> enumClass)
Returns a value of an enumeration that matches ignoring case the string obtained from the config with the given
key.
|
<T extends Enum<T>> |
getEnum(String key,
Class<T> enumClass) |
String |
getFirstEntry()
returns the first entry(key) in the config file.
|
Map<String,Object> |
getFirstMap()
returns the first entry in the config file if it's a map.
|
static String |
getGlobalProperty(String key) |
static int |
getInt(Map<String,Object> m,
String key) |
static int |
getInt(Map<String,Object> m,
String key,
int defaultValue)
return the m.get(key) as an int if it's present or v if it is not.
|
int |
getInt(String key)
int configs
|
int |
getInt(String key,
int defaultValue) |
int |
getInt(String key,
String key1) |
int |
getInt(String key,
String key1,
int defaultValue) |
Set<String> |
getKeys() |
static <T> List<T> |
getList(Map<String,Object> m,
String key) |
<T> List<T> |
getList(String key)
List configs
|
static long |
getLong(Map<String,Object> m,
String key) |
static long |
getLong(Map<String,Object> m,
String key,
long v)
return the m.get(key) as an long if it's present or v if it is not.
|
long |
getLong(String key)
long configs
|
long |
getLong(String key,
long defaultValue) |
static Map<String,Object> |
getMap(Map<String,Object> m,
String key)
Map configs
|
Map<String,Object> |
getMap(String key)
Deprecated.
|
String |
getPath() |
static YConfigurationResolver |
getResolver() |
Map<String,Object> |
getRoot() |
List<YConfiguration> |
getServiceConfigList(String key)
This is the same like the method above but will create a {class: "string"} for strings rather than throwing an
exception.
|
static String |
getString(Map m,
String key)
Returns m.get(key) if it exists and is of type string, otherwise throws an exception
|
static String |
getString(Map m,
String key,
String defaultValue) |
String |
getString(String key) |
String |
getString(String key,
String defaultValue) |
<T> List<T> |
getSubList(String key,
String key1) |
Map<String,Object> |
getSubMap(String key,
String key1) |
String |
getSubString(String key,
String subkey) |
static boolean |
isDefined(String subsystem) |
static boolean |
isList(Map m,
String key) |
boolean |
isList(String key) |
static boolean |
isNull(Map m,
String key) |
static void |
setResolver(YConfigurationResolver resolver) |
static void |
setup()
calls setup(null)
|
static void |
setup(String configPrefix)
If configPrefix is not null, sets up the configuration to search the classpath for files like
"configPrefix/xyz.properties"
Also sets up the TimeEncoding configuration
|
static void |
setup(String configPrefix,
String userConfigDirectory) |
String |
toJson() |
static YConfiguration |
wrap(Map<String,Object> m)
Create a new configuration wrapping around a map The resulting config will have no parent
|
public YConfiguration(String subsystem, InputStream is, String confpath)
is - - input stream where the configuration is loaded fromconfpath - - configuration path - it is remembered together with the configuration in case of error to indicate
where it is coming from (i.e. which file)public YConfiguration(YConfiguration parent, String parentKey, Map<String,Object> root)
parent - parentKey - root - public static void setup(String configPrefix) throws ConfigurationException
configPrefix - ConfigurationExceptionpublic static void setup()
throws ConfigurationException
ConfigurationExceptionpublic static YConfiguration getConfiguration(String subsystem) throws ConfigurationException
subsystem - ConfigurationException - if the configuration file could not be found or not loaded (e.g. error in yaml formatting)public static YConfiguration getConfiguration(String subsystem, boolean reload) throws ConfigurationException
subsystem - reload - ConfigurationException - if the configuration file could not be found or not loaded (e.g. error in yaml formatting)public static boolean isDefined(String subsystem) throws ConfigurationException
ConfigurationExceptionpublic boolean containsKey(String key)
public boolean containsKey(String key, String key1) throws ConfigurationException
ConfigurationExceptionpublic Map<String,Object> getFirstMap() throws ConfigurationException
ConfigurationExceptionpublic String getFirstEntry() throws ConfigurationException
ConfigurationExceptionpublic YConfiguration getConfig(String key)
The returned object will have its parent set to this object
key - public static Map<String,Object> getMap(Map<String,Object> m, String key) throws ConfigurationException
ConfigurationException@Deprecated public Map<String,Object> getMap(String key) throws ConfigurationException
getConfig(java.lang.String) to get a child config instead of accessing the map directlyConfigurationExceptionpublic Map<String,Object> getSubMap(String key, String key1) throws ConfigurationException
ConfigurationExceptionpublic static String getString(Map m, String key) throws ConfigurationException
m - key - ConfigurationExceptionpublic static String getString(Map m, String key, String defaultValue) throws ConfigurationException
ConfigurationExceptionpublic String getString(String key) throws ConfigurationException
ConfigurationExceptionpublic String getString(String key, String defaultValue) throws ConfigurationException
ConfigurationExceptionpublic String getSubString(String key, String subkey) throws ConfigurationException
ConfigurationExceptionpublic <T> List<T> getList(String key) throws ConfigurationException
ConfigurationExceptionpublic List<YConfiguration> getConfigList(String key) throws ConfigurationException
ConfigurationExceptionpublic double getDouble(String key) throws ConfigurationException
ConfigurationExceptionpublic double getDouble(String key, double defaultValue) throws ConfigurationException
ConfigurationExceptionpublic List<YConfiguration> getServiceConfigList(String key) throws ConfigurationException
key - ConfigurationExceptionpublic <T> List<T> getSubList(String key, String key1) throws ConfigurationException
ConfigurationExceptionpublic static boolean getBoolean(Map<String,Object> m, String key, boolean defaultValue) throws ConfigurationException
m - key - defaultValue - - the default value to return if m.get(key) does not exist.ConfigurationExceptionpublic static boolean getBoolean(Map<String,Object> m, String key) throws ConfigurationException
ConfigurationExceptionpublic boolean getBoolean(String key) throws ConfigurationException
ConfigurationExceptionpublic boolean getBoolean(String key, String key1) throws ConfigurationException
ConfigurationExceptionpublic boolean getBoolean(String key, boolean defaultValue)
public int getInt(String key) throws ConfigurationException
ConfigurationExceptionpublic int getInt(String key, int defaultValue) throws ConfigurationException
ConfigurationExceptionpublic int getInt(String key, String key1) throws ConfigurationException
ConfigurationExceptionpublic int getInt(String key, String key1, int defaultValue) throws ConfigurationException
ConfigurationExceptionpublic static int getInt(Map<String,Object> m, String key) throws ConfigurationException
ConfigurationExceptionpublic static int getInt(Map<String,Object> m, String key, int defaultValue) throws ConfigurationException
m - key - defaultValue - ConfigurationException - if the key is present but it's not an intpublic long getLong(String key)
public long getLong(String key, long defaultValue)
public static long getLong(Map<String,Object> m, String key) throws ConfigurationException
ConfigurationExceptionpublic static long getLong(Map<String,Object> m, String key, long v) throws ConfigurationException
m - key - v - ConfigurationException - if the key is present but it's not an longpublic static double getDouble(Map<String,Object> m, String key, double v) throws ConfigurationException
ConfigurationExceptionpublic boolean isList(String key)
public static void setResolver(YConfigurationResolver resolver)
public static YConfigurationResolver getResolver()
public static <T extends Enum<T>> T getEnum(Map<String,Object> config, String key, Class<T> enumClass)
config - key - enumClass - public static YConfiguration wrap(Map<String,Object> m)
m - public static YConfiguration emptyConfig()
public String toJson()
public String getPath()
public static <T> List<T> getList(Map<String,Object> m, String key) throws ConfigurationException
ConfigurationExceptionCopyright © 2019 Space Applications Services. All rights reserved.