Package io.debezium.config
Interface Configuration
- All Known Subinterfaces:
JdbcConfiguration
An immutable representation of a Debezium configuration. A
Configuration instance can be obtained
from Properties or loaded from a file, stream,
reader, URL, or classpath resource. They can
also be built by first creating a builder and then using that builder to populate and
return the immutable Configuration instance.
A Configuration object is basically a decorator around a Properties object. It has methods to get and convert
individual property values to numeric, boolean and String types, optionally using a default value if the given property value
does not exist. However, it is immutable, so it does not have any methods to set property values, allowing
it to be passed around and reused without concern that other components might change the underlying property values.
- Author:
- Randall Hauch
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classA builder of Configuration objects.static interfaceConfiguration.ConfigBuilder<C extends Configuration,B extends Configuration.ConfigBuilder<C, B>> The basic interface for configuration builders. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionasMap()Get a copy of these configuration properties as a Properties object.Get a copy of these configuration properties with defaults as a Map.default PropertiesGet a copy of these configuration properties as a Properties object.default PropertiesasProperties(Field.Set fields) Get a copy of these configuration properties as a Properties object.static Configuration.Buildercopy(Configuration config) Create a newconfiguration builderthat starts with a copy of the supplied configuration.static Configuration.Buildercreate()Create a newconfiguration builder.default Configuration.Builderedit()Obtain an editor for a copy of this configuration.static Configurationempty()Obtain an empty configuration.default ConfigurationReturn a newConfigurationthat contains only the subset of keys that satisfy the given predicate.default <T> voidforEach(BiConsumer<String, String> function) Call the supplied function for each of the fields.default <T> voidforEachMatchingFieldName(String regex, int groupNumber, BiFunction<String, String, T> groupExtractor, BiConsumer<String, T> function) For all fields whose names match the given regular expression, extract a value from the specified group in the regular expression and call the supplied function.default voidforEachMatchingFieldName(String regex, BiConsumer<String, String> function) Apply the given function to all fields whose names match the given regular expression.default <T> voidforEachMatchingFieldName(Pattern regex, int groupNumber, BiFunction<String, String, T> groupExtractor, BiConsumer<String, T> function) For all fields whose names match the given regular expression, extract a value from the specified group in the regular expression and call the supplied function.default voidforEachMatchingFieldName(Pattern regex, BiConsumer<String, String> function) Apply the given function to all fields whose names match the given regular expression.default <T> voidforEachMatchingFieldNameWithBoolean(String regex, int groupNumber, BiConsumer<String, Boolean> function) For all fields whose names match the given regular expression, extract a boolean value from the first group in the regular expression and call the supplied function.default <T> voidforEachMatchingFieldNameWithBoolean(String regex, BiConsumer<String, Boolean> function) For all fields whose names match the given regular expression, extract a boolean value from the first group in the regular expression and call the supplied function.default <T> voidforEachMatchingFieldNameWithBoolean(Pattern regex, int groupNumber, BiConsumer<String, Boolean> function) For all fields whose names match the given regular expression, extract a boolean value from the first group in the regular expression and call the supplied function.default <T> voidforEachMatchingFieldNameWithInteger(String regex, int groupNumber, BiConsumer<String, Integer> function) For all fields whose names match the given regular expression, extract an integer from the first group in the regular expression and call the supplied function.default <T> voidforEachMatchingFieldNameWithInteger(String regex, BiConsumer<String, Integer> function) For all fields whose names match the given regular expression, extract an integer from the first group in the regular expression and call the supplied function.default <T> voidforEachMatchingFieldNameWithInteger(Pattern regex, int groupNumber, BiConsumer<String, Integer> function) For all fields whose names match the given regular expression, extract an integer from the first group in the regular expression and call the supplied function.default <T> voidforEachMatchingFieldNameWithString(String regex, int groupNumber, BiConsumer<String, String> function) For all fields whose names match the given regular expression, extract a string value from the first group in the regular expression and call the supplied function.default <T> voidforEachMatchingFieldNameWithString(String regex, BiConsumer<String, String> function) For all fields whose names match the given regular expression, extract a string value from the first group in the regular expression and call the supplied function.default <T> voidforEachMatchingFieldNameWithString(Pattern regex, int groupNumber, BiConsumer<String, String> function) For all fields whose names match the given regular expression, extract a string value from the first group in the regular expression and call the supplied function.static ConfigurationObtain a configuration instance by copying the supplied map of string keys and object values.static <T> ConfigurationObtain a configuration instance by copying the supplied map of string keys and object values.static Configurationfrom(Properties properties) Obtain a configuration instance by copying the supplied Properties object.static ConfigurationfromSystemProperties(String prefix) Create a Configuration object that is populated by system properties, perwithSystemProperties(String).default booleangetBoolean(Field field) Get the boolean value associated with the given field when that field has a default value.default booleangetBoolean(Field field, boolean defaultValue) Get the boolean value associated with the given field, returning the field's default value if there is no such key-value pair.default BooleangetBoolean(Field field, BooleanSupplier defaultValueSupplier) Get the boolean value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.default BooleangetBoolean(String key) Get the boolean value associated with the given key.default booleangetBoolean(String key, boolean defaultValue) Get the boolean value associated with the given key, returning the default value if there is no such key-value pair or if the value could not beparsedas a boolean value.default BooleangetBoolean(String key, BooleanSupplier defaultValueSupplier) Get the boolean value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.default DurationgetDuration(Field field, TemporalUnit unit) Gets the duration value associated with the given key.default StringgetFallbackStringProperty(Field newProperty, Field oldProperty) Returns the string config value from newProperty config field if it's set or its default value when it's not set/null.If both are null it returns the value of the oldProperty config field, or its default value when it's null.default StringgetFallbackStringPropertyWithWarning(Field newProperty, Field oldProperty) Returns the string config value from newProperty config field with a warning if it's set or its default value when it's not set/null.default <T> TgetInstance(Field field, Class<T> clazz) Get an instance of the class given by the value in the configuration associated with the given field.default <T> TgetInstance(Field field, Class<T> clazz, Configuration configuration) Get an instance of the class given by the value in the configuration associated with the given field.default <T> TgetInstance(Field field, Class<T> type, Supplier<ClassLoader> classloaderSupplier) Get an instance of the class given by the value in the configuration associated with the given field.default <T> TgetInstance(Field field, Class<T> clazz, Properties props) Get an instance of the class given by the value in the configuration associated with the given field.default <T> TgetInstance(String key, Class<T> type) Get an instance of the class given by the value in the configuration associated with the given key.default <T> TgetInstance(String key, Class<T> clazz, Configuration configuration) Get an instance of the class given by the value in the configuration associated with the given key.default <T> TgetInstance(String key, Class<T> type, Supplier<ClassLoader> classloaderSupplier) Get an instance of the class given by the value in the configuration associated with the given key.default intgetInteger(Field field) Get the integer value associated with the given field, returning the field's default value if there is no such key-value pair.default intgetInteger(Field field, int defaultValue) Get the integer value associated with the given field, returning the field's default value if there is no such key-value pair.default IntegergetInteger(Field field, IntSupplier defaultValueSupplier) Get the integer value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.default IntegergetInteger(String key) Get the integer value associated with the given key.default intgetInteger(String key, int defaultValue) Get the integer value associated with the given key, returning the default value if there is no such key-value pair or if the value could not beparsedas an integer.default IntegergetInteger(String key, IntSupplier defaultValueSupplier) Get the integer value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.default longGet the long value associated with the given field, returning the field's default value if there is no such key-value pair.default longGet the long value associated with the given field, returning the field's default value if there is no such key-value pair.default LonggetLong(Field field, LongSupplier defaultValueSupplier) Get the long value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.default LongGet the long value associated with the given key.default longGet the long value associated with the given key, returning the default value if there is no such key-value pair or if the value could not beparsedas a long.default LonggetLong(String key, LongSupplier defaultValueSupplier) Get the long value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.default NumberGet the numeric value associated with the given field, returning the field's default value if there is no such key-value pair.default NumberGet the integer value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.default StringGet the string value associated with the given field, returning the field's default value if there is no such key-value pair in this configuration.default StringGet the string value associated with the given field, returning the field's default value if there is no such key-value pair in this configuration.default StringGet the boolean value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.Get the string value associated with the given key.default StringGet the string value associated with the given key, returning the default value if there is no such key-value pair.default StringGet the string value associated with the given key, returning the default value if there is no such key-value pair.getStrings(Field field, String regex) Get the string value(s) associated with the given key, where the supplied regular expression is used to parse the single string value into multiple values.getStrings(String key, String regex) Get the string value(s) associated with the given key, where the supplied regular expression is used to parse the single string value into multiple values.getTrimmedStrings(Field field, String regex) Get the string value(s) associated with the given key, where the supplied regular expression is used to parse the single string value into multiple values.default booleanDetermine whether this configuration contains a key-value pair associated with the given field and the value is non-null.default booleanDetermine whether this configuration contains a key-value pair with the given key and the value is non-nulldefault booleanisEmpty()Determine if this configuration is empty and has no properties.keys()Get the set of keys in this configuration.static ConfigurationObtain a configuration instance by loading the Properties from the supplied file.static Configurationload(InputStream stream) Obtain a configuration instance by loading the Properties from the supplied stream.static ConfigurationObtain a configuration instance by loading the Properties from the supplied reader.static ConfigurationObtain a configuration instance by loading the Properties from a file on the file system or classpath given by the supplied path.static Configurationload(String path, ClassLoader classLoader) Obtain a configuration instance by loading the Properties from a file on the file system or classpath given by the supplied path.static Configurationload(String path, ClassLoader classLoader, Consumer<String> logger) Obtain a configuration instance by loading the Properties from a file on the file system or classpath given by the supplied path.static ConfigurationObtain a configuration instance by loading the Properties from the supplied URL.default ConfigurationReturn a newConfigurationthat contains only the subset of keys that satisfy the given predicate.default Configurationmapped(BiFunction<? super String, ? super String, String> mapper) Return a newConfigurationthat contains the mapped values.default ConfigurationReturn a newConfigurationthat contains only the subset of keys that match the given prefix.Validate the supplied fields in this configuration.default booleanvalidate(Iterable<Field> fields, Field.ValidationOutput problems) Validate the supplied fields in this configuration.default booleanvalidateAndRecord(Iterable<Field> fields, Consumer<String> problems) Validate the supplied fields in this configuration.default ConfigurationwithMasked(String keyRegex) Return a newConfigurationthat contains all of the same fields as this configuration, except with masked values for all keys that match the specified pattern.default ConfigurationwithMasked(Pattern keyRegex) Return a newConfigurationthat contains all of the same fields as this configuration, except with masked values for all keys that match the specified pattern.default ConfigurationReturn a newConfigurationthat contains all of the same fields as this configuration, except with masked values for all keys that end in "password".default ConfigurationwithReplacedVariables(Function<String, String> valuesByVariableName) Return a newConfigurationthat contains all of the same fields as this configuration, except with all variables in the fields replaced with values from the supplied function.default ConfigurationwithSystemProperties(String prefix) Return a copy of this configuration except where acceptable system properties are used to overwrite properties copied from this configuration.default ConfigurationwithSystemProperties(Function<String, String> propertyNameConverter) Return a copy of this configuration except where acceptable system properties are used to overwrite properties copied from this configuration.
-
Field Details
-
CONFIGURATION_LOGGER
static final org.slf4j.Logger CONFIGURATION_LOGGER -
PASSWORD_PATTERN
-
-
Method Details
-
create
Create a newconfiguration builder.- Returns:
- the configuration builder
-
copy
Create a newconfiguration builderthat starts with a copy of the supplied configuration.- Parameters:
config- the configuration to copy; may be null- Returns:
- the configuration builder
-
fromSystemProperties
Create a Configuration object that is populated by system properties, perwithSystemProperties(String).- Parameters:
prefix- the required prefix for the system properties; may not be null but may be empty- Returns:
- the configuration
-
empty
Obtain an empty configuration.- Returns:
- an empty configuration; never null
-
from
Obtain a configuration instance by copying the supplied Properties object. The suppliedPropertiesobject is copied so that the resulting Configuration cannot be modified.- Parameters:
properties- the properties; may be null or empty- Returns:
- the configuration; never null
-
from
Obtain a configuration instance by copying the supplied map of string keys and object values. The entries within the map are copied so that the resulting Configuration cannot be modified.- Parameters:
properties- the properties; may be null or empty- Returns:
- the configuration; never null
-
from
Obtain a configuration instance by copying the supplied map of string keys and object values. The entries within the map are copied so that the resulting Configuration cannot be modified.- Parameters:
properties- the properties; may be null or emptyconversion- the function that converts the supplied values into strings, or returnsnullif the value is to be excluded- Returns:
- the configuration; never null
-
load
Obtain a configuration instance by loading the Properties from the supplied URL.- Parameters:
url- the URL to the stream containing the configuration properties; may not be null- Returns:
- the configuration; never null
- Throws:
IOException- if there is an error reading the stream
-
load
Obtain a configuration instance by loading the Properties from the supplied file.- Parameters:
file- the file containing the configuration properties; may not be null- Returns:
- the configuration; never null
- Throws:
IOException- if there is an error reading the stream
-
load
Obtain a configuration instance by loading the Properties from the supplied stream.- Parameters:
stream- the stream containing the properties; may not be null- Returns:
- the configuration; never null
- Throws:
IOException- if there is an error reading the stream
-
load
Obtain a configuration instance by loading the Properties from the supplied reader.- Parameters:
reader- the reader containing the properties; may not be null- Returns:
- the configuration; never null
- Throws:
IOException- if there is an error reading the stream
-
load
Obtain a configuration instance by loading the Properties from a file on the file system or classpath given by the supplied path.- Parameters:
path- the path to the file containing the configuration properties; may not be nullclazz- the class whose classpath is to be used to find the file; may be null- Returns:
- the configuration; never null but possibly empty
- Throws:
IOException- if there is an error reading the stream
-
load
Obtain a configuration instance by loading the Properties from a file on the file system or classpath given by the supplied path.- Parameters:
path- the path to the file containing the configuration properties; may not be nullclassLoader- the class loader to use; may be null- Returns:
- the configuration; never null but possibly empty
- Throws:
IOException- if there is an error reading the stream
-
load
static Configuration load(String path, ClassLoader classLoader, Consumer<String> logger) throws IOException Obtain a configuration instance by loading the Properties from a file on the file system or classpath given by the supplied path.- Parameters:
path- the path to the file containing the configuration properties; may not be nullclassLoader- the class loader to use; may be nulllogger- the function that will be called with status updates; may be null- Returns:
- the configuration; never null but possibly empty
- Throws:
IOException- if there is an error reading the stream
-
edit
Obtain an editor for a copy of this configuration.- Returns:
- a builder that is populated with this configuration's key-value pairs; never null
-
hasKey
Determine whether this configuration contains a key-value pair with the given key and the value is non-null- Parameters:
key- the key- Returns:
- true if the configuration contains the key, or false otherwise
-
hasKey
Determine whether this configuration contains a key-value pair associated with the given field and the value is non-null.- Parameters:
field- the field; may not be null- Returns:
- true if the configuration contains the key, or false otherwise
-
keys
Get the set of keys in this configuration.- Returns:
- the set of keys; never null but possibly empty
-
getString
Get the string value associated with the given key.- Parameters:
key- the key for the configuration property- Returns:
- the value, or null if the key is null or there is no such key-value pair in the configuration
-
getString
Get the string value associated with the given key, returning the default value if there is no such key-value pair.- Parameters:
key- the key for the configuration propertydefaultValue- the value that should be returned by default if there is no such key-value pair in the configuration; may be null- Returns:
- the configuration value, or the
defaultValueif there is no such key-value pair in the configuration
-
getString
Get the string value associated with the given key, returning the default value if there is no such key-value pair.- Parameters:
key- the key for the configuration propertydefaultValueSupplier- the supplier of value that should be returned by default if there is no such key-value pair in the configuration; may be null and may return null- Returns:
- the configuration value, or the
defaultValueif there is no such key-value pair in the configuration
-
getString
Get the string value associated with the given field, returning the field's default value if there is no such key-value pair in this configuration.- Parameters:
field- the field; may not be null- Returns:
- the configuration's value for the field, or the field's
default valueif there is no such key-value pair in the configuration
-
getString
Get the string value associated with the given field, returning the field's default value if there is no such key-value pair in this configuration.- Parameters:
field- the field; may not be nulldefaultValue- the default value- Returns:
- the configuration's value for the field, or the field's
default valueif there is no such key-value pair in the configuration
-
getStrings
Get the string value(s) associated with the given key, where the supplied regular expression is used to parse the single string value into multiple values.- Parameters:
field- the field; may not be nullregex- the delimiting regular expression- Returns:
- the list of string values; null only if there is no such key-value pair in the configuration
- See Also:
-
getStrings
Get the string value(s) associated with the given key, where the supplied regular expression is used to parse the single string value into multiple values.- Parameters:
key- the key for the configuration propertyregex- the delimiting regular expression- Returns:
- the list of string values; null only if there is no such key-value pair in the configuration
- See Also:
-
getTrimmedStrings
Get the string value(s) associated with the given key, where the supplied regular expression is used to parse the single string value into multiple values. In addition, all values will be trimmed.- Parameters:
field- the field for the configuration propertyregex- the delimiting regular expression- Returns:
- the list of string values; null only if there is no such key-value pair in the configuration
- See Also:
-
getInteger
Get the integer value associated with the given key.- Parameters:
key- the key for the configuration property- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration, or the value could not be parsed as an integer
-
getLong
Get the long value associated with the given key.- Parameters:
key- the key for the configuration property- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration, or the value could not be parsed as an integer
-
getBoolean
Get the boolean value associated with the given key.- Parameters:
key- the key for the configuration property- Returns:
- the boolean value, or null if the key is null, there is no such key-value pair in the configuration, or the value could not be parsed as a boolean value
-
getInteger
Get the integer value associated with the given key, returning the default value if there is no such key-value pair or if the value could not beparsedas an integer.- Parameters:
key- the key for the configuration propertydefaultValue- the default value- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration, or the value could not be parsed as an integer
-
getLong
Get the long value associated with the given key, returning the default value if there is no such key-value pair or if the value could not beparsedas a long.- Parameters:
key- the key for the configuration propertydefaultValue- the default value- Returns:
- the long value, or null if the key is null, there is no such key-value pair in the configuration, or the value could not be parsed as a long
-
getBoolean
Get the boolean value associated with the given key, returning the default value if there is no such key-value pair or if the value could not beparsedas a boolean value.- Parameters:
key- the key for the configuration propertydefaultValue- the default value- Returns:
- the boolean value, or null if the key is null, there is no such key-value pair in the configuration, or the value could not be parsed as a boolean value
-
getNumber
Get the integer value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.- Parameters:
key- the key for the configuration propertydefaultValueSupplier- the supplier for the default value; may be null- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration, the
defaultValueSupplierreference is null, or there is a key-value pair in the configuration but the value could not be parsed as an integer
-
getInteger
Get the integer value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.- Parameters:
key- the key for the configuration propertydefaultValueSupplier- the supplier for the default value; may be null- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration, the
defaultValueSupplierreference is null, or there is a key-value pair in the configuration but the value could not be parsed as an integer
-
getLong
Get the long value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.- Parameters:
key- the key for the configuration propertydefaultValueSupplier- the supplier for the default value; may be null- Returns:
- the long value, or null if the key is null, there is no such key-value pair in the configuration, the
defaultValueSupplierreference is null, or there is a key-value pair in the configuration but the value could not be parsed as a long
-
getBoolean
Get the boolean value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.- Parameters:
key- the key for the configuration propertydefaultValueSupplier- the supplier for the default value; may be null- Returns:
- the boolean value, or null if the key is null, there is no such key-value pair in the configuration, the
defaultValueSupplierreference is null, or there is a key-value pair in the configuration but the value could not be parsed as a boolean value
-
getNumber
Get the numeric value associated with the given field, returning the field's default value if there is no such key-value pair.- Parameters:
field- the field- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration and there is no default value in the field or the default value could not be parsed as a long, or there is a key-value pair in the configuration but the value could not be parsed as an integer value
- Throws:
NumberFormatException- if there is no name-value pair and the field has no default value
-
getInteger
Get the integer value associated with the given field, returning the field's default value if there is no such key-value pair.- Parameters:
field- the field- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration and there is no default value in the field or the default value could not be parsed as a long, or there is a key-value pair in the configuration but the value could not be parsed as an integer value
- Throws:
NumberFormatException- if there is no name-value pair and the field has no default value
-
getLong
Get the long value associated with the given field, returning the field's default value if there is no such key-value pair.- Parameters:
field- the field- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration and there is no default value in the field or the default value could not be parsed as a long, or there is a key-value pair in the configuration but the value could not be parsed as a long value
- Throws:
NumberFormatException- if there is no name-value pair and the field has no default value
-
getBoolean
Get the boolean value associated with the given field when that field has a default value. If the configuration does not have a name-value pair with the same name as the field, then the field's default value.- Parameters:
field- the field- Returns:
- the boolean value, or null if the key is null, there is no such key-value pair in the configuration and there is no default value in the field or the default value could not be parsed as a long, or there is a key-value pair in the configuration but the value could not be parsed as a boolean value
- Throws:
NumberFormatException- if there is no name-value pair and the field has no default value
-
getInteger
Get the integer value associated with the given field, returning the field's default value if there is no such key-value pair.- Parameters:
field- the fielddefaultValue- the default value- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration and there is no default value in the field or the default value could not be parsed as a long, or there is a key-value pair in the configuration but the value could not be parsed as an integer value
-
getLong
Get the long value associated with the given field, returning the field's default value if there is no such key-value pair.- Parameters:
field- the fielddefaultValue- the default value- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration and there is no default value in the field or the default value could not be parsed as a long, or there is a key-value pair in the configuration but the value could not be parsed as a long value
-
getBoolean
Get the boolean value associated with the given field, returning the field's default value if there is no such key-value pair.- Parameters:
field- the fielddefaultValue- the default value- Returns:
- the boolean value, or null if the key is null, there is no such key-value pair in the configuration and there is no default value in the field or the default value could not be parsed as a long, or there is a key-value pair in the configuration but the value could not be parsed as a boolean value
-
getInteger
Get the integer value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.- Parameters:
field- the fielddefaultValueSupplier- the supplier for the default value; may be null- Returns:
- the integer value, or null if the key is null, there is no such key-value pair in the configuration, the
defaultValueSupplierreference is null, or there is a key-value pair in the configuration but the value could not be parsed as an integer
-
getLong
Get the long value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.- Parameters:
field- the fielddefaultValueSupplier- the supplier for the default value; may be null- Returns:
- the long value, or null if the key is null, there is no such key-value pair in the configuration, the
defaultValueSupplierreference is null, or there is a key-value pair in the configuration but the value could not be parsed as a long
-
getBoolean
Get the boolean value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.- Parameters:
field- the fielddefaultValueSupplier- the supplier for the default value; may be null- Returns:
- the boolean value, or null if the key is null, there is no such key-value pair in the configuration, the
defaultValueSupplierreference is null, or there is a key-value pair in the configuration but the value could not be parsed as a boolean value
-
getString
Get the boolean value associated with the given key, using the given supplier to obtain a default value if there is no such key-value pair.- Parameters:
field- the fielddefaultValueSupplier- the supplier of value that should be returned by default if there is no such key-value pair in the configuration; may be null and may return null- Returns:
- the configuration value, or the
defaultValueif there is no such key-value pair in the configuration
-
getDuration
Gets the duration value associated with the given key.- Parameters:
field- the fieldunit- the temporal unit of the duration value- Returns:
- the duration value associated with the given key
-
getInstance
Get an instance of the class given by the value in the configuration associated with the given key.- Parameters:
key- the key for the configuration propertytype- the Class of which the resulting object is expected to be an instance of; may not be null- Returns:
- the new instance, or null if there is no such key-value pair in the configuration or if there is a key-value configuration but the value could not be converted to an existing class with a zero-argument constructor
-
getInstance
Get an instance of the class given by the value in the configuration associated with the given key.- Parameters:
key- the key for the configuration propertytype- the Class of which the resulting object is expected to be an instance of; may not be nullclassloaderSupplier- the supplier of the ClassLoader to be used to load the resulting class; may be null if this class' ClassLoader should be used- Returns:
- the new instance, or null if there is no such key-value pair in the configuration or if there is a key-value configuration but the value could not be converted to an existing class with a zero-argument constructor
-
getInstance
Get an instance of the class given by the value in the configuration associated with the given key. The instance is created usingInstance(Configuration)constructor.- Parameters:
key- the key for the configuration propertyclazz- the Class of which the resulting object is expected to be an instance of; may not be nullconfiguration-Configurationobject that is passed as a parameter to the constructor- Returns:
- the new instance, or null if there is no such key-value pair in the configuration or if there is a key-value configuration but the value could not be converted to an existing class with a zero-argument constructor
-
getInstance
Get an instance of the class given by the value in the configuration associated with the given field.- Parameters:
field- the field for the configuration propertyclazz- the Class of which the resulting object is expected to be an instance of; may not be null- Returns:
- the new instance, or null if there is no such key-value pair in the configuration or if there is a key-value configuration but the value could not be converted to an existing class with a zero-argument constructor
-
getInstance
Get an instance of the class given by the value in the configuration associated with the given field.- Parameters:
field- the field for the configuration propertytype- the Class of which the resulting object is expected to be an instance of; may not be nullclassloaderSupplier- the supplier of the ClassLoader to be used to load the resulting class; may be null if this class' ClassLoader should be used- Returns:
- the new instance, or null if there is no such key-value pair in the configuration or if there is a key-value configuration but the value could not be converted to an existing class with a zero-argument constructor
-
getInstance
Get an instance of the class given by the value in the configuration associated with the given field. The instance is created usingInstance(Configuration)constructor.- Parameters:
field- the field for the configuration propertyclazz- the Class of which the resulting object is expected to be an instance of; may not be nullconfiguration- theConfigurationobject that is passed as a parameter to the constructor- Returns:
- the new instance, or null if there is no such key-value pair in the configuration or if there is a key-value configuration but the value could not be converted to an existing class with a zero-argument constructor
-
getInstance
Get an instance of the class given by the value in the configuration associated with the given field. The instance is created usingInstance(Configuration)constructor.- Parameters:
field- the field for the configuration propertyclazz- the Class of which the resulting object is expected to be an instance of; may not be nullprops- thePropertiesobject that is passed as a parameter to the constructor- Returns:
- the new instance, or null if there is no such key-value pair in the configuration or if there is a key-value configuration but the value could not be converted to an existing class with a zero-argument constructor
-
subset
Return a newConfigurationthat contains only the subset of keys that match the given prefix. If desired, the keys in the resulting Configuration will have the prefix (plus any terminating "." character if needed) removed.This method returns this Configuration instance if the supplied
prefixis null or empty.- Parameters:
prefix- the prefixremovePrefix- true if the prefix (and any subsequent "." character) should be removed from the keys in the resulting Configuration, or false if the keys in this Configuration should be used as-is in the resulting Configuration- Returns:
- the subset of this Configuration; never null
-
map
Return a newConfigurationthat contains only the subset of keys that satisfy the given predicate.- Parameters:
mapper- that function that transforms keys- Returns:
- the subset Configuration; never null
-
filter
Return a newConfigurationthat contains only the subset of keys that satisfy the given predicate.- Parameters:
matcher- the function that determines whether a key should be included in the subset- Returns:
- the subset Configuration; never null
-
mapped
Return a newConfigurationthat contains the mapped values.- Parameters:
mapper- the function that takes a key and value and returns the new mapped value- Returns:
- the Configuration with mapped values; never null
-
withReplacedVariables
Return a newConfigurationthat contains all of the same fields as this configuration, except with all variables in the fields replaced with values from the supplied function. Variables found in fields will be left as-is if the supplied function returns no value for the variable name(s).Variables may appear anywhere within a field value, and multiple variables can be used within the same field. Variables take the form:
variable := '${' variableNames [ ':' defaultValue ] '}' variableNames := variableName [ ',' variableNames ] variableName := // any characters except ',' and ':' and '}' defaultValue := // any characters except '}'and examples of variables include:${var1}${var1:defaultValue}${var1,var2}${var1,var2:defaultValue}
- Parameters:
valuesByVariableName- the function that returns a variable value for a variable name; may not be null but may return null if the variable name is not known- Returns:
- the Configuration with masked values for matching keys; never null
-
withMaskedPasswords
Return a newConfigurationthat contains all of the same fields as this configuration, except with masked values for all keys that end in "password".- Returns:
- the Configuration with masked values for matching keys; never null
-
withMasked
Return a newConfigurationthat contains all of the same fields as this configuration, except with masked values for all keys that match the specified pattern.- Parameters:
keyRegex- the regular expression to match against the keys- Returns:
- the Configuration with masked values for matching keys; never null
-
withMasked
Return a newConfigurationthat contains all of the same fields as this configuration, except with masked values for all keys that match the specified pattern.- Parameters:
keyRegex- the regular expression to match against the keys- Returns:
- the Configuration with masked values for matching keys; never null
-
isEmpty
default boolean isEmpty()Determine if this configuration is empty and has no properties.- Returns:
trueif empty, orfalseotherwise
-
asProperties
Get a copy of these configuration properties as a Properties object.- Returns:
- the properties object; never null
-
asProperties
Get a copy of these configuration properties as a Properties object.- Parameters:
fields- the fields defining the defaults; may be null- Returns:
- the properties object; never null
-
asMap
Get a copy of these configuration properties as a Properties object.- Returns:
- the properties object; never null
-
asMap
Get a copy of these configuration properties with defaults as a Map.- Parameters:
fields- the fields defining the defaults; may be null- Returns:
- the properties object; never null
-
withSystemProperties
Return a copy of this configuration except where acceptable system properties are used to overwrite properties copied from this configuration. All system properties whose name has the given prefix are added, where the prefix is removed from the system property name, it is converted to lower case, and each underscore character ('_') are replaced with a period ('.').- Parameters:
prefix- the required prefix for the system properties- Returns:
- the resulting properties converted from the system properties; never null, but possibly empty
-
withSystemProperties
Return a copy of this configuration except where acceptable system properties are used to overwrite properties copied from this configuration. Each of the system properties is examined and passed to the supplied function; if the result of the function is a non-null string, then a property with that string as the name and the system property value are added to the returned configuration.- Parameters:
propertyNameConverter- the function that will convert the name of each system property to an applicable property name (or null if the system property name does not apply); may not be null- Returns:
- the resulting properties filtered from the input properties; never null, but possibly empty
-
validate
Validate the supplied fields in this configuration. Extra fields not described by the suppliedfieldsparameter are not validated.- Parameters:
fields- the fieldsproblems- the consumer to be called with each problem; never null- Returns:
trueif the value is considered valid, orfalseif it is not valid
-
validateAndRecord
Validate the supplied fields in this configuration. Extra fields not described by the suppliedfieldsparameter are not validated.- Parameters:
fields- the fieldsproblems- the consumer to be called with each problem; never null- Returns:
trueif the value is considered valid, orfalseif it is not valid
-
validate
Validate the supplied fields in this configuration. Extra fields not described by the suppliedfieldsparameter are not validated.- Parameters:
fields- the fields- Returns:
- the
ConfigValuefor each of the fields; never null
-
forEachMatchingFieldName
Apply the given function to all fields whose names match the given regular expression.- Parameters:
regex- the regular expression string; may not be nullfunction- the consumer that takes the name and value of matching fields; may not be null
-
forEachMatchingFieldName
Apply the given function to all fields whose names match the given regular expression.- Parameters:
regex- the regular expression string; may not be nullfunction- the consumer that takes the name and value of matching fields; may not be null
-
forEachMatchingFieldNameWithInteger
default <T> void forEachMatchingFieldNameWithInteger(String regex, BiConsumer<String, Integer> function) For all fields whose names match the given regular expression, extract an integer from the first group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullfunction- the consumer that takes the value of matching field and the integer extracted from the field name; may not be null
-
forEachMatchingFieldNameWithInteger
default <T> void forEachMatchingFieldNameWithInteger(String regex, int groupNumber, BiConsumer<String, Integer> function) For all fields whose names match the given regular expression, extract an integer from the first group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullgroupNumber- the number of the regular expression group containing the integer to be extracted; must be positivefunction- the consumer that takes the value of matching field and the integer extracted from the field name; may not be null
-
forEachMatchingFieldNameWithInteger
default <T> void forEachMatchingFieldNameWithInteger(Pattern regex, int groupNumber, BiConsumer<String, Integer> function) For all fields whose names match the given regular expression, extract an integer from the first group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullgroupNumber- the number of the regular expression group containing the integer to be extracted; must be positivefunction- the consumer that takes the value of matching field and the integer extracted from the field name; may not be null
-
forEachMatchingFieldNameWithBoolean
default <T> void forEachMatchingFieldNameWithBoolean(String regex, BiConsumer<String, Boolean> function) For all fields whose names match the given regular expression, extract a boolean value from the first group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullfunction- the consumer that takes the value of matching field and the boolean extracted from the field name; may not be null
-
forEachMatchingFieldNameWithBoolean
default <T> void forEachMatchingFieldNameWithBoolean(String regex, int groupNumber, BiConsumer<String, Boolean> function) For all fields whose names match the given regular expression, extract a boolean value from the first group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullgroupNumber- the number of the regular expression group containing the boolean to be extracted; must be positivefunction- the consumer that takes the value of matching field and the boolean extracted from the field name; may not be null
-
forEachMatchingFieldNameWithBoolean
default <T> void forEachMatchingFieldNameWithBoolean(Pattern regex, int groupNumber, BiConsumer<String, Boolean> function) For all fields whose names match the given regular expression, extract a boolean value from the first group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullgroupNumber- the number of the regular expression group containing the boolean to be extracted; must be positivefunction- the consumer that takes the value of matching field and the boolean extracted from the field name; may not be null
-
forEachMatchingFieldNameWithString
default <T> void forEachMatchingFieldNameWithString(String regex, BiConsumer<String, String> function) For all fields whose names match the given regular expression, extract a string value from the first group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullfunction- the consumer that takes the value of matching field and the string value extracted from the field name; may not be null
-
forEachMatchingFieldNameWithString
default <T> void forEachMatchingFieldNameWithString(String regex, int groupNumber, BiConsumer<String, String> function) For all fields whose names match the given regular expression, extract a string value from the first group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullgroupNumber- the number of the regular expression group containing the string value to be extracted; must be positivefunction- the consumer that takes the value of matching field and the string value extracted from the field name; may not be null
-
forEachMatchingFieldNameWithString
default <T> void forEachMatchingFieldNameWithString(Pattern regex, int groupNumber, BiConsumer<String, String> function) For all fields whose names match the given regular expression, extract a string value from the first group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullgroupNumber- the number of the regular expression group containing the string value to be extracted; must be positivefunction- the consumer that takes the value of matching field and the string value extracted from the field name; may not be null
-
forEachMatchingFieldName
default <T> void forEachMatchingFieldName(String regex, int groupNumber, BiFunction<String, String, T> groupExtractor, BiConsumer<String, T> function) For all fields whose names match the given regular expression, extract a value from the specified group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullgroupNumber- the number of the regular expression group containing the string value to be extracted; must be positivegroupExtractor- the function that extracts the value from the groupfunction- the consumer that takes the value of matching field and the value extracted from the field name; may not be null
-
forEachMatchingFieldName
default <T> void forEachMatchingFieldName(Pattern regex, int groupNumber, BiFunction<String, String, T> groupExtractor, BiConsumer<String, T> function) For all fields whose names match the given regular expression, extract a value from the specified group in the regular expression and call the supplied function.- Parameters:
regex- the regular expression string; may not be nullgroupNumber- the number of the regular expression group containing the string value to be extracted; must be positivegroupExtractor- the function that extracts the value from the groupfunction- the consumer that takes the value of matching field and the value extracted from the field name; may not be null
-
forEach
Call the supplied function for each of the fields.- Parameters:
function- the consumer that takes the field name and the string value extracted from the field; may not be null
-
getFallbackStringProperty
Returns the string config value from newProperty config field if it's set or its default value when it's not set/null.If both are null it returns the value of the oldProperty config field, or its default value when it's null. This fallback only works for newProperty fields that have a null / not-set default value!- Parameters:
newProperty- the new property config fieldoldProperty- the old / fallback property config field- Returns:
- the evaluated value
-
getFallbackStringPropertyWithWarning
Returns the string config value from newProperty config field with a warning if it's set or its default value when it's not set/null. If both are null it returns the value of the oldProperty config field with a warning, or its default value when it's null.
-