Package com.saperion.util.configuration
Class ConfigHolder
- java.lang.Object
-
- com.saperion.util.configuration.ConfigHolder
-
public final class ConfigHolder extends java.lang.Object
This class is a singleton configuration holder. Once the configuration settings are set they will be available for the rest of the application as long as the application itself runs.- Author:
- sts
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,java.lang.Object>
configs
Configurations map.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(java.lang.String key, java.lang.Object value)
Adds the given key-value pair to this holder.void
addAll(java.util.Properties properties)
Adds all properities contained in the given Properties object to this holder.java.lang.Object
get(java.lang.String key, java.lang.Object defaultValue)
Returns the value for the given key as an Object if existing.java.util.Properties
getAll()
Returns all properties of this holder as a Properties object.boolean
getAsBoolean(java.lang.String key, boolean defaultValue)
Returns the value for the given key as a Boolean if existing.int
getAsInteger(java.lang.String key, int defaultValue)
Returns the value for the given key as an Integer if existing.java.lang.String
getAsString(java.lang.String key, java.lang.String defaultValue)
Returns the value for the given key as a String if existing.static ConfigHolder
getInstance()
Returns an instance of this class.java.lang.String
printCurrentConfigs()
-
-
-
Method Detail
-
getInstance
public static ConfigHolder getInstance()
Returns an instance of this class. Creates the instance if it is not existing yet.- Returns:
- The ConfigHolder instance.
-
addAll
public void addAll(java.util.Properties properties)
Adds all properities contained in the given Properties object to this holder.- Parameters:
properties
- The Properties to hold.
-
getAll
public java.util.Properties getAll()
Returns all properties of this holder as a Properties object. Manipulations on the returned Properties object do not affect this holders properties.- Returns:
- properties of this holder.
-
add
public void add(java.lang.String key, java.lang.Object value)
Adds the given key-value pair to this holder.- Parameters:
key
- The key of the configuration.value
- The value of the configuration.
-
get
public java.lang.Object get(java.lang.String key, java.lang.Object defaultValue)
Returns the value for the given key as an Object if existing. Otherwise the given default value is returned.- Parameters:
key
- The key for the configuration value to get.defaultValue
- The default value if the configuration is not existing.- Returns:
- the value for the given key as an Object if existing. Otherwise the given default value is returned.
-
getAsBoolean
public boolean getAsBoolean(java.lang.String key, boolean defaultValue)
Returns the value for the given key as a Boolean if existing. Otherwise the given default value is returned.- Parameters:
key
- The key for the configuration value to get.defaultValue
- default value if the configuration is not existing.- Returns:
- the value for the given key as a Boolean if existing. Otherwise the given default value is returned.
-
getAsInteger
public int getAsInteger(java.lang.String key, int defaultValue)
Returns the value for the given key as an Integer if existing. Otherwise the given default value is returned.- Parameters:
key
- The key for the configuration value to get.defaultValue
- default value if the configuration is not existing.- Returns:
- the value for the given key as an Integer if existing. Otherwise the given default value is returned.
-
getAsString
public java.lang.String getAsString(java.lang.String key, java.lang.String defaultValue)
Returns the value for the given key as a String if existing. Otherwise the given default value is returned.- Parameters:
key
- The key for the configuration value to get.defaultValue
- default value if the configuration is not existing.- Returns:
- the value for the given key as a String if existing. Otherwise the given default value is returned.
-
printCurrentConfigs
public java.lang.String printCurrentConfigs()
-
-