Package kieker.common.configuration
Class Configuration
java.lang.Object
java.util.Dictionary<K,V>
java.util.Hashtable<java.lang.Object,java.lang.Object>
java.util.Properties
kieker.common.configuration.Configuration
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.util.Map<java.lang.Object,java.lang.Object>
- Direct Known Subclasses:
ReadOnlyConfiguration
public class Configuration
extends java.util.Properties
This class represents a configuration object within the Kieker project. Technically it is a property list with some additional methods and possibilities.
Some of the methods are marked as deprecated. This is not because they will be removed, but rather because they should not be used anymore (at least not directly
- they are still used in a valid way within this class). Normally we would remove them, but they are inherited from the class
Properties
and can neither
be removed nor get a lower visibility modificator.- Since:
- 1.5
- Author:
- Jan Waller
- See Also:
- Serialized Form
-
Field Summary
-
Constructor Summary
Constructors Constructor Description Configuration()
Creates a new (empty) configuration.Configuration(java.util.Properties defaults)
Creates a new instance of this class using the given parameters. -
Method Summary
Modifier and Type Method Description static java.lang.String
convertToPath(java.lang.String pathname)
Based upon Guava 14.0.1 (Chris Nokleberg, Colin Decker).Configuration
flatten()
Flattens the Properties hierarchies and returns a new Configuration object.Configuration
flatten(Configuration defaultConfiguration)
Flattens the Properties hierarchies and returns a new Configuration object.void
flattenInPlace()
Flattens the Properties hierarchies with this Configuration.java.lang.Object
get(java.lang.Object key)
Deprecated.This method will not be removed (as this is for technical reasons not possible), but should only be used within this class.boolean
getBooleanProperty(java.lang.String key)
Reads the given property from the configuration and interprets it as a boolean.boolean
getBooleanProperty(java.lang.String key, boolean defaultValue)
Reads the given property from the configuration and interprets it as a boolean.double
getDoubleProperty(java.lang.String key)
Reads the given property from the configuration and interprets it as a double.double
getDoubleProperty(java.lang.String key, double defaultValue)
Reads the given property from the configuration and interprets it as a double.<T extends java.lang.Enum<T>>
TgetEnumProperty(java.lang.String key, java.lang.Class<T> enumType, T defaultValue)
Reads the given property from the configuration and interprets it as a double.int
getIntProperty(java.lang.String key)
Reads the given property from the configuration and interprets it as an integer.int
getIntProperty(java.lang.String key, int defaultValue)
Reads the given property from the configuration and interprets it as an integer.long
getLongProperty(java.lang.String key)
Reads the given property from the configuration and interprets it as a long.long
getLongProperty(java.lang.String key, long defaultValue)
Reads the given property from the configuration and interprets it as a long.java.lang.String
getPathProperty(java.lang.String key)
Reads the given property from the configuration and interprets it as a path.Configuration
getPropertiesStartingWith(java.lang.String prefix)
Flattens the Properties hierarchies and returns a Configuration object containing only keys starting with the prefix.java.lang.String
getProperty(java.lang.String key)
Deprecated.This method will not be removed (as this is for technical reasons not possible), but should only be used within this class.java.lang.String
getProperty(java.lang.String key, java.lang.String defaultValue)
Deprecated.This method will not be removed (as this is for technical reasons not possible), but should only be used within this class.java.lang.String[]
getStringArrayProperty(java.lang.String key)
Interprets the property (defined by the given key) as an array of values and transforms it into a real array.java.lang.String[]
getStringArrayProperty(java.lang.String key, java.lang.String split)
Interprets the property (defined by the given key) as an array of values and transforms it into a real array.java.lang.String
getStringProperty(java.lang.String key)
Reads the given property from the configuration and interprets it as a string.java.lang.String
getStringProperty(java.lang.String key, java.lang.String defaultValue)
Reads the given property from the configuration and interprets it as a string.java.lang.Object
put(java.lang.Object key, java.lang.Object value)
Deprecated.This method will not be removed (as this is for technical reasons not possible), but should only be used within this class.void
setDefaultConfiguration(Configuration defaultConfiguration)
You should know what you do if you use this method! Currently it is used for a (dirty) hack to add default configurations to Writers or AnalysisPlugins.void
setProperty(java.lang.String key, boolean value)
Convenience method to set boolean-valued properties.void
setProperty(java.lang.String key, double value)
Convenience method to set double-valued properties.void
setProperty(java.lang.String key, int value)
Convenience method to set int-valued properties.void
setProperty(java.lang.String key, long value)
Convenience method to set long-valued properties.void
setStringArrayProperty(java.lang.String key, java.lang.String[] value)
Sets a property to the given string array.static java.lang.String
toProperty(java.lang.Object[] values)
Converts the Object[] to a String split by '|'.Methods inherited from class java.util.Properties
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, getOrDefault, hashCode, isEmpty, keys, keySet, list, list, load, load, loadFromXML, merge, propertyNames, putAll, putIfAbsent, rehash, remove, remove, replace, replace, replaceAll, save, setProperty, size, store, store, storeToXML, storeToXML, storeToXML, stringPropertyNames, toString, values
-
Constructor Details
-
Configuration
public Configuration()Creates a new (empty) configuration. -
Configuration
public Configuration(java.util.Properties defaults)Creates a new instance of this class using the given parameters.- Parameters:
defaults
- The property object which delivers the default values for the new configuration.
-
-
Method Details
-
getStringProperty
public final java.lang.String getStringProperty(java.lang.String key)Reads the given property from the configuration and interprets it as a string.- Parameters:
key
- The key of the property.- Returns:
- A string with the value of the given property or the empty string, if the property does not exist.
-
getStringProperty
public final java.lang.String getStringProperty(java.lang.String key, java.lang.String defaultValue)Reads the given property from the configuration and interprets it as a string.- Parameters:
key
- The key of the property.defaultValue
- The default value for the givenkey
- Returns:
- A string with the value of the given property or the given
defaultValue
, if the property does not exist.
-
getBooleanProperty
public final boolean getBooleanProperty(java.lang.String key)Reads the given property from the configuration and interprets it as a boolean.- Parameters:
key
- The key of the property.- Returns:
- A boolean with the value of the given property or null, if the property does not exist.
-
getBooleanProperty
public final boolean getBooleanProperty(java.lang.String key, boolean defaultValue)Reads the given property from the configuration and interprets it as a boolean. If no value exists for this property, the given default value is returned.- Parameters:
key
- The key of the property.defaultValue
- The default value for this property- Returns:
- A boolean with the value of the given property or the default value
-
setProperty
public void setProperty(java.lang.String key, boolean value)Convenience method to set boolean-valued properties.- Parameters:
key
- The key to be placed in this configurationvalue
- The value to be stored for the given key
-
getIntProperty
public final int getIntProperty(java.lang.String key)Reads the given property from the configuration and interprets it as an integer.- Parameters:
key
- The key of the property.- Returns:
- An integer with the value of the given property or zero, if the property does not exist.
-
getIntProperty
public final int getIntProperty(java.lang.String key, int defaultValue)Reads the given property from the configuration and interprets it as an integer. If no value exists for this property, the given default value is returned.- Parameters:
key
- The key of the property.defaultValue
- The default value for this property- Returns:
- An integer with the value of the given property or the default value
-
setProperty
public void setProperty(java.lang.String key, int value)Convenience method to set int-valued properties.- Parameters:
key
- The key to be placed in this configurationvalue
- The value to be stored for the given key
-
getLongProperty
public final long getLongProperty(java.lang.String key)Reads the given property from the configuration and interprets it as a long.- Parameters:
key
- The key of the property.- Returns:
- A long with the value of the given property or null, if the property does not exist.
-
getLongProperty
public final long getLongProperty(java.lang.String key, long defaultValue)Reads the given property from the configuration and interprets it as a long. If no value exists for this property, the given default value is returned.- Parameters:
key
- The key of the property.defaultValue
- The default value for this property- Returns:
- A long with the value of the given property or the default value
-
setProperty
public void setProperty(java.lang.String key, long value)Convenience method to set long-valued properties.- Parameters:
key
- The key to be placed in this configurationvalue
- The value to be stored for the given key
-
getDoubleProperty
public final double getDoubleProperty(java.lang.String key)Reads the given property from the configuration and interprets it as a double.- Parameters:
key
- The key of the property.- Returns:
- A long with the value of the given property or null, if the property does not exist.
-
getDoubleProperty
public final double getDoubleProperty(java.lang.String key, double defaultValue)Reads the given property from the configuration and interprets it as a double. If no value exists for this property, the given default value is returned.- Parameters:
key
- The key of the property.defaultValue
- The default value for this property- Returns:
- A double with the value of the given property or the default value
-
getEnumProperty
public final <T extends java.lang.Enum<T>> T getEnumProperty(java.lang.String key, java.lang.Class<T> enumType, T defaultValue)Reads the given property from the configuration and interprets it as a double. If no value exists for this property, the given default value is returned.- Parameters:
key
- The key of the property.defaultValue
- The default value for this property- Returns:
- A double with the value of the given property or the default value
-
setProperty
public void setProperty(java.lang.String key, double value)Convenience method to set double-valued properties.- Parameters:
key
- The key to be placed in this configurationvalue
- The value to be stored for the given key
-
getPathProperty
public final java.lang.String getPathProperty(java.lang.String key)Reads the given property from the configuration and interprets it as a path.- Parameters:
key
- The key of the property.- Returns:
- A string with the value of the given property or null, if the property does not exist.
-
getStringArrayProperty
public final java.lang.String[] getStringArrayProperty(java.lang.String key)Interprets the property (defined by the given key) as an array of values and transforms it into a real array. Property values have to be split by '|'.- Parameters:
key
- The key of the property.- Returns:
- A string array containing the single values of the properties.
-
setStringArrayProperty
public void setStringArrayProperty(java.lang.String key, java.lang.String[] value)Sets a property to the given string array. Note that the values must not contain the separator character '|'.- Parameters:
key
- The key of the property to changevalue
- The array to set
-
getStringArrayProperty
public final java.lang.String[] getStringArrayProperty(java.lang.String key, java.lang.String split)Interprets the property (defined by the given key) as an array of values and transforms it into a real array. Property values have to be split by 'split'.- Parameters:
split
- a regular expressionkey
- The key of the property.- Returns:
- A string array containing the single values of the properties.
- See Also:
toProperty(Object[])
-
toProperty
public static final java.lang.String toProperty(java.lang.Object[] values)Converts the Object[] to a String split by '|'.- Parameters:
values
- The values which will be transformed into a string.- Returns:
- A string representation of the given values array.
- See Also:
getStringArrayProperty(String)
,getStringArrayProperty(String, String)
-
convertToPath
public static final java.lang.String convertToPath(java.lang.String pathname)Based upon Guava 14.0.1 (Chris Nokleberg, Colin Decker). Guava is licensed under "The Apache Software License, Version 2.0". Simplifies a given file system path.- Parameters:
pathname
- The path to be simplified.- Returns:
- A simplified version of the given path.
-
getPropertiesStartingWith
Flattens the Properties hierarchies and returns a Configuration object containing only keys starting with the prefix.- Parameters:
prefix
- The prefix to be used during the flattening.- Returns:
- A new configuration object with a flattened properties hierarchy.
-
flatten
Flattens the Properties hierarchies and returns a new Configuration object.- Parameters:
defaultConfiguration
- The configuration which will be used as a base.- Returns:
- A new configuration object with a flattened properties hierarchy.
-
flatten
Flattens the Properties hierarchies and returns a new Configuration object.- Returns:
- A new configuration object with a flattened properties hierarchy.
-
flattenInPlace
public final void flattenInPlace()Flattens the Properties hierarchies with this Configuration. Afterwards, all Properties will still be present and defaults will be null. -
setDefaultConfiguration
You should know what you do if you use this method! Currently it is used for a (dirty) hack to add default configurations to Writers or AnalysisPlugins.- Parameters:
defaultConfiguration
- The default configuration for this configuration object.
-
put
@Deprecated public final java.lang.Object put(java.lang.Object key, java.lang.Object value)Deprecated.This method will not be removed (as this is for technical reasons not possible), but should only be used within this class. Don't call this method directly.Puts a given key value pair into the container. This method should never be used directly! UseProperties.setProperty(String, String)
instead!- Specified by:
put
in interfacejava.util.Map<java.lang.Object,java.lang.Object>
- Overrides:
put
in classjava.util.Properties
- Parameters:
key
- The key which will be used to store the given value.value
- The value to store.- Returns:
- The old object which was stored under the given key or null if there wasn't a value before.
-
get
@Deprecated public final java.lang.Object get(java.lang.Object key)Deprecated.This method will not be removed (as this is for technical reasons not possible), but should only be used within this class. Don't call this method directly.Searches for a given key. This method should never be used directly! UsegetStringProperty(String)
instead!- Specified by:
get
in interfacejava.util.Map<java.lang.Object,java.lang.Object>
- Overrides:
get
in classjava.util.Properties
- Parameters:
key
- The key for the value in question.- Returns:
- The value for the specified key if available, null otherwise.
-
getProperty
@Deprecated public final java.lang.String getProperty(java.lang.String key)Deprecated.This method will not be removed (as this is for technical reasons not possible), but should only be used within this class. Don't call this method directly.Searches for a given property key. This method should never be used directly! UsegetStringProperty(String)
instead!- Overrides:
getProperty
in classjava.util.Properties
- Parameters:
key
- The key for the property in question.- Returns:
- The property for the specified key if available, null otherwise.
-
getProperty
@Deprecated public final java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)Deprecated.This method will not be removed (as this is for technical reasons not possible), but should only be used within this class. Don't call this method directly.Searches for a given property key. This method should never be used directly!- Overrides:
getProperty
in classjava.util.Properties
- Parameters:
key
- The key for the property in question.defaultValue
- The default value to be returned.- Returns:
- The property for the specified key if available, the given default value otherwise.
-