Class BaseConfiguration<T>

    • Constructor Detail

      • BaseConfiguration

        public BaseConfiguration()
    • Method Detail

      • normalizeKey

        protected java.lang.String normalizeKey​(@Nonnull
                                                java.lang.String key)
        Normalizes a requested key if required by this implementation.
        Implementation Specification:
        The default implementation returns the key unmodified after checking for null.
        Parameters:
        key - The configuration key.
        Returns:
        The requested configuration key, modified as needed for lookup in this implementation.
      • convertValue

        protected <C> java.util.Optional<C> convertValue​(@Nonnull
                                                         java.util.Optional<T> value,
                                                         @Nonnull
                                                         java.lang.Class<C> convertClass)
                                                  throws ConfigurationException
        Converts a configuration value from its actual type in the underlying storage to the requested type.
        Implementation Specification:
        This implementation merely checked to see if the value can be cast to the requested type; otherwise, an exception is thrown.
        Type Parameters:
        C - The requested conversion type.
        Parameters:
        value - The value to convert.
        convertClass - The class indicating the requested conversion type.
        Returns:
        The value converted to the requested type.
        Throws:
        ConfigurationException - if the value is present and cannot be converted to the requested type.
      • hasConfigurationValue

        public boolean hasConfigurationValue​(@Nonnull
                                             java.lang.String key)
                                      throws ConfigurationException
        Determines whether a configuration of some type exists for the given configuration key.
        Implementation Specification:
        This implementation normalizes the key and delegates to hasConfigurationValueImpl(String).
        Implementation Note:
        Most subclasses should not override this method, and instead override hasConfigurationValueImpl(String).
        Parameters:
        key - The configuration key.
        Returns:
        true if a value of any type could be retrieved from this configuration using the given key.
        Throws:
        java.lang.NullPointerException - if the given key is null.
        java.lang.SecurityException - If a security manager exists and it doesn't allow access to the specified configuration.
        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
        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.
        Implementation Specification:
        This implementation converts the value using convertValue(Optional, Class).
        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.
      • hasConfigurationValueImpl

        protected boolean hasConfigurationValueImpl​(@Nonnull
                                                    java.lang.String key)
                                             throws ConfigurationException
        Determines whether a configuration value is present in the underlying storage.

        The given configuration 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.

        Implementation Specification:
        The default implementation delegates to findConfigurationValueImpl(String).
        Parameters:
        key - The normalized configuration key.
        Returns:
        true if a value of any type could be retrieved from this configuration using the given key.
        Throws:
        java.lang.NullPointerException - if the given key is null.
        java.lang.SecurityException - If a security manager exists and it doesn't allow access to the specified configuration.
        ConfigurationException - if there is a configuration value stored in an invalid format.
      • findConfigurationValue

        protected java.util.Optional<T> 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.

        Implementation Note:
        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 findConfigurationValueImpl(String) instead.
        Parameters:
        key - The configuration key, which may not be normalized.
        Returns:
        The optional configuration value associated with the given key.
        Throws:
        java.lang.NullPointerException - if the given key is null.
        java.lang.SecurityException - If a security manager exists and it doesn't allow access to the specified configuration.
        ConfigurationException - if there is a configuration value stored in an invalid format.
        See Also:
        normalizeKey(String)
      • findConfigurationValueImpl

        protected abstract java.util.Optional<T> findConfigurationValueImpl​(@Nonnull
                                                                            java.lang.String key)
                                                                     throws ConfigurationException
        Implementation to retrieves a general configuration value that may not be present from the underlying storage.

        The given configuration 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 configuration key.
        Returns:
        The optional configuration value associated with the given key.
        Throws:
        java.lang.NullPointerException - if the given key is null.
        java.lang.SecurityException - If a security manager exists and it doesn't allow access to the specified configuration.
        ConfigurationException - if there is a configuration value stored in an invalid format.