- All Known Subinterfaces:
ConfigPropertySource.Unconfigured,FileMutableConfig,FileWatchableConfig,MutableConfig,PreferencesMutableConfig,WatchableConfig
- All Known Implementing Classes:
AbstractConfig,AbstractMutableConfig,AbstractWatchableConfig,CommonsConfigImpl,CommonsMutableConfigImpl,DelegatedConfig,DelegatedMutableConfig,DelegatedWatchableConfig,EnvironmentConfigImpl,JsonConfigImpl,JsonMutableConfigImpl,PreferencesConfigImpl,PreferencesMutableConfigImpl,PropertiesConfigImpl,PropertiesMutableConfigImpl,SpringEnvironmentConfigImpl,SystemConfigImpl,XmlConfigImpl,XmlMutableConfigImpl,YamlConfigImpl,YamlMutableConfigImpl
@API(status=STABLE,
since="1.0")
public interface Config
Configuration properties provider.
- Since:
- 0.1
- Version:
- 1.0, 2019-07, 2.0, 2025-05
- Author:
- (w) Iker Hernaez
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Config>
TCreates a configuration proxy of the specified type.default <T extends Config>
TCreates a configuration proxy of the specified type.default booleanReturnstrueif the property with the key passed as argument has been configured.static @NotNull CommonsConfigBuilderCreates a new Apache Commons Configuration based configuration builder.static @NotNull EnvironmentConfigBuilderCreates a new environment variables based configuration builder.static @NotNull PreferencesConfigInitialBuilderCreates a newPreferencesbased configuration builder.static @NotNull JsonConfigBuilderfromJson()Creates a new JSON based configuration builder.static @NotNull PropertiesConfigBuilderCreates a newPropertiesbased configuration builder.static @NotNull SpringEnvironmentConfigInitialBuilderCreates a new Spring Environment based configuration builder.static @NotNull SystemConfigBuilderCreates a new system properties based configuration builder.static @NotNull XmlConfigBuilderfromXml()Creates a new XML based configuration builder.static @NotNull YamlConfigBuilderfromYaml()Creates a new YAML based configuration builder.Returns the value of the configuration parameter asString.default StringReturns the value of the configuration parameter asString.default StringReturns the value of the configuration parameter asString.default BooleangetBoolean(@NotBlank String key) Returns the value of the configuration parameter asBoolean.default booleangetBoolean(@NotBlank String key, boolean defaultValue) Returns the value of the configuration parameter asBoolean.default BooleangetBoolean(@NotBlank String key, @NotNull Supplier<Boolean> defaultValue) Returns the value of the configuration parameter asBoolean.default IntegergetInteger(@NotBlank String key, @NotNull Supplier<Integer> defaultValue) Returns the value of the configuration parameter asBoolean.default IntegergetInteger(@NotNull String key) Returns the integer value of the specified configuration property, with variable substitution.default intgetInteger(@NotNull String key, int defaultValue) Returns the integer value of the specified configuration property, with variable substitution.getKeys()Returns the configuration property keys contained in this configuration.Returns the configuration property keys contained in this configuration that start with the specified prefix.Returns the configuration property keys contained in this configuration that match the specified predicate.default LongReturns the value of the configuration parameter asBoolean.default LongReturns the integer value of the specified configuration property, with variable substitution.default longReturns the integer value of the specified configuration property, with variable substitution.default ConfigReturns the parent configuration, if any.default StringgetUndecored(@NotBlank String key) Returns the value of the configuration parameter asStringwithout applying any decoration or transformation.default booleanisEmpty()Returnstrueif the configuration contains no property.default @NotNull ConfigCreates a subset configuration containing only the properties with the specified prefix.
-
Method Details
-
fromEnvironmentVariables
Creates a new environment variables based configuration builder.- Returns:
- The configuration builder.
-
fromSystemProperties
Creates a new system properties based configuration builder.- Returns:
- The configuration builder.
-
fromProperties
Creates a newPropertiesbased configuration builder.- Returns:
- The configuration builder.
-
fromJson
Creates a new JSON based configuration builder.- Returns:
- The configuration builder.
-
fromYaml
Creates a new YAML based configuration builder.- Returns:
- The configuration builder.
-
fromXml
Creates a new XML based configuration builder.- Returns:
- The configuration builder.
-
fromJavaPreferences
Creates a newPreferencesbased configuration builder.- Returns:
- The configuration builder.
-
fromApacheCommons
Creates a new Apache Commons Configuration based configuration builder.- Returns:
- The configuration builder.
-
fromSpringEnvironment
Creates a new Spring Environment based configuration builder.- Returns:
- The configuration builder.
-
as
Creates a configuration proxy of the specified type.The configuration proxy will delegate all method calls to the underlying configuration instance, except for the default methods defined in the specified type interface, which will be invoked directly on the interface.
- Type Parameters:
T- The configuration type.- Parameters:
config- The proxied configuration instance.type- The configuration type interface to create a proxy for.- Returns:
- The proxy of the specified configuration type.
-
getParent
Returns the parent configuration, if any.- Returns:
- The parent configuration
-
isEmpty
default boolean isEmpty()Returnstrueif the configuration contains no property.- Returns:
- Returns
trueif the configuration contains no property. - Throws:
NonIterableConfigException- If the configuration property keys cannot be iterated.ConfigException- If an error occurs accessing the configuration.
-
contains
Returnstrueif the property with the key passed as argument has been configured.- Parameters:
key- The configuration property.- Returns:
- Returns
trueif the property has been configured.
-
getKeys
Returns the configuration property keys contained in this configuration.- Returns:
- The configuration property keys.
- Throws:
NonIterableConfigException- If the configuration property keys cannot be iterated.ConfigException- If an error occurs accessing the configuration.
-
getKeys
Returns the configuration property keys contained in this configuration that match the specified predicate.- Parameters:
filter- The predicate to filter the property keys with.- Returns:
- The configuration property keys that match the predicate.
- Throws:
NonIterableConfigException- If the configuration property keys cannot be iterated.ConfigException- If an error occurs accessing the configuration.
-
getKeys
Returns the configuration property keys contained in this configuration that start with the specified prefix.- Parameters:
prefix- The predicate to filter the property keys with.- Returns:
- The configuration property keys that match the predicate.
- Throws:
NonIterableConfigException- If the configuration property keys cannot be iterated.ConfigException- If an error occurs accessing the configuration.
-
get
Returns the value of the configuration parameter asString.- Parameters:
key- The configuration property- Returns:
- The configuration parameter value as
String - Throws:
ConfigException- If an error occurs retrieving the configuration property value
-
getUndecored
Returns the value of the configuration parameter asStringwithout applying any decoration or transformation.- Parameters:
key- The configuration property- Returns:
- The configuration parameter value as
String - Throws:
ConfigException- If an error occurs retrieving the configuration property value
-
get
Returns the value of the configuration parameter asString.- Parameters:
key- The key of the configuration parameterdefaultValue- The default value to return if the configuration parameter is not set or isnull.- Returns:
- The configuration parameter value as
String - Throws:
ConfigException- If an error occurs retrieving the configuration property value
-
get
Returns the value of the configuration parameter asString.- Parameters:
key- The key of the configuration parameterdefaultValue- The default value supplier if the configuration parameter is not set or isnull.- Returns:
- The configuration parameter value as
String - Throws:
ConfigException- If an error occurs retrieving the configuration property value
-
getBoolean
Returns the value of the configuration parameter asBoolean.- Parameters:
key- The key of the configuration parameter- Returns:
- The configuration parameter value as
Boolean - Throws:
ConfigException- If an error occurs retrieving the configuration property value
-
getBoolean
Returns the value of the configuration parameter asBoolean.- Parameters:
key- The key of the configuration parameterdefaultValue- The default value to return if the configuration parameter is not set or isnull.- Returns:
- The configuration parameter value as
Boolean - Throws:
ConfigException- If an error occurs retrieving the configuration property value
-
getBoolean
default Boolean getBoolean(@NotBlank @NotBlank String key, @NotNull @NotNull Supplier<Boolean> defaultValue) Returns the value of the configuration parameter asBoolean.- Parameters:
key- The key of the configuration parameterdefaultValue- The default value supplier if the configuration parameter is not set or isnull.- Returns:
- The configuration parameter value as
Boolean - Throws:
ConfigException- If an error occurs retrieving the configuration property value
-
getInteger
Returns the integer value of the specified configuration property, with variable substitution.- Parameters:
key- The configuration property.- Returns:
- The value configuration property, if any.
- Throws:
NumberFormatException- If the configuration value cannot be parsed as an integer.
-
getInteger
Returns the integer value of the specified configuration property, with variable substitution.- Parameters:
key- The configuration property.defaultValue- The default value to return if the configuration parameter is not set or isnull.- Returns:
- The value configuration property, if any.
- Throws:
NumberFormatException- If the configuration value cannot be parsed as an integer.
-
getInteger
default Integer getInteger(@NotBlank @NotBlank String key, @NotNull @NotNull Supplier<Integer> defaultValue) Returns the value of the configuration parameter asBoolean.- Parameters:
key- The key of the configuration parameterdefaultValue- The default value supplier if the configuration parameter is not set or isnull.- Returns:
- The configuration parameter value as
Boolean - Throws:
ConfigException- If an error occurs retrieving the configuration property value
-
getLong
Returns the integer value of the specified configuration property, with variable substitution.- Parameters:
key- The configuration property.- Returns:
- The value configuration property, if any.
- Throws:
NumberFormatException- If the configuration value cannot be parsed as an long.
-
getLong
Returns the integer value of the specified configuration property, with variable substitution.- Parameters:
key- The configuration property.defaultValue- The default value to return if the configuration parameter is not set or isnull.- Returns:
- The value configuration property, if any.
- Throws:
NumberFormatException- If the configuration value cannot be parsed as an long.
-
getLong
Returns the value of the configuration parameter asBoolean.- Parameters:
key- The key of the configuration parameterdefaultValue- The default value supplier if the configuration parameter is not set or isnull.- Returns:
- The configuration parameter value as
Boolean - Throws:
ConfigException- If an error occurs retrieving the configuration property value
-
as
Creates a configuration proxy of the specified type.The configuration proxy will delegate all method calls to this configuration instance, except for the default methods defined in the specified type interface, which will be invoked directly on the interface.
- Type Parameters:
T- The configuration type.- Parameters:
type- The configuration type interface to create a proxy for.- Returns:
- The proxy of the specified configuration type.
- See Also:
-
subset
Creates a subset configuration containing only the properties with the specified prefix.- Parameters:
prefix- The prefix for configuration keys.- Returns:
- The subset configuration.
-