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 theConfig
API.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 JavaServiceLoader
mechanism and automatically adds them to everyBuilder
unless the application disables this feature for a givenBuilder
by 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 theConfig
instance 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 newConfig
instance to the application.If a filter's
init
method usesConfig#get
to retrieve config information, then -- as always -- the config system will invoke theapply
method on every filter which the application added to the builder. But theinit
methods of filters with lower priority than the current filter will not have executed. Developers should keep this in mind while writing filterinit
methods.
-
-
Field Summary
Fields Modifier and Type Field Description static int
PRIORITY
Default priority of the filter if registered byConfig.Builder
automatically.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description String
apply(Config.Key key, String stringValue)
Filters an elementary config value before it is made available to the application via theConfig
API.default void
init(Config config)
Initializes the filter using theConfig
instance which the filter will affect onceConfig.Builder.build
completes.
-
-
-
Field Detail
-
PRIORITY
static final int PRIORITY
Default priority of the filter if registered byConfig.Builder
automatically.- 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 theConfig
API.- Parameters:
key
- configurationkey
associated with theConfig
nodestringValue
- 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 theConfig
instance which the filter will affect onceConfig.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
-
-