public class ConfigurationDataHelper
extends java.lang.Object
| Constructor and Description |
|---|
ConfigurationDataHelper(java.util.Map<java.lang.String,java.lang.String> parameters) |
| Modifier and Type | Method and Description |
|---|---|
java.lang.Boolean |
getBoolean(java.lang.String name)
Get a boolean from the data or
null if the parameter is not
set or not a boolean |
boolean |
getBoolean(java.lang.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(java.lang.String name,
java.lang.String errorMessage) |
java.util.Map<java.lang.String,java.lang.String> |
getData()
The actual configuration data
|
java.lang.Double |
getDouble(java.lang.String name)
Get an integer from the data or
null if the parameter is not
set or not an integer |
double |
getDouble(java.lang.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(java.lang.String name,
java.lang.String errorMessage)
Get an integer from the configuration data
|
<E extends java.lang.Enum<E>> |
getEnum(java.lang.String name,
java.lang.Class<E> enumType) |
<E extends java.lang.Enum<E>> |
getEnum(java.lang.String name,
java.lang.Class<E> enumType,
E defaultValue) |
<E extends java.lang.Enum<E>> |
getEnumChecked(java.lang.String name,
java.lang.Class<E> enumType,
java.lang.String errorMessage) |
java.lang.Integer |
getInteger(java.lang.String name)
Get an integer from the data or
null if the parameter is not
set or not an integer |
int |
getInteger(java.lang.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(java.lang.String name,
java.lang.String errorMessage)
Get an integer from the configuration data
|
java.lang.Long |
getLong(java.lang.String name)
Get a long from the data or
null if the parameter is not set
or not a long |
long |
getLong(java.lang.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(java.lang.String name,
java.lang.String errorMessage)
Get a long from the configuration data
|
java.util.Map<java.lang.String,java.lang.String> |
getPrefixed(java.lang.String prefix)
Extracts attributes that start with a prefix and return the matching
entries only with the key truncated by the prefix.
|
java.util.Properties |
getPrefixedProperties(java.lang.String prefix)
Convenience method to get prefixed attributes as
Properties
object |
java.lang.String |
getString(java.lang.String name)
Get a string from the configuration
|
java.lang.String |
getString(java.lang.String name,
java.lang.String defaultValue) |
java.lang.String |
getStringChecked(java.lang.String name,
java.lang.String errorMessage)
Get a string from the configuration data
|
java.lang.String |
getStringNonEmpty(java.lang.String name)
Get a non-empty string from the configuration.
|
java.lang.String |
getStringOfChecked(java.lang.String name,
java.util.Collection<java.lang.String> whitelisted)
Get a whitelisted string from the configuration data
|
java.lang.String |
getStringOfChecked(java.lang.String name,
java.lang.String defaultValue,
java.util.Collection<java.lang.String> whitelisted)
Get a whitelisted string from the configuration data
|
java.util.Set<java.lang.String> |
getStringSet(java.lang.String prefix)
Get all values of the keys that start with a specific prefix
|
static <E extends java.lang.Enum<E>> |
makeEnum(java.lang.Class<E> enumType,
E defaultValue,
java.lang.String stringValue,
boolean ignoreMissing) |
protected static <E extends java.lang.Enum<E>> |
makeEnumError(java.lang.Class<E> enumType,
java.lang.String stringValue) |
public ConfigurationDataHelper(java.util.Map<java.lang.String,java.lang.String> parameters)
public java.util.Map<java.lang.String,java.lang.String> getData()
public java.lang.Integer getInteger(java.lang.String name)
null if the parameter is not
set or not an integername - the name of the parameternullpublic int getInteger(java.lang.String name,
int defaultValue)
name - the name of the parameterdefaultValue - the default valuepublic int getIntegerChecked(java.lang.String name,
java.lang.String errorMessage)
throws java.lang.IllegalArgumentException,
java.lang.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 setjava.lang.NumberFormatExceptionjava.lang.IllegalArgumentExceptionpublic java.lang.Long getLong(java.lang.String name)
null if the parameter is not set
or not a longname - the name of the parameternullpublic long getLong(java.lang.String name,
long defaultValue)
name - the name of the parameterdefaultValue - the default valuepublic long getLongChecked(java.lang.String name,
java.lang.String errorMessage)
throws java.lang.IllegalArgumentException,
java.lang.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 setjava.lang.NumberFormatExceptionjava.lang.IllegalArgumentExceptionpublic java.lang.String getStringNonEmpty(java.lang.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 java.lang.String getString(java.lang.String name)
name - the name of the string to getnull if the string was not setpublic java.lang.String getString(java.lang.String name,
java.lang.String defaultValue)
public java.lang.String getStringChecked(java.lang.String name,
java.lang.String errorMessage)
throws java.lang.IllegalArgumentException
name - the name of the parameter to geterrorMessage - the error message if the string is not setjava.lang.IllegalArgumentException - if the string is not setpublic java.lang.String getStringOfChecked(java.lang.String name,
java.util.Collection<java.lang.String> whitelisted)
throws java.lang.IllegalArgumentException
name - the name of the parameter to getwhitelist - the list of allowed valuesjava.lang.IllegalArgumentException - if the string is not setpublic java.lang.String getStringOfChecked(java.lang.String name,
java.lang.String defaultValue,
java.util.Collection<java.lang.String> whitelisted)
throws java.lang.IllegalArgumentException
name - the name of the parameter to getdefaultValue - the default valuewhitelist - the list of allowed valuesjava.lang.IllegalArgumentException - if the string is not setpublic java.util.Set<java.lang.String> getStringSet(java.lang.String prefix)
prefix - the prefixnullpublic java.lang.Double getDouble(java.lang.String name)
null if the parameter is not
set or not an integername - the name of the parameternullpublic double getDouble(java.lang.String name,
double defaultValue)
name - the name of the parameterdefaultValue - the default valuepublic double getDoubleChecked(java.lang.String name,
java.lang.String errorMessage)
throws java.lang.IllegalArgumentException,
java.lang.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 setjava.lang.NumberFormatExceptionjava.lang.IllegalArgumentExceptionpublic boolean getBooleanChecked(java.lang.String name,
java.lang.String errorMessage)
public java.lang.Boolean getBoolean(java.lang.String name)
null if the parameter is not
set or not a booleanname - the name of the parameternullpublic boolean getBoolean(java.lang.String name,
boolean defaultValue)
name - the name of the parameterdefaultValue - the default valuepublic java.util.Map<java.lang.String,java.lang.String> getPrefixed(java.lang.String prefix)
If you want your prefix to be "prefix." you must also add the dot.
prefix - the prefix to usepublic java.util.Properties getPrefixedProperties(java.lang.String prefix)
Properties
object
Actually calls getPrefixed(String)
prefix - the prefix to usepublic <E extends java.lang.Enum<E>> E getEnumChecked(java.lang.String name,
java.lang.Class<E> enumType,
java.lang.String errorMessage)
public <E extends java.lang.Enum<E>> E getEnum(java.lang.String name,
java.lang.Class<E> enumType)
public <E extends java.lang.Enum<E>> E getEnum(java.lang.String name,
java.lang.Class<E> enumType,
E defaultValue)
public static <E extends java.lang.Enum<E>> E makeEnum(java.lang.Class<E> enumType,
E defaultValue,
java.lang.String stringValue,
boolean ignoreMissing)
protected static <E extends java.lang.Enum<E>> java.lang.String makeEnumError(java.lang.Class<E> enumType,
java.lang.String stringValue)
Copyright (c) IBH SYSTEMS GmbH and others 2010, 2013.
All rights reserved. This program and the accompanying materials
are made available under the terms of the
Eclipse Public License v1.0