Package ai.dat.core.configuration
Class Configuration
java.lang.Object
ai.dat.core.configuration.Configuration
- All Implemented Interfaces:
ReadableConfig,WritableConfig
Lightweight configuration object which stores key/value pairs.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new empty configuration.Configuration(Configuration other) Creates a new configuration with the copy of the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAll(Configuration other) voidaddAll(Configuration other, String prefix) Adds all entries from the given configuration into this configuration.voidaddAllToProperties(Properties props) Adds all entries in thisConfigurationto the givenProperties.booleancontains(ConfigOption<?> configOption) Checks whether there is an entry for the given config option.booleancontainsKey(String key) Checks whether there is an entry with the specified key.static ConfigurationCreates a new configuration that is initialized with the options of the given map.<T> Tget(ConfigOption<T> option) Please check the java doc ofgetRawValueFromOption(ConfigOption).booleangetBoolean(ConfigOption<Boolean> configOption) Returns the value associated with the given config option as a boolean.booleangetBoolean(ConfigOption<Boolean> configOption, boolean overrideDefault) Returns the value associated with the given config option as a boolean.byte[]Returns the value associated with the given key as a byte array.<T> Class<T>getClass(String key, Class<? extends T> defaultValue, ClassLoader classLoader) Returns the class associated with the given key as a string.doublegetDouble(ConfigOption<Double> configOption) Returns the value associated with the given config option as adouble.doublegetDouble(ConfigOption<Double> configOption, double overrideDefault) Returns the value associated with the given config option as adouble.<T extends Enum<T>>
TgetEnum(Class<T> enumClass, ConfigOption<String> configOption) Returns the value associated with the given config option as an enum.floatgetFloat(ConfigOption<Float> configOption) Returns the value associated with the given config option as a float.floatgetFloat(ConfigOption<Float> configOption, float overrideDefault) Returns the value associated with the given config option as a float.intgetInteger(ConfigOption<Integer> configOption) Returns the value associated with the given config option as an integer.intgetInteger(ConfigOption<Integer> configOption, int overrideDefault) Returns the value associated with the given config option as an integer.longgetLong(ConfigOption<Long> configOption) Returns the value associated with the given config option as a long integer.longgetLong(ConfigOption<Long> configOption, long overrideDefault) Returns the value associated with the given config option as a long integer.<T> Optional<T>getOptional(ConfigOption<T> option) Reads a value using the metadata included inConfigOption.getString(ConfigOption<String> configOption) Returns the value associated with the given config option as a string.getString(ConfigOption<String> configOption, String overrideDefault) Returns the value associated with the given config option as a string.getValue(ConfigOption<?> configOption) Returns the value associated with the given config option as a string.keySet()Returns the keys of all key/value pairs stored inside this configuration object.<T> booleanremoveConfig(ConfigOption<T> configOption) Removes given config option from the configuration.booleanRemoves given key from the configuration.<T> Configurationset(ConfigOption<T> option, T value) Stores a given value using the metadata included in theConfigOption.voidsetBoolean(ConfigOption<Boolean> key, boolean value) Adds the given value to the configuration object.voidsetBoolean(String key, boolean value) Adds the given key/value pair to the configuration object.voidAdds the given byte array to the configuration object.voidAdds the given key/value pair to the configuration object.voidsetDouble(ConfigOption<Double> key, double value) Adds the given value to the configuration object.voidAdds the given key/value pair to the configuration object.voidsetFloat(ConfigOption<Float> key, float value) Adds the given value to the configuration object.voidAdds the given key/value pair to the configuration object.voidsetInteger(ConfigOption<Integer> key, int value) Adds the given value to the configuration object.voidsetInteger(String key, int value) Adds the given key/value pair to the configuration object.voidsetLong(ConfigOption<Long> key, long value) Adds the given value to the configuration object.voidAdds the given key/value pair to the configuration object.voidsetString(ConfigOption<String> key, String value) Adds the given value to the configuration object.voidAdds the given key/value pair to the configuration object.toMap()Converts the configuration items into a map of string key-value pairs.
-
Field Details
-
confData
Stores the concrete key/value pairs of this configuration object.
-
-
Constructor Details
-
Configuration
public Configuration()Creates a new empty configuration. -
Configuration
Creates a new configuration with the copy of the given configuration.- Parameters:
other- The configuration to copy the entries from.
-
-
Method Details
-
fromMap
Creates a new configuration that is initialized with the options of the given map. -
getClass
public <T> Class<T> getClass(String key, Class<? extends T> defaultValue, ClassLoader classLoader) throws ClassNotFoundException Returns the class associated with the given key as a string.- Type Parameters:
T- The type of the class to return.- Parameters:
key- The key pointing to the associated valuedefaultValue- The optional default value returned if no entry existsclassLoader- The class loader used to resolve the class.- Returns:
- The value associated with the given key, or the default value, if to entry for the key exists.
- Throws:
ClassNotFoundException
-
setClass
Adds the given key/value pair to the configuration object. The class can be retrieved by invokinggetClass(String, Class, ClassLoader)if it is in the scope of the class loader on the caller.- Parameters:
key- The key of the pair to be addedklazz- The value of the pair to be added- See Also:
-
getString
Returns the value associated with the given config option as a string.- Parameters:
configOption- The configuration option- Returns:
- the (default) value associated with the given config option
-
getString
Returns the value associated with the given config option as a string. If no value is mapped under any key of the option, it returns the specified default instead of the option's default value.- Parameters:
configOption- The configuration option- Returns:
- the (default) value associated with the given config option
-
setString
Adds the given key/value pair to the configuration object.- Parameters:
key- the key of the key/value pair to be addedvalue- the value of the key/value pair to be added
-
setString
Adds the given value to the configuration object. The main key of the config option will be used to map the value.- Parameters:
key- the option specifying the key to be addedvalue- the value of the key/value pair to be added
-
getInteger
Returns the value associated with the given config option as an integer.- Parameters:
configOption- The configuration option- Returns:
- the (default) value associated with the given config option
-
getInteger
Returns the value associated with the given config option as an integer. If no value is mapped under any key of the option, it returns the specified default instead of the option's default value.- Parameters:
configOption- The configuration optionoverrideDefault- The value to return if no value was mapper for any key of the option- Returns:
- the configured value associated with the given config option, or the overrideDefault
-
setInteger
Adds the given key/value pair to the configuration object.- Parameters:
key- the key of the key/value pair to be addedvalue- the value of the key/value pair to be added
-
setInteger
Adds the given value to the configuration object. The main key of the config option will be used to map the value.- Parameters:
key- the option specifying the key to be addedvalue- the value of the key/value pair to be added
-
getLong
Returns the value associated with the given config option as a long integer.- Parameters:
configOption- The configuration option- Returns:
- the (default) value associated with the given config option
-
getLong
Returns the value associated with the given config option as a long integer. If no value is mapped under any key of the option, it returns the specified default instead of the option's default value.- Parameters:
configOption- The configuration optionoverrideDefault- The value to return if no value was mapper for any key of the option- Returns:
- the configured value associated with the given config option, or the overrideDefault
-
setLong
Adds the given key/value pair to the configuration object.- Parameters:
key- the key of the key/value pair to be addedvalue- the value of the key/value pair to be added
-
setLong
Adds the given value to the configuration object. The main key of the config option will be used to map the value.- Parameters:
key- the option specifying the key to be addedvalue- the value of the key/value pair to be added
-
getBoolean
Returns the value associated with the given config option as a boolean.- Parameters:
configOption- The configuration option- Returns:
- the (default) value associated with the given config option
-
getBoolean
Returns the value associated with the given config option as a boolean. If no value is mapped under any key of the option, it returns the specified default instead of the option's default value.- Parameters:
configOption- The configuration optionoverrideDefault- The value to return if no value was mapper for any key of the option- Returns:
- the configured value associated with the given config option, or the overrideDefault
-
setBoolean
Adds the given key/value pair to the configuration object.- Parameters:
key- the key of the key/value pair to be addedvalue- the value of the key/value pair to be added
-
setBoolean
Adds the given value to the configuration object. The main key of the config option will be used to map the value.- Parameters:
key- the option specifying the key to be addedvalue- the value of the key/value pair to be added
-
getFloat
Returns the value associated with the given config option as a float.- Parameters:
configOption- The configuration option- Returns:
- the (default) value associated with the given config option
-
getFloat
Returns the value associated with the given config option as a float. If no value is mapped under any key of the option, it returns the specified default instead of the option's default value.- Parameters:
configOption- The configuration optionoverrideDefault- The value to return if no value was mapper for any key of the option- Returns:
- the configured value associated with the given config option, or the overrideDefault
-
setFloat
Adds the given key/value pair to the configuration object.- Parameters:
key- the key of the key/value pair to be addedvalue- the value of the key/value pair to be added
-
setFloat
Adds the given value to the configuration object. The main key of the config option will be used to map the value.- Parameters:
key- the option specifying the key to be addedvalue- the value of the key/value pair to be added
-
getDouble
Returns the value associated with the given config option as adouble.- Parameters:
configOption- The configuration option- Returns:
- the (default) value associated with the given config option
-
getDouble
Returns the value associated with the given config option as adouble. If no value is mapped under any key of the option, it returns the specified default instead of the option's default value.- Parameters:
configOption- The configuration optionoverrideDefault- The value to return if no value was mapper for any key of the option- Returns:
- the configured value associated with the given config option, or the overrideDefault
-
setDouble
Adds the given key/value pair to the configuration object.- Parameters:
key- the key of the key/value pair to be addedvalue- the value of the key/value pair to be added
-
setDouble
Adds the given value to the configuration object. The main key of the config option will be used to map the value.- Parameters:
key- the option specifying the key to be addedvalue- the value of the key/value pair to be added
-
getBytes
Returns the value associated with the given key as a byte array.- Parameters:
key- The key pointing to the associated value.defaultValue- The default value which is returned in case there is no value associated with the given key.- Returns:
- the (default) value associated with the given key.
-
setBytes
Adds the given byte array to the configuration object. If key isnullthen nothing is added.- Parameters:
key- The key under which the bytes are added.bytes- The bytes to be added.
-
getValue
Returns the value associated with the given config option as a string.- Parameters:
configOption- The configuration option- Returns:
- the (default) value associated with the given config option
-
getEnum
Returns the value associated with the given config option as an enum.- Parameters:
enumClass- The return enum classconfigOption- The configuration option- Throws:
IllegalArgumentException- If the string associated with the given config option cannot be parsed as a value of the provided enum class.
-
keySet
Returns the keys of all key/value pairs stored inside this configuration object.- Returns:
- the keys of all key/value pairs stored inside this configuration object
-
addAllToProperties
Adds all entries in thisConfigurationto the givenProperties. -
addAll
-
addAll
Adds all entries from the given configuration into this configuration. The keys are prepended with the given prefix.- Parameters:
other- The configuration whose entries are added to this configuration.prefix- The prefix to prepend.
-
containsKey
Checks whether there is an entry with the specified key.- Parameters:
key- key of entry- Returns:
- true if the key is stored, false otherwise
-
contains
Checks whether there is an entry for the given config option.- Parameters:
configOption- The configuration option- Returns:
- true if a valid (current or deprecated) key of the config option is stored, false otherwise
-
get
Please check the java doc ofgetRawValueFromOption(ConfigOption). If no keys are found inConfiguration, default value of the given option will return. Please make sure there will be at least one value available. Otherwise, a NPE will be thrown when the value is used.NOTE: current logic is not able to get the default value of the fallback key's ConfigOption, in case the given ConfigOption has no default value. If you want to use fallback key, please make sure its value could be found in
Configurationat runtime.- Specified by:
getin interfaceReadableConfig- Type Parameters:
T- type of the value to read- Parameters:
option- metadata of the option to read- Returns:
- the value of the given option
- See Also:
-
getOptional
Description copied from interface:ReadableConfigReads a value using the metadata included inConfigOption. In contrast toReadableConfig.get(ConfigOption)returnsOptional.empty()if value not present.- Specified by:
getOptionalin interfaceReadableConfig- Type Parameters:
T- type of the value to read- Parameters:
option- metadata of the option to read- Returns:
- read value or
Optional.empty()if not found - See Also:
-
set
Description copied from interface:WritableConfigStores a given value using the metadata included in theConfigOption. The value should be readable back throughReadableConfig.- Specified by:
setin interfaceWritableConfig- Type Parameters:
T- type of the value to be stored- Parameters:
option- metadata informationvalue- value to be stored- Returns:
- instance of this configuration for fluent API
-
toMap
Description copied from interface:ReadableConfigConverts the configuration items into a map of string key-value pairs.- Specified by:
toMapin interfaceReadableConfig- Returns:
- a map containing the configuration properties, where the keys are strings and the values are the corresponding configuration values in string format.
-
toConfMap
-
removeConfig
Removes given config option from the configuration.- Type Parameters:
T- Type of the config option- Parameters:
configOption- config option to remove- Returns:
- true is config has been removed, false otherwise
-
removeKey
Removes given key from the configuration.- Parameters:
key- key of a config option to remove- Returns:
- true is config has been removed, false otherwise
-