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 Details

    • fromEnvironmentVariables

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

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

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

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

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

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

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

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

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

      static <T extends Config> T as(Config config, 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 @Nullable 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(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

      default 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

      default Stream<String> getKeys(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

      default Stream<String> getKeys(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

      @Nullable String get(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 @Nullable String getUndecored(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 @Nullable String get(String key, @Nullable 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 @Nullable String get(String key, Supplier<@Nullable 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 @Nullable Boolean getBoolean(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(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 @Nullable Boolean getBoolean(String key, Supplier<@Nullable 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 @Nullable Integer getInteger(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(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 @Nullable Integer getInteger(String key, Supplier<@Nullable 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 @Nullable Long getLong(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(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 @Nullable Long getLong(String key, Supplier<@Nullable 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(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

      default Config subset(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.