Package io.confound.config
Class AbstractConfigurationDecorator
- java.lang.Object
-
- io.confound.config.AbstractConfiguration
-
- io.confound.config.AbstractConfigurationDecorator
-
- All Implemented Interfaces:
Configuration
- Direct Known Subclasses:
SubConfiguration
,SuperConfiguration
public abstract class AbstractConfigurationDecorator extends AbstractConfiguration
Abstract wrapper configuration that forwards calls to the decorated configuration.- Author:
- Garret Wilson
-
-
Field Summary
-
Fields inherited from interface io.confound.config.Configuration
KEY_SEGMENT_SEPARATOR
-
-
Constructor Summary
Constructors Constructor Description AbstractConfigurationDecorator(Configuration configuration)
Wrapped configuration constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.Optional<java.lang.String>
decorateKey(java.lang.String key)
Transforms the key appropriately before it is passed to the decorated configuration.java.util.Optional<java.lang.Boolean>
findBoolean(java.lang.String key)
Retrieves a Boolean configuration value that may not be present.java.util.OptionalDouble
findDouble(java.lang.String key)
Retrieves a floating point configuration value that may not be present.java.util.OptionalInt
findInt(java.lang.String key)
Retrieves an integer configuration value that may not be present.java.util.OptionalLong
findLong(java.lang.String key)
Retrieves a long integer configuration value that may not be present.java.util.Optional<java.lang.Object>
findObject(java.lang.String key)
Retrieves a general configuration object that may not be present.<O> java.util.Optional<O>
findObject(java.lang.String key, java.lang.Class<O> type)
Retrieves a general configuration object that may not be present as the requested type, converting it as necessary.java.util.Optional<java.nio.file.Path>
findPath(java.lang.String key)
Retrieves a path configuration value that may not be present.java.util.Optional<java.lang.String>
findString(java.lang.String key)
Retrieves a string configuration value that may not be present.java.util.Optional<java.net.URI>
findUri(java.lang.String key)
Retrieves a URI configuration value that may not be present.boolean
getBoolean(java.lang.String key)
Retrieves a Boolean configuration value.protected Configuration
getConfiguration()
Returns the wrapped configuration.double
getDouble(java.lang.String key)
Retrieves a floating point configuration value.int
getInt(java.lang.String key)
Retrieves an integer configuration value.long
getLong(java.lang.String key)
Retrieves a long integer configuration value.java.lang.Object
getObject(java.lang.String key)
Retrieves a general configuration object.<O> O
getObject(java.lang.String key, java.lang.Class<O> type)
Retrieves a general configuration object as the requested type, converting it as necessary.java.nio.file.Path
getPath(java.lang.String key)
Retrieves a path configuration value.java.lang.String
getString(java.lang.String key)
Retrieves a string configuration value.java.net.URI
getUri(java.lang.String key)
Retrieves a URI configuration value.boolean
hasConfigurationValue(java.lang.String key)
Determines whether a configuration of some type exists for the given configuration key.-
Methods inherited from class io.confound.config.AbstractConfiguration
or
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.confound.config.Configuration
createMissingConfigurationKeyException, requireConfiguration, resolvePath, subConfiguration, superConfiguration, withFallback
-
-
-
-
Constructor Detail
-
AbstractConfigurationDecorator
public AbstractConfigurationDecorator(@Nonnull Configuration configuration)
Wrapped configuration constructor.- Parameters:
configuration
- The configuration to decorate.- Throws:
java.lang.NullPointerException
- if the given configuration isnull
.
-
-
Method Detail
-
getConfiguration
protected Configuration getConfiguration()
Returns the wrapped configuration.- Returns:
- The decorated configuration delegate instance.
-
decorateKey
protected java.util.Optional<java.lang.String> decorateKey(@Nonnull java.lang.String key)
Transforms the key appropriately before it is passed to the decorated configuration. The key may be given some prefix or have some prefix removed, for example, or the case of the key may be changed.If no key is returned, it indicates that the given key does not represent a key in this configuration view. For example, if the decorator represents a subset of the decorator configuration only for those keys starting with
foo.
, this method would return an empty configuration if a key did not being withfoo.
.- API Note:
- This method is useful for implementing subsets and supersets.
- Implementation Specification:
- The default implementation merely returns the key unchanged.
- Parameters:
key
- The key as provided by the caller.- Returns:
- The key transformed appropriately to be passed to the wrapped configuration.
-
hasConfigurationValue
public boolean hasConfigurationValue(java.lang.String key) throws ConfigurationException
Description copied from interface:Configuration
Determines whether a configuration of some type exists for the given configuration key.- Parameters:
key
- The configuration key.- Returns:
true
if a value of any type could be retrieved from this configuration using the given key.- Throws:
ConfigurationException
- if there is a configuration value stored in an invalid format.
-
getObject
public java.lang.Object getObject(java.lang.String key) throws MissingConfigurationKeyException, ConfigurationException
Description copied from interface:Configuration
Retrieves a general configuration object.- Parameters:
key
- The configuration key.- Returns:
- The configuration value associated with the given key.
- Throws:
MissingConfigurationKeyException
- if no configuration is associated with the given key.ConfigurationException
- if there is a configuration value stored in an invalid format.
-
findObject
public java.util.Optional<java.lang.Object> findObject(java.lang.String key) throws ConfigurationException
Description copied from interface:Configuration
Retrieves a general configuration object that may not be present.- Parameters:
key
- The configuration key.- Returns:
- The optional configuration value associated with the given key.
- Throws:
ConfigurationException
- if there is a configuration value stored in an invalid format.
-
getObject
public <O> O getObject(java.lang.String key, java.lang.Class<O> type) throws MissingConfigurationKeyException, ConfigurationException
Description copied from interface:Configuration
Retrieves a general configuration object as the requested type, converting it as necessary. If the object is present but cannot be converted, aConfigurationException
will be thrown.- Type Parameters:
O
- The type of configuration object expected.- Parameters:
key
- The configuration key.type
- The type of object requested.- Returns:
- The configuration value associated with the given key.
- Throws:
MissingConfigurationKeyException
- if no configuration is associated with the given key.ConfigurationException
- if there is a configuration value stored in an invalid format.
-
findObject
public <O> java.util.Optional<O> findObject(java.lang.String key, java.lang.Class<O> type) throws ConfigurationException
Description copied from interface:Configuration
Retrieves a general configuration object that may not be present as the requested type, converting it as necessary. If the object is present but cannot be converted, aConfigurationException
will be thrown.- Type Parameters:
O
- The type of configuration object expected.- Parameters:
key
- The configuration key.type
- The type of object requested.- Returns:
- The optional configuration value associated with the given key.
- Throws:
ConfigurationException
- if there is a configuration value stored in an invalid format.
-
getBoolean
public boolean getBoolean(java.lang.String key) throws MissingConfigurationKeyException, ConfigurationException
Description copied from interface:Configuration
Retrieves a Boolean configuration value.- Parameters:
key
- The configuration key.- Returns:
- The configuration value associated with the given key.
- Throws:
MissingConfigurationKeyException
- if no configuration is associated with the given key.ConfigurationException
- if there is a configuration value stored in an invalid format.
-
findBoolean
public java.util.Optional<java.lang.Boolean> findBoolean(java.lang.String key) throws ConfigurationException
Description copied from interface:Configuration
Retrieves a Boolean configuration value that may not be present.- Parameters:
key
- The configuration key.- Returns:
- The optional configuration value associated with the given key.
- Throws:
ConfigurationException
- if there is a configuration value stored in an invalid format.
-
getDouble
public double getDouble(java.lang.String key) throws MissingConfigurationKeyException, ConfigurationException
Description copied from interface:Configuration
Retrieves a floating point configuration value.- Parameters:
key
- The configuration key.- Returns:
- The configuration value associated with the given key.
- Throws:
MissingConfigurationKeyException
- if no configuration is associated with the given key.ConfigurationException
- if there is a configuration value stored in an invalid format.
-
findDouble
public java.util.OptionalDouble findDouble(java.lang.String key) throws ConfigurationException
Description copied from interface:Configuration
Retrieves a floating point configuration value that may not be present.- Parameters:
key
- The configuration key.- Returns:
- The optional configuration value associated with the given key.
- Throws:
ConfigurationException
- if there is a configuration value stored in an invalid format.
-
getInt
public int getInt(java.lang.String key) throws MissingConfigurationKeyException, ConfigurationException
Description copied from interface:Configuration
Retrieves an integer configuration value.- Parameters:
key
- The configuration key.- Returns:
- The configuration value associated with the given key.
- Throws:
MissingConfigurationKeyException
- if no configuration is associated with the given key.ConfigurationException
- if there is a configuration value stored in an invalid format.
-
findInt
public java.util.OptionalInt findInt(java.lang.String key) throws ConfigurationException
Description copied from interface:Configuration
Retrieves an integer configuration value that may not be present.- Parameters:
key
- The configuration key.- Returns:
- The optional configuration value associated with the given key.
- Throws:
ConfigurationException
- if there is a configuration value stored in an invalid format.
-
getLong
public long getLong(java.lang.String key) throws MissingConfigurationKeyException, ConfigurationException
Description copied from interface:Configuration
Retrieves a long integer configuration value.- Parameters:
key
- The configuration key.- Returns:
- The configuration value associated with the given key.
- Throws:
MissingConfigurationKeyException
- if no configuration is associated with the given key.ConfigurationException
- if there is a configuration value stored in an invalid format.
-
findLong
public java.util.OptionalLong findLong(java.lang.String key) throws ConfigurationException
Description copied from interface:Configuration
Retrieves a long integer configuration value that may not be present.- Parameters:
key
- The configuration key.- Returns:
- The optional configuration value associated with the given key.
- Throws:
ConfigurationException
- if there is a configuration value stored in an invalid format.
-
getPath
public java.nio.file.Path getPath(java.lang.String key) throws MissingConfigurationKeyException, ConfigurationException
Description copied from interface:Configuration
Retrieves a path configuration value.The path will be resolved using
Configuration.resolvePath(Path)
.- Parameters:
key
- The configuration key.- Returns:
- The configuration value associated with the given key.
- Throws:
MissingConfigurationKeyException
- if no configuration is associated with the given key.ConfigurationException
- if there is a configuration value stored in an invalid format.
-
findPath
public java.util.Optional<java.nio.file.Path> findPath(java.lang.String key) throws ConfigurationException
Description copied from interface:Configuration
Retrieves a path configuration value that may not be present.The path will be resolved using
Configuration.resolvePath(Path)
.- Parameters:
key
- The configuration key.- Returns:
- The optional configuration value associated with the given key.
- Throws:
ConfigurationException
- if there is a configuration value stored in an invalid format.
-
getString
public java.lang.String getString(java.lang.String key) throws MissingConfigurationKeyException, ConfigurationException
Description copied from interface:Configuration
Retrieves a string configuration value.TODO discuss dereferencing
- Parameters:
key
- The configuration key.- Returns:
- The configuration value associated with the given key.
- Throws:
MissingConfigurationKeyException
- if no configuration is associated with the given key.ConfigurationException
- if there is a configuration value stored in an invalid format.- See Also:
Format.format(Object)
-
findString
public java.util.Optional<java.lang.String> findString(java.lang.String key) throws ConfigurationException
Description copied from interface:Configuration
Retrieves a string configuration value that may not be present.TODO discuss dereferencing
- Parameters:
key
- The configuration key.- Returns:
- The optional configuration value associated with the given key.
- Throws:
ConfigurationException
- if there is a configuration value stored in an invalid format.- See Also:
Format.format(Object)
-
getUri
public java.net.URI getUri(java.lang.String key) throws MissingConfigurationKeyException, ConfigurationException
Description copied from interface:Configuration
Retrieves a URI configuration value.- Parameters:
key
- The configuration key.- Returns:
- The configuration value associated with the given key.
- Throws:
MissingConfigurationKeyException
- if no configuration is associated with the given key.ConfigurationException
- if there is a configuration value stored in an invalid format.
-
findUri
public java.util.Optional<java.net.URI> findUri(java.lang.String key) throws ConfigurationException
Description copied from interface:Configuration
Retrieves a URI configuration value that may not be present.- Parameters:
key
- The configuration key.- Returns:
- The optional configuration value associated with the given key.
- Throws:
ConfigurationException
- if there is a configuration value stored in an invalid format.
-
-