| Modifier and Type | Field and Description |
|---|---|
static String |
STRIP_SUFFIX
A suffix that is automatically appended to property keys that are prefixes of other
property keys.
|
| Constructor and Description |
|---|
ConfigUtils() |
| Modifier and Type | Method and Description |
|---|---|
static Properties |
configToProperties(Config config)
Convert a given
Config instance to a Properties instance. |
static Properties |
configToProperties(Config config,
Optional<String> prefix)
Convert a given
Config instance to a Properties instance. |
static Properties |
configToProperties(Config config,
String prefix)
Convert a given
Config instance to a Properties instance. |
static State |
configToState(Config config)
|
static String |
desanitizeKey(String propKey) |
static String |
emptyIfNotPresent(Config config,
String path)
Return string value at
path if config has path. |
static Set<String> |
findFullPrefixKeys(Properties properties,
Optional<String> keyPrefix)
Finds a list of properties whose keys are complete prefix of other keys.
|
static boolean |
getBoolean(Config config,
String path,
boolean def)
Return boolean value at
path if config has path. |
static Config |
getConfig(Config config,
String path,
Config def)
|
static Config |
getConfigOrEmpty(Config config,
String key) |
static double |
getDouble(Config config,
String path,
double def)
Return double value at
path if config has path. |
static Integer |
getInt(Config config,
String path,
Integer def)
|
static Long |
getLong(Config config,
String path,
Long def)
|
static String |
getString(Config config,
String path,
String def)
Return string value at
path if config has path. |
static List<String> |
getStringList(Config config,
String path)
An extension to
Config.getStringList(String). |
static boolean |
hasNonEmptyPath(Config config,
String key)
Check if the given
key exists in config and it is not null or empty
Uses StringUtils.isNotBlank(CharSequence) |
static Config |
propertiesToConfig(Properties properties)
Convert a given
Properties to a Config instance. |
static Config |
propertiesToConfig(Properties properties,
Optional<String> prefix)
|
static Config |
propertiesToTypedConfig(Properties properties,
Optional<String> prefix)
|
static Config |
resolveEncrypted(Config config,
Optional<String> encConfigPath)
Resolves encrypted config value(s) by considering on the path with "encConfigPath" as encrypted.
|
static String |
sanitizeFullPrefixKey(String propKey) |
static boolean |
verifySubset(Config superConfig,
Config subConfig)
Check that every key-value in superConfig is in subConfig
|
public static final String STRIP_SUFFIX
public static Properties configToProperties(Config config)
Config instance to a Properties instance.config - the given Config instanceProperties instancepublic static Properties configToProperties(Config config, Optional<String> prefix)
Config instance to a Properties instance.config - the given Config instanceprefix - an optional prefix; if present, only properties whose name starts with the prefix
will be returned.Properties instancepublic static Properties configToProperties(Config config, String prefix)
Config instance to a Properties instance.config - the given Config instanceprefix - only properties whose name starts with the prefix will be returned.Properties instancepublic static Config getConfigOrEmpty(Config config, String key)
public static Config propertiesToConfig(Properties properties)
Properties to a Config instance.
This method will throw an exception if (1) the Object.toString() method of any two keys in the
Properties objects returns the same String, or (2) if any two keys are prefixes of one another,
see the Java Docs of ConfigFactory.parseMap(Map) for more details.
properties - the given Properties instanceConfig instancepublic static Set<String> findFullPrefixKeys(Properties properties, Optional<String> keyPrefix)
properties - the Properties collection to inspectkeyPrefix - an optional key prefix which limits which properties are inspected.public static Config propertiesToConfig(Properties properties, Optional<String> prefix)
prefix in Properties to a Config instance.
This method will throw an exception if (1) the Object.toString() method of any two keys in the
Properties objects returns the same String, or (2) if any two keys are prefixes of one another,
see the Java Docs of ConfigFactory.parseMap(Map) for more details.
properties - the given Properties instanceprefix - of keys to be convertedConfig instancepublic static Config propertiesToTypedConfig(Properties properties, Optional<String> prefix)
prefix in Properties to a
Config instance. The method also tries to guess the types of properties.
This method will throw an exception if (1) the Object.toString() method of any two keys in the
Properties objects returns the same String, or (2) if any two keys are prefixes of one another,
see the Java Docs of ConfigFactory.parseMap(Map) for more details.
properties - the given Properties instanceprefix - of keys to be convertedConfig instancepublic static String emptyIfNotPresent(Config config, String path)
path if config has path. If not return an empty stringconfig - in which the path may be presentpath - key to look for in the config objectpath if config has path. If not return an empty stringpublic static String getString(Config config, String path, String def)
path if config has path. If not return defconfig - in which the path may be presentpath - key to look for in the config objectpath if config has path. If not return defpublic static Long getLong(Config config, String path, Long def)
config - in which the path may be presentpath - key to look for in the config objectLong value at path if config has path. If not return defpublic static Integer getInt(Config config, String path, Integer def)
config - in which the path may be presentpath - key to look for in the config objectInteger value at path if config has path. If not return defpublic static boolean getBoolean(Config config, String path, boolean def)
path if config has path. If not return defconfig - in which the path may be presentpath - key to look for in the config objectpath if config has path. If not return defpublic static double getDouble(Config config, String path, double def)
path if config has path. If not return defconfig - in which the path may be presentpath - key to look for in the config objectpath if config has path. If not return defpublic static Config getConfig(Config config, String path, Config def)
config - in which the path may be presentpath - key to look for in the config objectpath if config has path. If not return defpublic static List<String> getStringList(Config config, String path)
An extension to Config.getStringList(String). The value at path can either be a TypeSafe
ConfigList of strings in which case it delegates to Config.getStringList(String) or as list of
comma separated strings in which case it splits the comma separated list.
path does not exist
config - in which the path may be presentpath - key to look for in the config objectpublic static boolean hasNonEmptyPath(Config config, String key)
key exists in config and it is not null or empty
Uses StringUtils.isNotBlank(CharSequence)config - which may have the keykey - to look for in the configpublic static boolean verifySubset(Config superConfig, Config subConfig)
public static Config resolveEncrypted(Config config, Optional<String> encConfigPath)
config - encConfigPath -