Package io.confound.config
Class AbstractStringConfiguration
- All Implemented Interfaces:
Configuration
- Direct Known Subclasses:
StringMapConfiguration
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 via BaseConfiguration.findConfigurationValueImpl(String)
, and afterwards dereferenced using dereferenceString(String)
.
- Author:
- Garret Wilson
-
Field Summary
Fields inherited from interface io.confound.config.Configuration
KEY_SEGMENT_SEPARATOR, KEY_SEGMENTS_PATTERN
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected String
dereferenceString
(String string) Evaluates and replaces any references in the given string.findBoolean
(String key) Retrieves a Boolean configuration value that may not be present.Tries to retrieves a general configuration value from the underlying storage.findDouble
(String key) Retrieves a floating point configuration value that may not be present.Retrieves an integer configuration value that may not be present.Retrieves a long integer configuration value that may not be present.<O> Optional<O>
findObject
(String key, Class<O> type) Retrieves a general configuration object that may not be present as the requested type, converting it as necessary.Retrieves a path configuration value that may not be present.findString
(String key) Retrieves a string configuration value that may not be present.Retrieves a URI configuration value that may not be present.Methods inherited from class io.confound.config.BaseConfiguration
convertValue, findCollection, 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, findCollection, findObject, findSection, getBoolean, getCollection, getCollection, getDouble, getInt, getLong, getObject, getObject, getPath, getSection, getString, getUri, requireConfiguration, resolvePath, subConfiguration, superConfiguration, withFallback
-
Constructor Details
-
AbstractStringConfiguration
public AbstractStringConfiguration()
-
-
Method Details
-
findObject
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<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
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:
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 Optional<String> findConfigurationValue(@Nonnull 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<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:
-
findBoolean
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
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
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
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
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
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:
-
findUri
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.
-