Package io.confound.config
Class AbstractObjectConfiguration
- java.lang.Object
-
- io.confound.config.AbstractConfiguration
-
- io.confound.config.BaseConfiguration<java.lang.Object>
-
- io.confound.config.AbstractObjectConfiguration
-
- All Implemented Interfaces:
Configuration
- Direct Known Subclasses:
ObjectMapConfiguration
public abstract class AbstractObjectConfiguration extends BaseConfiguration<java.lang.Object>
Abstract configuration implementation for which the underlying storage is based on general objects.- Author:
- Garret Wilson
- Implementation Specification:
- The current implementation supports conversion between number types; otherwise this class throws a
ConfigurationException
if the requested object is not of the requested type.
-
-
Field Summary
-
Fields inherited from interface io.confound.config.Configuration
KEY_SEGMENT_SEPARATOR
-
-
Constructor Summary
Constructors Constructor Description AbstractObjectConfiguration()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <O> java.util.Optional<O>
convertValue(java.util.Optional<java.lang.Object> value, java.lang.Class<O> convertClass)
Converts a configuration value from its actual type in the underlying storage to the requested type.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.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.-
Methods inherited from class io.confound.config.BaseConfiguration
findConfigurationValue, findConfigurationValueImpl, findObject, hasConfigurationValue, hasConfigurationValueImpl, normalizeKey
-
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, findObject, getBoolean, getDouble, getInt, getLong, getObject, getObject, getPath, getString, getUri, requireConfiguration, resolvePath, subConfiguration, superConfiguration, withFallback
-
-
-
-
Method Detail
-
convertValue
protected <O> java.util.Optional<O> convertValue(@Nonnull java.util.Optional<java.lang.Object> value, @Nonnull java.lang.Class<O> convertClass) throws ConfigurationException
Converts a configuration value from its actual type in the underlying storage to the requested type.- Overrides:
convertValue
in classBaseConfiguration<java.lang.Object>
- Implementation Specification:
- The current implementation supports conversion between number types; otherwise this implementation merely checked to see if the value can be cast to the requested type.
- Type Parameters:
O
- The requested conversion type.- Parameters:
value
- The value to convert.convertClass
- The class indicating the requested conversion type.- Returns:
- The value converted to the requested type.
- Throws:
ConfigurationException
- if the value is present and cannot be converted to the requested type.
-
findBoolean
public java.util.Optional<java.lang.Boolean> findBoolean(java.lang.String key) throws ConfigurationException
Retrieves a Boolean configuration value that may not be present.- Implementation Specification:
- This implementation converts the value using
convertValue(Optional, Class)
. - 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.
-
findDouble
public java.util.OptionalDouble findDouble(java.lang.String key) throws ConfigurationException
Retrieves a floating point configuration value that may not be present.- Implementation Specification:
- This implementation converts the value using
convertValue(Optional, Class)
. - 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.
-
findInt
public java.util.OptionalInt findInt(java.lang.String key) throws ConfigurationException
Retrieves an integer configuration value that may not be present.- Implementation Specification:
- This implementation converts the value using
convertValue(Optional, Class)
. - 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.
-
findLong
public java.util.OptionalLong findLong(java.lang.String key) throws ConfigurationException
Retrieves a long integer configuration value that may not be present.- Implementation Specification:
- This implementation converts the value using
convertValue(Optional, Class)
. - 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.
-
findPath
public java.util.Optional<java.nio.file.Path> findPath(java.lang.String key) throws ConfigurationException
Retrieves a path configuration value that may not be present.The path will be resolved using
Configuration.resolvePath(Path)
.- Implementation Specification:
- This implementation normalizes the key using
BaseConfiguration.normalizeKey(String)
, converts the value usingconvertValue(Optional, Class)
, and then resolves the path usingConfiguration.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.
-
findString
public final java.util.Optional<java.lang.String> findString(java.lang.String key) throws ConfigurationException
Retrieves a string configuration value that may not be present.TODO discuss dereferencing
- Implementation Specification:
- This implementation converts the value using
convertValue(Optional, Class)
. - 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)
-
findUri
public java.util.Optional<java.net.URI> findUri(java.lang.String key) throws ConfigurationException
Retrieves a URI configuration value that may not be present.- Implementation Specification:
- This implementation converts the value using
convertValue(Optional, Class)
. - 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.
-
-