Class Config

java.lang.Object
com.helger.config.Config
All Implemented Interfaces:
IConfig, com.helger.typeconvert.trait.IGetterByKeyTrait<String>
Direct Known Subclasses:
ConfigWithFallback

public class Config extends Object implements IConfig
Default implementation of IConfig. It is recommended to use ConfigFactory for accessing IConfig objects.
Author:
Philip Helger
  • Field Details

    • DEFAULT_REPLACE_VARIABLES

      public static final boolean DEFAULT_REPLACE_VARIABLES
      For backwards compatibility reason, variable replacement is enabled by default since v11.0.2.
      See Also:
    • DEFAULT_USE_VARIABLE_DEFAULT_VALUES

      public static final boolean DEFAULT_USE_VARIABLE_DEFAULT_VALUES
      By default the usage of variable default is allowed. Since 11.1.11
      See Also:
    • DEFAULT_UNRESOLVED_VARIABLE_PROVIDER

      public static final UnaryOperator<String> DEFAULT_UNRESOLVED_VARIABLE_PROVIDER
  • Constructor Details

    • Config

      public Config(@Nonnull IConfigurationValueProvider aValueProvider)
      Constructor
      Parameters:
      aValueProvider - The main configuration value provider. May not be null.
  • Method Details

    • getConfigurationValueProvider

      @Nonnull public final IConfigurationValueProvider getConfigurationValueProvider()
      Returns:
      The configuration value provider as provided in the constructor. Never null.
    • getFoundKeyConsumer

      @Nullable public final BiConsumer<String,ConfiguredValue> getFoundKeyConsumer()
      Returns:
      The callback to be invoked if a configuration value was found. May be null.
    • setFoundKeyConsumer

      @Nullable public final Config setFoundKeyConsumer(@Nullable BiConsumer<String,ConfiguredValue> aKeyFoundConsumer)
      Parameters:
      aKeyFoundConsumer - The callback to be invoked if a configuration value was found. The parameters are key and value. May be null.
      Returns:
      this for chaining
      Since:
      9.4.5
    • getKeyNotFoundConsumer

      @Nullable public final Consumer<String> getKeyNotFoundConsumer()
      Returns:
      The callback to be invoked if a configuration value was not found. May be null.
    • setKeyNotFoundConsumer

      @Nullable public final Config setKeyNotFoundConsumer(@Nullable Consumer<String> aKeyNotFoundConsumer)
      Parameters:
      aKeyNotFoundConsumer - The callback to be invoked if a configuration value was not found. The parameter is the key. May be null.
      Returns:
      this for chaining
      Since:
      9.4.5
    • isReplaceVariables

      public final boolean isReplaceVariables()
      Returns:
      true if variables in configuration properties should be replaced, false if not. The default value is true.
      Since:
      10.2.0
    • setReplaceVariables

      @Nonnull public final Config setReplaceVariables(boolean bReplaceVariables)
      Enable or disable the replacement of variables in configuration values.
      Parameters:
      bReplaceVariables - true to enable replacement, false to disable it.
      Returns:
      this for chaining
      Since:
      10.2.0
    • isUseVariableDefaultValues

      public final boolean isUseVariableDefaultValues()
      Returns:
      true if variables are allowed to have default values in the form ${variable:default}, false if not. The default value is true.
      Since:
      11.1.1
    • setUseVariableDefaultValues

      @Nonnull public final Config setUseVariableDefaultValues(boolean bUseVariableDefaultValues)
      Enable or disable the usage of default values in variables of configuration values.
      Parameters:
      bUseVariableDefaultValues - true to allow the usage, false to disable it.
      Returns:
      this for chaining
      Since:
      11.1.1
    • getUnresolvedVariableProvider

      @Nonnull public final UnaryOperator<String> getUnresolvedVariableProvider()
      Returns:
      The unresolved variable provider to be used. Never null.
    • setUnresolvedVariableProvider

      @Nonnull public final Config setUnresolvedVariableProvider(@Nonnull UnaryOperator<String> aUnresolvedVariableProvider)
      Set the handler to be invoked when a variable could not be resolved.
      Parameters:
      aUnresolvedVariableProvider - The unresolved variable provider to be used. May not be null.
      Returns:
      this for chaining
      Since:
      10.2.0
    • getConfiguredValue

      @Nullable public ConfiguredValue getConfiguredValue(@Nullable String sKey)
      Description copied from interface: IConfig
      Get the configured value, which is the combination of the matching configuration source and the value, for the provided key.
      Specified by:
      getConfiguredValue in interface IConfig
      Parameters:
      sKey - The configuration key to look up.
      Returns:
      null if no such configuration value is available.
    • getValue

      @Nullable public String getValue(@Nullable String sKey)
      Specified by:
      getValue in interface com.helger.typeconvert.trait.IGetterByKeyTrait<String>
    • forEachConfigurationValueProviderRecursive

      public static void forEachConfigurationValueProviderRecursive(@Nonnull IConfigurationValueProvider aValueProvider, @Nonnull IConfigurationValueProviderWithPriorityCallback aCallback)
    • forEachConfigurationValueProvider

      public void forEachConfigurationValueProvider(@Nonnull IConfigurationValueProviderWithPriorityCallback aCallback)
      Description copied from interface: IConfig
      Enumerate all contained configuration value provider. All items will be enumerated in the order they are checked, so the ones with highest priority first.
      Specified by:
      forEachConfigurationValueProvider in interface IConfig
      Parameters:
      aCallback - The callback to invoked. May not be null.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • create

      @Nonnull public static Config create(@Nonnull IConfigurationValueProvider aCVP)