Class AbstractObjectConfiguration

  • All Implemented Interfaces:
    Configuration, Parameters
    Direct Known Subclasses:
    ObjectMapConfiguration

    public abstract class AbstractObjectConfiguration
    extends BaseConfiguration<java.lang.Object>
    Abstract configuration implementation for which the underlying storage is based on general objects.

    In the current implementation, this class throws a ConfigurationException if the requested object is not of the requested type. A future version will allow values to be converted between compatible types.

    Author:
    Garret Wilson
    • Constructor Detail

      • AbstractObjectConfiguration

        public AbstractObjectConfiguration​(@Nullable
                                           Configuration parentConfiguration)
        Parent configuration constructor.
        Parameters:
        parentConfiguration - The parent configuration to use for fallback lookup, or null if there is no parent configuration.
    • Method Detail

      • convertParameter

        protected <C> java.util.Optional<C> convertParameter​(@Nonnull
                                                             java.util.Optional<java.lang.Object> parameter,
                                                             @Nonnull
                                                             java.lang.Class<C> convertClass)
                                                      throws ConfigurationException
        Converts a parameter from its actual type in the underlying storage to the requested type.

        The current implementation merely checked to see if the parameter can be cast to the requested type; otherwise, an exception is thrown.

        Type Parameters:
        C - The requested conversion type.
        Parameters:
        parameter - The parameter to convert.
        convertClass - The class indicating the requested conversion type.
        Returns:
        The parameter converted to the requested type.
        Throws:
        ConfigurationException - if the parameter is present and cannot be converted to the requested type.
      • getOptionalBoolean

        public java.util.Optional<java.lang.Boolean> getOptionalBoolean​(java.lang.String key)
                                                                 throws ConfigurationException
        Retrieves a Boolean parameter that may not be present.

        This implementation converts the value using convertParameter(Optional, Class).

        Parameters:
        key - The parameter key.
        Returns:
        The optional value of the parameter associated with the given key.
        Throws:
        ConfigurationException - if there is a parameter value stored in an invalid format.
      • getOptionalDouble

        public java.util.Optional<java.lang.Double> getOptionalDouble​(java.lang.String key)
                                                               throws ConfigurationException
        Retrieves a floating point parameter that may not be present.

        This implementation converts the value using convertParameter(Optional, Class).

        Parameters:
        key - The parameter key.
        Returns:
        The optional value of the parameter associated with the given key.
        Throws:
        ConfigurationException - if there is a parameter value stored in an invalid format.
      • getOptionalInt

        public java.util.Optional<java.lang.Integer> getOptionalInt​(java.lang.String key)
                                                             throws ConfigurationException
        Retrieves an integer parameter that may not be present.

        This implementation converts the value using convertParameter(Optional, Class).

        Parameters:
        key - The parameter key.
        Returns:
        The optional value of the parameter associated with the given key.
        Throws:
        ConfigurationException - if there is a parameter value stored in an invalid format.
      • getOptionalLong

        public java.util.Optional<java.lang.Long> getOptionalLong​(java.lang.String key)
                                                           throws ConfigurationException
        Retrieves a long integer parameter that may not be present.

        The default implementation delegates to Parameters.getOptionalInt(String).

        This implementation converts the value using convertParameter(Optional, Class).

        Parameters:
        key - The parameter key.
        Returns:
        The optional value of the parameter associated with the given key.
        Throws:
        ConfigurationException - if there is a parameter value stored in an invalid format.
      • getOptionalString

        public final java.util.Optional<java.lang.String> getOptionalString​(java.lang.String key)
                                                                     throws ConfigurationException
        Retrieves a string parameter that may not be present.

        TODO discuss dereferencing

        This implementation converts the value using convertParameter(Optional, Class).

        Parameters:
        key - The parameter key.
        Returns:
        The optional value of the parameter associated with the given key.
        Throws:
        ConfigurationException - if there is a parameter value stored in an invalid format.
        See Also:
        Format.format(Object)
      • getOptionalUri

        public java.util.Optional<java.net.URI> getOptionalUri​(java.lang.String key)
                                                        throws ConfigurationException
        Retrieves a URI parameter that may not be present.

        This implementation converts the value using convertParameter(Optional, Class).

        Parameters:
        key - The parameter key.
        Returns:
        The optional value of the parameter associated with the given key.
        Throws:
        ConfigurationException - if there is a parameter value stored in an invalid format.