Class AbstractObjectConfiguration
- java.lang.Object
-
- io.confound.config.AbstractConfiguration
-
- io.confound.config.BaseConfiguration<java.lang.Object>
-
- io.confound.config.AbstractObjectConfiguration
-
- All Implemented Interfaces:
Configuration
,Parameters
- 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.In the current implementation, this class throws a
ConfigurationException
if the requested object is not of the requested type. A future version will allow values to be converted between compatible types.- Author:
- Garret Wilson
-
-
Constructor Summary
Constructors Constructor Description AbstractObjectConfiguration(Configuration parentConfiguration)
Parent configuration constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <C> java.util.Optional<C>
convertParameter(java.util.Optional<java.lang.Object> parameter, java.lang.Class<C> convertClass)
Converts a parameter from its actual type in the underlying storage to the requested type.java.util.Optional<java.lang.Boolean>
getOptionalBoolean(java.lang.String key)
Retrieves a Boolean parameter that may not be present.java.util.Optional<java.lang.Double>
getOptionalDouble(java.lang.String key)
Retrieves a floating point parameter that may not be present.java.util.Optional<java.lang.Integer>
getOptionalInt(java.lang.String key)
Retrieves an integer parameter that may not be present.java.util.Optional<java.lang.Long>
getOptionalLong(java.lang.String key)
Retrieves a long integer parameter that may not be present.java.util.Optional<java.nio.file.Path>
getOptionalPath(java.lang.String key)
Retrieves a path parameter that may not be present.java.util.Optional<java.lang.String>
getOptionalString(java.lang.String key)
Retrieves a string parameter that may not be present.java.util.Optional<java.net.URI>
getOptionalUri(java.lang.String key)
Retrieves a URI parameter that may not be present.-
Methods inherited from class io.confound.config.BaseConfiguration
findParameter, findParameterImpl, getOptionalParameter, hasParameter, hasParameterImpl, normalizeKey
-
Methods inherited from class io.confound.config.AbstractConfiguration
getParentConfiguration, 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.Parameters
getBoolean, getDouble, getInt, getLong, getParameter, getPath, getString, getUri, requireParameter, resolvePath
-
-
-
-
Constructor Detail
-
AbstractObjectConfiguration
public AbstractObjectConfiguration(@Nullable Configuration parentConfiguration)
Parent configuration constructor.- Parameters:
parentConfiguration
- The parent configuration to use for fallback lookup, ornull
if there is no parent configuration.
-
-
Method Detail
-
convertParameter
protected <C> java.util.Optional<C> convertParameter(@Nonnull java.util.Optional<java.lang.Object> parameter, @Nonnull java.lang.Class<C> convertClass) throws ConfigurationException
Converts a parameter from its actual type in the underlying storage to the requested type.The current implementation merely checked to see if the parameter can be cast to the requested type; otherwise, an exception is thrown.
- Type Parameters:
C
- The requested conversion type.- Parameters:
parameter
- The parameter to convert.convertClass
- The class indicating the requested conversion type.- Returns:
- The parameter converted to the requested type.
- Throws:
ConfigurationException
- if the parameter is present and cannot be converted to the requested type.
-
getOptionalBoolean
public java.util.Optional<java.lang.Boolean> getOptionalBoolean(java.lang.String key) throws ConfigurationException
Retrieves a Boolean parameter that may not be present.This implementation converts the value using
convertParameter(Optional, Class)
.- Parameters:
key
- The parameter key.- Returns:
- The optional value of the parameter associated with the given key.
- Throws:
ConfigurationException
- if there is a parameter value stored in an invalid format.
-
getOptionalDouble
public java.util.Optional<java.lang.Double> getOptionalDouble(java.lang.String key) throws ConfigurationException
Retrieves a floating point parameter that may not be present.This implementation converts the value using
convertParameter(Optional, Class)
.- Parameters:
key
- The parameter key.- Returns:
- The optional value of the parameter associated with the given key.
- Throws:
ConfigurationException
- if there is a parameter value stored in an invalid format.
-
getOptionalInt
public java.util.Optional<java.lang.Integer> getOptionalInt(java.lang.String key) throws ConfigurationException
Retrieves an integer parameter that may not be present.This implementation converts the value using
convertParameter(Optional, Class)
.- Parameters:
key
- The parameter key.- Returns:
- The optional value of the parameter associated with the given key.
- Throws:
ConfigurationException
- if there is a parameter value stored in an invalid format.
-
getOptionalLong
public java.util.Optional<java.lang.Long> getOptionalLong(java.lang.String key) throws ConfigurationException
Retrieves a long integer parameter that may not be present.The default implementation delegates to
Parameters.getOptionalInt(String)
.This implementation converts the value using
convertParameter(Optional, Class)
.- Parameters:
key
- The parameter key.- Returns:
- The optional value of the parameter associated with the given key.
- Throws:
ConfigurationException
- if there is a parameter value stored in an invalid format.
-
getOptionalPath
public java.util.Optional<java.nio.file.Path> getOptionalPath(java.lang.String key) throws ConfigurationException
Retrieves a path parameter that may not be present.The path will be resolved using
Parameters.resolvePath(Path)
.This implementation normalizes the key using
BaseConfiguration.normalizeKey(String)
, converts the value usingconvertParameter(Optional, Class)
, and then resolves the path usingParameters.resolvePath(Path)
.- Parameters:
key
- The parameter key.- Returns:
- The optional value of the parameter associated with the given key.
- Throws:
ConfigurationException
- if there is a parameter value stored in an invalid format.
-
getOptionalString
public final java.util.Optional<java.lang.String> getOptionalString(java.lang.String key) throws ConfigurationException
Retrieves a string parameter that may not be present.TODO discuss dereferencing
This implementation converts the value using
convertParameter(Optional, Class)
.- Parameters:
key
- The parameter key.- Returns:
- The optional value of the parameter associated with the given key.
- Throws:
ConfigurationException
- if there is a parameter value stored in an invalid format.- See Also:
Format.format(Object)
-
getOptionalUri
public java.util.Optional<java.net.URI> getOptionalUri(java.lang.String key) throws ConfigurationException
Retrieves a URI parameter that may not be present.This implementation converts the value using
convertParameter(Optional, Class)
.- Parameters:
key
- The parameter key.- Returns:
- The optional value of the parameter associated with the given key.
- Throws:
ConfigurationException
- if there is a parameter value stored in an invalid format.
-
-