Class BaseConfiguration<T>
- java.lang.Object
-
- io.confound.config.AbstractConfiguration
-
- io.confound.config.BaseConfiguration<T>
-
- Type Parameters:
T
- The type of values used in the underlying storage.
- All Implemented Interfaces:
Configuration
,Parameters
- Direct Known Subclasses:
AbstractObjectConfiguration
,AbstractStringConfiguration
public abstract class BaseConfiguration<T> extends AbstractConfiguration
Abstract configuration implementation providing common base functionality.Concrete implementations must override
findParameterImpl(String)
, and may also overridehasParameterImpl(String)
for added efficiency.This class provides a facility
normalizeKey(String)
for modifying the requested key if necessary before ultimate retrieval viafindParameterImpl(String)
. Most implementations will not need this facility, and will use the default implementation which uses the requested key unmodified. In any case, the implementation must use the original key, not the normalized key, when delegating to the parent configuration, if any.- Author:
- Garret Wilson
-
-
Constructor Summary
Constructors Constructor Description BaseConfiguration(Configuration parentConfiguration)
Parent configuration constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.util.Optional<T>
findParameter(java.lang.String key)
Tries to retrieves a general parameter from the underlying storage.protected abstract java.util.Optional<T>
findParameterImpl(java.lang.String key)
Implementation to retrieves a general parameter that may not be present from the underlying storage.<P> java.util.Optional<P>
getOptionalParameter(java.lang.String key)
Retrieves a general parameter that may not be present.boolean
hasParameter(java.lang.String key)
Determines whether a parameter of some type exists for the given parameter key.protected boolean
hasParameterImpl(java.lang.String key)
Determines whether a parameter is present in the underlying storage.protected java.lang.String
normalizeKey(java.lang.String key)
Normalizes a requested key if required by this implementation.-
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, getOptionalBoolean, getOptionalDouble, getOptionalInt, getOptionalLong, getOptionalPath, getOptionalString, getOptionalUri, getParameter, getPath, getString, getUri, requireParameter, resolvePath
-
-
-
-
Constructor Detail
-
BaseConfiguration
public BaseConfiguration(@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
-
normalizeKey
protected java.lang.String normalizeKey(@Nonnull java.lang.String key)
Normalizes a requested key if required by this implementation.The default implementation returns the key unmodified after checking for
null
.- Parameters:
key
- The parameter key.- Returns:
- The requested parameter key, modified as needed for lookup in this implementation.
-
hasParameter
public boolean hasParameter(@Nonnull java.lang.String key) throws ConfigurationException
Determines whether a parameter of some type exists for the given parameter key.This implementation normalizes the key and delegates to
hasParameterImpl(String)
. Most subclasses should not override this method, and instead overridehasParameterImpl(String)
.- Parameters:
key
- The parameter key.- Returns:
true
if a parameter of type type could be retrieved from these parameters using the given key.- Throws:
java.lang.NullPointerException
- if the given key isnull
.java.lang.SecurityException
- If a security manager exists and it doesn't allow access to the specified parameter.ConfigurationException
- if there is a parameter value stored in an invalid format.
-
hasParameterImpl
protected boolean hasParameterImpl(@Nonnull java.lang.String key) throws ConfigurationException
Determines whether a parameter is present in the underlying storage.The given parameter key is assumed to already be normalized, and should not be modified.
This method must not fall back to parent configuration; only local values must be returned.
The default implementation delegates to
findParameterImpl(String)
.- Parameters:
key
- The normalized parameter key.- Returns:
true
if a parameter of type type could be retrieved from these parameters using the given key.- Throws:
java.lang.NullPointerException
- if the given key isnull
.java.lang.SecurityException
- If a security manager exists and it doesn't allow access to the specified parameter.ConfigurationException
- if there is a parameter value stored in an invalid format.
-
getOptionalParameter
public <P> java.util.Optional<P> getOptionalParameter(java.lang.String key) throws ConfigurationException
Retrieves a general parameter that may not be present.This implementation delegates to
findParameter(String)
.- Type Parameters:
P
- The type of parameter expected.- 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.
-
findParameter
protected java.util.Optional<T> findParameter(@Nonnull java.lang.String key) throws ConfigurationException
Tries to retrieves a general parameter from the underlying storage. The key need not be normalized; it will be normalized as necessary.This method must not fall back to parent configuration; only local strings must be returned.
This is an internal API call that should be used by child classes to funnel requests to the underlying storage. Normally child classes will not override this method, but override
findParameterImpl(String)
instead.- Parameters:
key
- The parameter key, which may not be normalized.- Returns:
- The optional value of the parameter associated with the given key.
- Throws:
java.lang.NullPointerException
- if the given key isnull
.java.lang.SecurityException
- If a security manager exists and it doesn't allow access to the specified parameter.ConfigurationException
- if there is a parameter value stored in an invalid format.- See Also:
normalizeKey(String)
-
findParameterImpl
protected abstract java.util.Optional<T> findParameterImpl(@Nonnull java.lang.String key) throws ConfigurationException
Implementation to retrieves a general parameter that may not be present from the underlying storage.The given parameter key is assumed to already be normalized, and should not be modified.
This method must not fall back to parent configuration; only local values must be returned.
- Parameters:
key
- The normalized parameter key.- Returns:
- The optional value of the parameter associated with the given key.
- Throws:
java.lang.NullPointerException
- if the given key isnull
.java.lang.SecurityException
- If a security manager exists and it doesn't allow access to the specified parameter.ConfigurationException
- if there is a parameter value stored in an invalid format.
-
-