Class SubConfiguration

  • All Implemented Interfaces:
    Configuration

    public class SubConfiguration
    extends AbstractConfigurationDecorator
    A configuration that decorates another configuration, providing a view of a subtree of the keyspace with some key prefix. The subconfiguration acts as a live view, but only has access to keys with the specified prefix plus 46, and those keys will effectively have the prefix and delimiter removed. For example if a key prefix of foo.bar is specified, only keys from the decorating logically starting with foo.bar. would be accessible in the subconfiguration. A setting in a configuration with the key foo.bar.example would be accessible in the subconfiguration as example.
    Author:
    Garret Wilson
    • Constructor Detail

      • SubConfiguration

        public SubConfiguration​(@Nonnull
                                Configuration configuration,
                                @Nonnull
                                java.lang.String prefixKey)
        Wrapped configuration constructor.
        Parameters:
        configuration - The configuration to decorate.
        prefixKey - The prefix not including the final segment separator 46.
        Throws:
        java.lang.NullPointerException - if the given configuration and/or prefix key is null.
    • Method Detail

      • decorateKey

        protected java.util.Optional<java.lang.String> decorateKey​(java.lang.String key)
        Description copied from class: AbstractConfigurationDecorator
        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..

        Overrides:
        decorateKey in class AbstractConfigurationDecorator
        Parameters:
        key - The key as provided by the caller.
        Returns:
        The key transformed appropriately to be passed to the wrapped configuration.