public class ConfigurationDataHelper extends Object
| Constructor and Description | 
|---|
ConfigurationDataHelper(Map<String,String> parameters)  | 
| Modifier and Type | Method and Description | 
|---|---|
Map<String,Map<String,String>> | 
getAggregated(Pattern pattern)
Scan by prefix and aggregate by the remainder  
 | 
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. 
 | 
ConfigurationDataHelper | 
getPrefixedHelper(String prefix)
Create a configuration data helper containing only the parameters having
 the provided prefix, including their prefix removed. 
 | 
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 | 
getStringNonEmptyChecked(String name,
                        String errorMessage)
Get a non-null, non-empty string from the configuration data 
 | 
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 
 | 
TimeZone | 
getTimeZone(String name,
           TimeZone defaultValue)
Return the time zone  
Note: The method internally calls TimeZone.getTimeZone(String) in order
 to convert the configured string to the actual time zone. | 
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 parameternullpublic 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 setNumberFormatExceptionIllegalArgumentExceptionpublic Long getLong(String name)
null if the parameter is not set
 or not a longname - the name of the parameternullpublic 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 setNumberFormatExceptionIllegalArgumentExceptionpublic 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 getStringNonEmptyChecked(String name, String errorMessage) throws IllegalArgumentException
name - the name of the parameter to geterrorMessage - the error message if the string is not set or emptyIllegalArgumentException - if the string is not set or is emptypublic 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 prefixnullpublic Double getDouble(String name)
null if the parameter is not
 set or not an integername - the name of the parameternullpublic 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 setNumberFormatExceptionIllegalArgumentExceptionpublic Boolean getBoolean(String name)
null if the parameter is not
 set or not a booleanname - the name of the parameternullpublic 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 parameternullpublic Variant getVariant(String name, Variant defaultValue)
name - the name of the parameterdefaultValue - the default valuepublic Variant getVariantChecked(String name, String errorMessage) throws IllegalArgumentException
IllegalArgumentExceptionpublic 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 ConfigurationDataHelper getPrefixedHelper(String prefix)
prefix - the prefixgetPrefixed(String)public Properties getPrefixedProperties(String prefix)
Properties
 object
 
 Actually calls getPrefixed(String)
 
prefix - the prefix to usepublic Map<String,Map<String,String>> getAggregated(Pattern pattern)
This will aggregate from:
 
 a=b
 c=d
 entry.group1=foo
 entry.group1.a=value1
 entry.group1.b=value2
 entry.group2.a=value3
 entry.group2.c=value4
 
 
 Using the pattern "entry\\.(?". To:
 
 
 group1 = {
  a=value1
  b=value2
 }
 group2 = {
  a=value3
  c=value4
 }
 
 
Note: Key that do not match at all won't get transfered into the result maps.
data - the data to scanpattern - a pattern that identifies the group part and the key part from
            the original key. The pattern must have two named groups:
            "group" and "key".public <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)
protected static <E extends Enum<E>> String makeEnumError(Class<E> enumType, String stringValue)
public TimeZone getTimeZone(String name, TimeZone defaultValue)
TimeZone.getTimeZone(String) in order
 to convert the configured string to the actual time zone.name - the name of the parameterdefaultValue - the default valueCopyright © 2014 Eclipse SCADA Project. All rights reserved.