Package io.confound.config
Class AbstractStringConfiguration
- java.lang.Object
-
- io.confound.config.AbstractConfiguration
-
- io.confound.config.BaseConfiguration<java.lang.String>
-
- io.confound.config.AbstractStringConfiguration
-
- All Implemented Interfaces:
Configuration
- Direct Known Subclasses:
StringMapConfiguration
public abstract class AbstractStringConfiguration extends BaseConfiguration<java.lang.String>
Abstract configuration implementation for which the underlying storage is based solely on strings.An implementing subclass must override
BaseConfiguration.findConfigurationValueImpl(String)
for local raw string retrieval. This class retrieves all values as stored in string format accessed viaBaseConfiguration.findConfigurationValueImpl(String)
, and afterwards dereferenced usingdereferenceString(String)
.- Author:
- Garret Wilson
-
-
Field Summary
-
Fields inherited from interface io.confound.config.Configuration
KEY_SEGMENT_SEPARATOR
-
-
Constructor Summary
Constructors Constructor Description AbstractStringConfiguration()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.String
dereferenceString(java.lang.String string)
Evaluates and replaces any references in the given string.java.util.Optional<java.lang.Boolean>
findBoolean(java.lang.String key)
Retrieves a Boolean configuration value that may not be present.protected java.util.Optional<java.lang.String>
findConfigurationValue(java.lang.String key)
Tries to retrieves a general configuration value from the underlying storage.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.<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.-
Methods inherited from class io.confound.config.BaseConfiguration
convertValue, findConfigurationValueImpl, 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
-
findObject
public <O> java.util.Optional<O> findObject(java.lang.String key, java.lang.Class<O> type) throws ConfigurationException
Description copied from class:BaseConfiguration
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.- Specified by:
findObject
in interfaceConfiguration
- Overrides:
findObject
in classBaseConfiguration<java.lang.String>
- 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.
-
dereferenceString
@Nonnull protected java.lang.String dereferenceString(@Nonnull java.lang.String string)
Evaluates and replaces any references in the given string.This method does not need to be called if the underlying configuration implementation already supports expression replacement.
- Parameters:
string
- The string for which expressions should be evaluated.- Returns:
- A string with expressions evaluated, which may be the original string.
- Throws:
java.lang.NullPointerException
- if the given string isnull
.ConfigurationException
- if an expression is not in the correct format, or if no value is associated with a key in an expression.
-
findConfigurationValue
protected java.util.Optional<java.lang.String> findConfigurationValue(@Nonnull java.lang.String key) throws ConfigurationException
Tries to retrieves a general configuration value 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 values must be returned.
- Overrides:
findConfigurationValue
in classBaseConfiguration<java.lang.String>
- Implementation Specification:
- This implementation normalizes the key, delegates to
BaseConfiguration.findConfigurationValueImpl(String)
, and then dereferences the string usingdereferenceString(String)
. - Parameters:
key
- The configuration key, which may not be normalized.- 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:
dereferenceString(String)
-
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 parses the value using
Boolean.valueOf(String)
. - 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 parses the value using
Double.parseDouble(String)
. - 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 parses the value using
Integer.parseInt(String)
. - 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 parses the value using
Long.parseLong(String)
. - 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 parses the value using
URI.create(String)
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 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 delegates to
findConfigurationValue(String)
. - 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 parses the value using
URI.create(String)
. - 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.
-
-