Interface ConfigFilter

All Known Implementing Classes:
EncryptionFilter, EncryptionFilterService, OverrideConfigFilter, ValueResolvingFilter
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface ConfigFilter
Filter that can transform elementary configuration (String) values before they are returned via the Config API.

The application can register filters with a builder by invoking Config.Builder.addFilter(ConfigFilter) or Config.Builder.addFilter(java.util.function.Function). The config system also locates filters using the Java ServiceLoader mechanism and automatically adds them to every Builder unless the application disables this feature for a given Builder by invoking Config.Builder.disableFilterServices().

A filter can specify a Weight. If no weight is explicitly assigned, the value of 100.0 is assumed.

Initializing Filters

Any filter that uses the Config instance during its initialization should do so in its init(Config) method, not in its constructor. The Config.Builder.build() method invokes each filter's `init` method according to the filters' weight and just before returning the new Config instance to the application.

If a filter's init method uses Config#get to retrieve config information, then -- as always -- the config system will invoke the apply method on every filter which the application added to the builder. But the init methods of filters with lower weight than the current filter will not have executed. Developers should keep this in mind while writing filter init methods.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    apply(Config.Key key, String stringValue)
    Filters an elementary config value before it is made available to the application via the Config API.
    default void
    init(Config config)
    Initializes the filter using the Config instance which the filter will affect once Config.Builder.build completes.
  • Method Details

    • apply

      String apply(Config.Key key, String stringValue)
      Filters an elementary config value before it is made available to the application via the Config API.
      Parameters:
      key - configuration key associated with the Config node
      stringValue - original value to be filtered, never null
      Returns:
      original value or filtered (changed) value, never null
    • init

      default void init(Config config)
      Initializes the filter using the Config instance which the filter will affect once Config.Builder.build completes.

      The config system propagates any thrown exception to the application so its invocation of Config.Builder#build fails.

      Parameters:
      config - Config instance under construction