Interface ConfigFilter
-
- All Known Implementing Classes:
EncryptionFilter,EncryptionFilterService
- 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 theConfigAPI.The application can register filters with a builder by invoking
Config.Builder.addFilter(ConfigFilter)orConfig.Builder.addFilter(java.util.function.Function). The config system also locates filters using the JavaServiceLoadermechanism and automatically adds them to everyBuilderunless the application disables this feature for a givenBuilderby invokingConfig.Builder.disableFilterServices().A filter can specify a
Priority. If no priority is explicitly assigned, the value of 100 is assumed.Initializing Filters
Any filter that uses theConfiginstance during its initialization should do so in itsinit(Config)method, not in its constructor. TheConfig.Builder.build()method invokes each filter's `init` method according to the filters' priority order and just before returning the newConfiginstance to the application.If a filter's
initmethod usesConfig#getto retrieve config information, then -- as always -- the config system will invoke theapplymethod on every filter which the application added to the builder. But theinitmethods of filters with lower priority than the current filter will not have executed. Developers should keep this in mind while writing filterinitmethods.
-
-
Field Summary
Fields Modifier and Type Field Description static intPRIORITYDefault priority of the filter if registered byConfig.Builderautomatically.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Stringapply(Config.Key key, String stringValue)Filters an elementary config value before it is made available to the application via theConfigAPI.default voidinit(Config config)Initializes the filter using theConfiginstance which the filter will affect onceConfig.Builder.buildcompletes.
-
-
-
Field Detail
-
PRIORITY
static final int PRIORITY
Default priority of the filter if registered byConfig.Builderautomatically.- See Also:
- Constant Field Values
-
-
Method Detail
-
apply
String apply(Config.Key key, String stringValue)
Filters an elementary config value before it is made available to the application via theConfigAPI.- Parameters:
key- configurationkeyassociated with theConfignodestringValue- original value to be filtered, nevernull- Returns:
- original value or filtered (changed) value, never
null
-
init
default void init(Config config)
Initializes the filter using theConfiginstance which the filter will affect onceConfig.Builder.buildcompletes.The config system propagates any thrown exception to the application so its invocation of
Config.Builder#buildfails.- Parameters:
config-Configinstance under construction
-
-