Class AbstractStringConfiguration

All Implemented Interfaces:
Configuration
Direct Known Subclasses:
StringMapConfiguration

public abstract class AbstractStringConfiguration extends BaseConfiguration<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 via BaseConfiguration.findConfigurationValueImpl(String), and afterwards dereferenced using dereferenceString(String).

Author:
Garret Wilson
  • Constructor Details

    • AbstractStringConfiguration

      public AbstractStringConfiguration()
  • Method Details

    • findObject

      public <O> Optional<O> findObject(String key, 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, a ConfigurationException will be thrown.
      Specified by:
      findObject in interface Configuration
      Overrides:
      findObject in class BaseConfiguration<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 String dereferenceString(@Nonnull 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:
      NullPointerException - if the given string is null.
      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 class BaseConfiguration<String>
      Implementation Specification:
      This implementation normalizes the key, delegates to BaseConfiguration.findConfigurationValueImpl(String), and then dereferences the string using dereferenceString(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

      public Optional<Boolean> findBoolean(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 OptionalDouble findDouble(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 OptionalInt findInt(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 OptionalLong findLong(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 Optional<Path> findPath(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 using Configuration.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 Optional<String> findString(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:
    • findUri

      public Optional<URI> findUri(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.