public class ConfigurationDataHelper extends Object
Constructor and Description |
---|
ConfigurationDataHelper(Map<String,String> parameters) |
Modifier and Type | Method and Description |
---|---|
Boolean |
getBoolean(String name)
Get a boolean from the data or
null if the parameter is not
set or not a boolean |
boolean |
getBoolean(String name,
boolean defaultValue)
Get a boolean from the data or the default value if the parameter is not
set or not a boolean
|
boolean |
getBooleanChecked(String name,
String errorMessage) |
Map<String,String> |
getData()
The actual configuration data
|
Double |
getDouble(String name)
Get an integer from the data or
null if the parameter is not
set or not an integer |
double |
getDouble(String name,
double defaultValue)
Get an integer from the data or the default value if the parameter is not
set or not an integer
|
double |
getDoubleChecked(String name,
String errorMessage)
Get an integer from the configuration data
|
<E extends Enum<E>> |
getEnum(String name,
Class<E> enumType) |
<E extends Enum<E>> |
getEnum(String name,
Class<E> enumType,
E defaultValue) |
<E extends Enum<E>> |
getEnumChecked(String name,
Class<E> enumType,
String errorMessage) |
Integer |
getInteger(String name)
Get an integer from the data or
null if the parameter is not
set or not an integer |
int |
getInteger(String name,
int defaultValue)
Get an integer from the data or the default value if the parameter is not
set or not an integer
|
int |
getIntegerChecked(String name,
String errorMessage)
Get an integer from the configuration data
|
Long |
getLong(String name)
Get a long from the data or
null if the parameter is not set
or not a long |
long |
getLong(String name,
long defaultValue)
Get a long from the data or the default value if the parameter is not set
or not a long
|
long |
getLongChecked(String name,
String errorMessage)
Get a long from the configuration data
|
Map<String,String> |
getPrefixed(String prefix)
Extracts attributes that start with a prefix and return the matching
entries only with the key truncated by the prefix.
|
Properties |
getPrefixedProperties(String prefix)
Convenience method to get prefixed attributes as
Properties
object |
String |
getString(String name)
Get a string from the configuration
|
String |
getString(String name,
String defaultValue) |
String |
getStringChecked(String name,
String errorMessage)
Get a string from the configuration data
|
String |
getStringNonEmpty(String name)
Get a non-empty string from the configuration.
|
String |
getStringOfChecked(String name,
Collection<String> whitelisted)
Get a whitelisted string from the configuration data
|
String |
getStringOfChecked(String name,
String defaultValue,
Collection<String> whitelisted)
Get a whitelisted string from the configuration data
|
Set<String> |
getStringSet(String prefix)
Get all values of the keys that start with a specific prefix
|
Variant |
getVariant(String name)
Get an variant from the data or
null if the parameter is not
set or not an variant |
Variant |
getVariant(String name,
Variant defaultValue)
Get an variant from the data or the default value if the parameter is not
set or not an variant
|
Variant |
getVariantChecked(String name,
String errorMessage) |
static <E extends Enum<E>> |
makeEnum(Class<E> enumType,
E defaultValue,
String stringValue,
boolean ignoreMissing) |
protected static <E extends Enum<E>> |
makeEnumError(Class<E> enumType,
String stringValue) |
public Map<String,String> getData()
public Integer getInteger(String name)
null
if the parameter is not
set or not an integername
- the name of the parameternull
public int getInteger(String name, int defaultValue)
name
- the name of the parameterdefaultValue
- the default valuepublic int getIntegerChecked(String name, String errorMessage) throws IllegalArgumentException, NumberFormatException
If the parameter is not set a IllegalArgumentException
will be
thrown. If the data can not be parsed to an integer a
NumberFormatException
will be thrown.
name
- the name of the parameter to geterrorMessage
- the error message if the string is not setNumberFormatException
IllegalArgumentException
public Long getLong(String name)
null
if the parameter is not set
or not a longname
- the name of the parameternull
public long getLong(String name, long defaultValue)
name
- the name of the parameterdefaultValue
- the default valuepublic long getLongChecked(String name, String errorMessage) throws IllegalArgumentException, NumberFormatException
If the parameter is not set a IllegalArgumentException
will be
thrown. If the data can not be parsed to a long a
NumberFormatException
will be thrown.
name
- the name of the parameter to geterrorMessage
- the error message if the string is not setNumberFormatException
IllegalArgumentException
public String getStringNonEmpty(String name)
name
- the name of the parameters to getnull
if the parameter is not set or is an
empty string. Otherwise the string itself will be returned.public String getString(String name)
name
- the name of the string to getnull
if the string was not setpublic String getStringChecked(String name, String errorMessage) throws IllegalArgumentException
name
- the name of the parameter to geterrorMessage
- the error message if the string is not setIllegalArgumentException
- if the string is not setpublic String getStringOfChecked(String name, Collection<String> whitelisted) throws IllegalArgumentException
name
- the name of the parameter to getwhitelist
- the list of allowed valuesIllegalArgumentException
- if the string is not setpublic String getStringOfChecked(String name, String defaultValue, Collection<String> whitelisted) throws IllegalArgumentException
name
- the name of the parameter to getdefaultValue
- the default valuewhitelist
- the list of allowed valuesIllegalArgumentException
- if the string is not setpublic Set<String> getStringSet(String prefix)
prefix
- the prefixnull
public Double getDouble(String name)
null
if the parameter is not
set or not an integername
- the name of the parameternull
public double getDouble(String name, double defaultValue)
name
- the name of the parameterdefaultValue
- the default valuepublic double getDoubleChecked(String name, String errorMessage) throws IllegalArgumentException, NumberFormatException
If the parameter is not set a IllegalArgumentException
will be
thrown. If the data can not be parsed to an integer a
NumberFormatException
will be thrown.
name
- the name of the parameter to geterrorMessage
- the error message if the string is not setNumberFormatException
IllegalArgumentException
public Boolean getBoolean(String name)
null
if the parameter is not
set or not a booleanname
- the name of the parameternull
public boolean getBoolean(String name, boolean defaultValue)
name
- the name of the parameterdefaultValue
- the default valuepublic Variant getVariant(String name)
null
if the parameter is not
set or not an variantname
- the name of the parameternull
public Variant getVariant(String name, Variant defaultValue)
name
- the name of the parameterdefaultValue
- the default valuepublic Variant getVariantChecked(String name, String errorMessage) throws IllegalArgumentException
IllegalArgumentException
public Map<String,String> getPrefixed(String prefix)
If you want your prefix to be "prefix." you must also add the dot.
prefix
- the prefix to usepublic Properties getPrefixedProperties(String prefix)
Properties
object
Actually calls getPrefixed(String)
prefix
- the prefix to usepublic <E extends Enum<E>> E getEnumChecked(String name, Class<E> enumType, String errorMessage)
public static <E extends Enum<E>> E makeEnum(Class<E> enumType, E defaultValue, String stringValue, boolean ignoreMissing)