Interface Config

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 Type
    Method
    Description
    static <T extends Config>
    T
    as(@NotNull Config config, @NotNull Class<T> type)
    Creates a configuration proxy of the specified type.
    default <T extends Config>
    T
    as(@NotNull Class<T> type)
    Creates a configuration proxy of the specified type.
    default boolean
    contains(@NotBlank String key)
    Returns true if the property with the key passed as argument has been configured.
    static @NotNull CommonsConfigBuilder
    Creates a new Apache Commons Configuration based configuration builder.
    static @NotNull EnvironmentConfigBuilder
    Creates a new environment variables based configuration builder.
    Creates a new Preferences based configuration builder.
    static @NotNull JsonConfigBuilder
    Creates a new JSON based configuration builder.
    static @NotNull PropertiesConfigBuilder
    Creates a new Properties based configuration builder.
    Creates a new Spring Environment based configuration builder.
    static @NotNull SystemConfigBuilder
    Creates a new system properties based configuration builder.
    static @NotNull XmlConfigBuilder
    Creates a new XML based configuration builder.
    static @NotNull YamlConfigBuilder
    Creates a new YAML based configuration builder.
    get(@NotBlank String key)
    Returns the value of the configuration parameter as String.
    default String
    get(@NotBlank String key, @NotNull Supplier<String> defaultValue)
    Returns the value of the configuration parameter as String.
    default String
    get(@NotBlank String key, String defaultValue)
    Returns the value of the configuration parameter as String.
    default Boolean
    getBoolean(@NotBlank String key)
    Returns the value of the configuration parameter as Boolean.
    default boolean
    getBoolean(@NotBlank String key, boolean defaultValue)
    Returns the value of the configuration parameter as Boolean.
    default Boolean
    getBoolean(@NotBlank String key, @NotNull Supplier<Boolean> defaultValue)
    Returns the value of the configuration parameter as Boolean.
    default Integer
    getInteger(@NotBlank String key, @NotNull Supplier<Integer> defaultValue)
    Returns the value of the configuration parameter as Boolean.
    default Integer
    getInteger(@NotNull String key)
    Returns the integer value of the specified configuration property, with variable substitution.
    default int
    getInteger(@NotNull String key, int defaultValue)
    Returns the integer value of the specified configuration property, with variable substitution.
    default @NotNull Stream<String>
    Returns the configuration property keys contained in this configuration.
    default @NotNull Stream<String>
    getKeys(@NotNull String prefix)
    Returns the configuration property keys contained in this configuration that start with the specified prefix.
    default @NotNull Stream<String>
    getKeys(@NotNull Predicate<String> filter)
    Returns the configuration property keys contained in this configuration that match the specified predicate.
    default Long
    getLong(@NotBlank String key, @NotNull Supplier<Long> defaultValue)
    Returns the value of the configuration parameter as Boolean.
    default Long
    getLong(@NotNull String key)
    Returns the integer value of the specified configuration property, with variable substitution.
    default long
    getLong(@NotNull String key, long defaultValue)
    Returns the integer value of the specified configuration property, with variable substitution.
    default Config
    Returns the parent configuration, if any.
    default String
    getUndecored(@NotBlank String key)
    Returns the value of the configuration parameter as String without applying any decoration or transformation.
    default boolean
    Returns true if the configuration contains no property.
    default @NotNull Config
    subset(@NotNull String prefix)
    Creates a subset configuration containing only the properties with the specified prefix.
  • Method Details

    • fromEnvironmentVariables

      @NotNull static @NotNull EnvironmentConfigBuilder fromEnvironmentVariables()
      Creates a new environment variables based configuration builder.
      Returns:
      The configuration builder.
    • fromSystemProperties

      @NotNull static @NotNull SystemConfigBuilder fromSystemProperties()
      Creates a new system properties based configuration builder.
      Returns:
      The configuration builder.
    • fromProperties

      @NotNull static @NotNull PropertiesConfigBuilder fromProperties()
      Creates a new Properties based configuration builder.
      Returns:
      The configuration builder.
    • fromJson

      @NotNull static @NotNull JsonConfigBuilder fromJson()
      Creates a new JSON based configuration builder.
      Returns:
      The configuration builder.
    • fromYaml

      @NotNull static @NotNull YamlConfigBuilder fromYaml()
      Creates a new YAML based configuration builder.
      Returns:
      The configuration builder.
    • fromXml

      @NotNull static @NotNull XmlConfigBuilder fromXml()
      Creates a new XML based configuration builder.
      Returns:
      The configuration builder.
    • fromJavaPreferences

      @NotNull static @NotNull PreferencesConfigInitialBuilder fromJavaPreferences()
      Creates a new Preferences based configuration builder.
      Returns:
      The configuration builder.
    • fromApacheCommons

      @NotNull static @NotNull CommonsConfigBuilder fromApacheCommons()
      Creates a new Apache Commons Configuration based configuration builder.
      Returns:
      The configuration builder.
    • fromSpringEnvironment

      @NotNull static @NotNull SpringEnvironmentConfigInitialBuilder fromSpringEnvironment()
      Creates a new Spring Environment based configuration builder.
      Returns:
      The configuration builder.
    • as

      static <T extends Config> T as(@NotNull @NotNull Config config, @NotNull @NotNull Class<T> type)
      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

      default Config getParent()
      Returns the parent configuration, if any.
      Returns:
      The parent configuration
    • isEmpty

      default boolean isEmpty()
      Returns true if the configuration contains no property.
      Returns:
      Returns true if the configuration contains no property.
      Throws:
      NonIterableConfigException - If the configuration property keys cannot be iterated.
      ConfigException - If an error occurs accessing the configuration.
    • contains

      default boolean contains(@NotBlank @NotBlank String key)
      Returns true if the property with the key passed as argument has been configured.
      Parameters:
      key - The configuration property.
      Returns:
      Returns true if the property has been configured.
    • getKeys

      @NotNull default @NotNull Stream<String> 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

      @NotNull default @NotNull Stream<String> getKeys(@NotNull @NotNull Predicate<String> filter)
      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

      @NotNull default @NotNull Stream<String> getKeys(@NotNull @NotNull String prefix)
      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

      String get(@NotBlank @NotBlank String key)
      Returns the value of the configuration parameter as String.
      Parameters:
      key - The configuration property
      Returns:
      The configuration parameter value as String
      Throws:
      ConfigException - If an error occurs retrieving the configuration property value
    • getUndecored

      default String getUndecored(@NotBlank @NotBlank String key)
      Returns the value of the configuration parameter as String without 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

      default String get(@NotBlank @NotBlank String key, String defaultValue)
      Returns the value of the configuration parameter as String.
      Parameters:
      key - The key of the configuration parameter
      defaultValue - The default value to return if the configuration parameter is not set or is null.
      Returns:
      The configuration parameter value as String
      Throws:
      ConfigException - If an error occurs retrieving the configuration property value
    • get

      default String get(@NotBlank @NotBlank String key, @NotNull @NotNull Supplier<String> defaultValue)
      Returns the value of the configuration parameter as String.
      Parameters:
      key - The key of the configuration parameter
      defaultValue - The default value supplier if the configuration parameter is not set or is null.
      Returns:
      The configuration parameter value as String
      Throws:
      ConfigException - If an error occurs retrieving the configuration property value
    • getBoolean

      default Boolean getBoolean(@NotBlank @NotBlank String key)
      Returns the value of the configuration parameter as Boolean.
      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

      default boolean getBoolean(@NotBlank @NotBlank String key, boolean defaultValue)
      Returns the value of the configuration parameter as Boolean.
      Parameters:
      key - The key of the configuration parameter
      defaultValue - The default value to return if the configuration parameter is not set or is null.
      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 as Boolean.
      Parameters:
      key - The key of the configuration parameter
      defaultValue - The default value supplier if the configuration parameter is not set or is null.
      Returns:
      The configuration parameter value as Boolean
      Throws:
      ConfigException - If an error occurs retrieving the configuration property value
    • getInteger

      default Integer getInteger(@NotNull @NotNull String key)
      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

      default int getInteger(@NotNull @NotNull String key, int defaultValue)
      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 is null.
      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 as Boolean.
      Parameters:
      key - The key of the configuration parameter
      defaultValue - The default value supplier if the configuration parameter is not set or is null.
      Returns:
      The configuration parameter value as Boolean
      Throws:
      ConfigException - If an error occurs retrieving the configuration property value
    • getLong

      default Long getLong(@NotNull @NotNull String key)
      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

      default long getLong(@NotNull @NotNull String key, long defaultValue)
      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 is null.
      Returns:
      The value configuration property, if any.
      Throws:
      NumberFormatException - If the configuration value cannot be parsed as an long.
    • getLong

      default Long getLong(@NotBlank @NotBlank String key, @NotNull @NotNull Supplier<Long> defaultValue)
      Returns the value of the configuration parameter as Boolean.
      Parameters:
      key - The key of the configuration parameter
      defaultValue - The default value supplier if the configuration parameter is not set or is null.
      Returns:
      The configuration parameter value as Boolean
      Throws:
      ConfigException - If an error occurs retrieving the configuration property value
    • as

      default <T extends Config> T as(@NotNull @NotNull Class<T> type)
      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

      @NotNull default @NotNull Config subset(@NotNull @NotNull String prefix)
      Creates a subset configuration containing only the properties with the specified prefix.
      Parameters:
      prefix - The prefix for configuration keys.
      Returns:
      The subset configuration.