Class AbstractConfigurationDecorator

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.util.Optional<java.lang.String> decorateKey​(java.lang.String key)
      Transforms the key appropriately before it is passed to the decorated configuration.
      java.util.Optional<java.lang.Boolean> findBoolean​(java.lang.String key)
      Retrieves a Boolean configuration value that may not be present.
      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.
      java.util.Optional<java.lang.Object> findObject​(java.lang.String key)
      Retrieves a general configuration object 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.
      boolean getBoolean​(java.lang.String key)
      Retrieves a Boolean configuration value.
      protected Configuration getConfiguration()
      Returns the wrapped configuration.
      double getDouble​(java.lang.String key)
      Retrieves a floating point configuration value.
      int getInt​(java.lang.String key)
      Retrieves an integer configuration value.
      long getLong​(java.lang.String key)
      Retrieves a long integer configuration value.
      java.lang.Object getObject​(java.lang.String key)
      Retrieves a general configuration object.
      <O> O getObject​(java.lang.String key, java.lang.Class<O> type)
      Retrieves a general configuration object as the requested type, converting it as necessary.
      java.nio.file.Path getPath​(java.lang.String key)
      Retrieves a path configuration value.
      java.lang.String getString​(java.lang.String key)
      Retrieves a string configuration value.
      java.net.URI getUri​(java.lang.String key)
      Retrieves a URI configuration value.
      boolean hasConfigurationValue​(java.lang.String key)
      Determines whether a configuration of some type exists for the given configuration key.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractConfigurationDecorator

        public AbstractConfigurationDecorator​(@Nonnull
                                              Configuration configuration)
        Wrapped configuration constructor.
        Parameters:
        configuration - The configuration to decorate.
        Throws:
        java.lang.NullPointerException - if the given configuration is null.
    • Method Detail

      • getConfiguration

        protected Configuration getConfiguration()
        Returns the wrapped configuration.
        Returns:
        The decorated configuration delegate instance.
      • decorateKey

        protected java.util.Optional<java.lang.String> decorateKey​(@Nonnull
                                                                   java.lang.String key)
        Transforms the key appropriately before it is passed to the decorated configuration. The key may be given some prefix or have some prefix removed, for example, or the case of the key may be changed.

        If no key is returned, it indicates that the given key does not represent a key in this configuration view. For example, if the decorator represents a subset of the decorator configuration only for those keys starting with foo., this method would return an empty configuration if a key did not being with foo..

        API Note:
        This method is useful for implementing subsets and supersets.
        Implementation Specification:
        The default implementation merely returns the key unchanged.
        Parameters:
        key - The key as provided by the caller.
        Returns:
        The key transformed appropriately to be passed to the wrapped configuration.
      • hasConfigurationValue

        public boolean hasConfigurationValue​(java.lang.String key)
                                      throws ConfigurationException
        Description copied from interface: Configuration
        Determines whether a configuration of some type exists for the given configuration key.
        Parameters:
        key - The configuration key.
        Returns:
        true if a value of any type could be retrieved from this configuration using the given key.
        Throws:
        ConfigurationException - if there is a configuration value stored in an invalid format.
      • findObject

        public java.util.Optional<java.lang.Object> findObject​(java.lang.String key)
                                                        throws ConfigurationException
        Description copied from interface: Configuration
        Retrieves a general configuration object that may not be present.
        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.
      • getObject

        public <O> O getObject​(java.lang.String key,
                               java.lang.Class<O> type)
                        throws MissingConfigurationKeyException,
                               ConfigurationException
        Description copied from interface: Configuration
        Retrieves a general configuration object as the requested type, converting it as necessary. If the object is present but cannot be converted, a ConfigurationException will be thrown.
        Type Parameters:
        O - The type of configuration object expected.
        Parameters:
        key - The configuration key.
        type - The type of object requested.
        Returns:
        The configuration value associated with the given key.
        Throws:
        MissingConfigurationKeyException - if no configuration is associated with the given key.
        ConfigurationException - if there is a configuration value stored in an invalid format.
      • findObject

        public <O> java.util.Optional<O> findObject​(java.lang.String key,
                                                    java.lang.Class<O> type)
                                             throws ConfigurationException
        Description copied from interface: Configuration
        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.
        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.
      • findBoolean

        public java.util.Optional<java.lang.Boolean> findBoolean​(java.lang.String key)
                                                          throws ConfigurationException
        Description copied from interface: Configuration
        Retrieves a Boolean configuration value that may not be present.
        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
        Description copied from interface: Configuration
        Retrieves a floating point configuration value that may not be present.
        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
        Description copied from interface: Configuration
        Retrieves an integer configuration value that may not be present.
        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
        Description copied from interface: Configuration
        Retrieves a long integer configuration value that may not be present.
        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
        Description copied from interface: Configuration
        Retrieves a path configuration value that may not be present.

        The path will be resolved 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 java.util.Optional<java.lang.String> findString​(java.lang.String key)
                                                        throws ConfigurationException
        Description copied from interface: Configuration
        Retrieves a string configuration value that may not be present.

        TODO discuss dereferencing

        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
        Description copied from interface: Configuration
        Retrieves a URI configuration value that may not be present.
        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.