Class ConfigurationPropertyBuilder<T>

java.lang.Object
com.azure.core.util.ConfigurationPropertyBuilder<T>
Type Parameters:
T - The property value type.

public final class ConfigurationPropertyBuilder<T> extends Object
Builds configuration property.
  • Constructor Details

    • ConfigurationPropertyBuilder

      public ConfigurationPropertyBuilder(String name, Function<String,T> converter)
      Constructs ConfigurationPropertyBuilder instance.
       ConfigurationProperty<SampleEnumProperty> modeProperty =
           new ConfigurationPropertyBuilder<>("mode", SampleEnumProperty::fromString)
               .logValue(true)
               .defaultValue(SampleEnumProperty.MODE_1)
               .build();
       System.out.println(configuration.get(modeProperty));
       
      Parameters:
      name - name of the property.
      converter - Converter used to map the configuration to T.
  • Method Details

    • ofString

      public static ConfigurationPropertyBuilder<String> ofString(String name)
      Creates default ConfigurationPropertyBuilder. String property values are redacted in logs by default. If property value does not contain sensitive information, use logValue(boolean) to enable logging.
       ConfigurationProperty<String> property = ConfigurationPropertyBuilder.ofString("http.proxy.hostname")
           .shared(true)
           .logValue(true)
           .systemPropertyName("http.proxyHost")
           .build();
      
       // attempts to get local `azure.sdk.<client-name>.http.proxy.host` property and falls back to
       // shared azure.sdk.http.proxy.port
       System.out.println(configuration.get(property));
       
      Parameters:
      name - property name.
      Returns:
      instance of ConfigurationPropertyBuilder.
    • ofInteger

      public static ConfigurationPropertyBuilder<Integer> ofInteger(String name)
      Creates ConfigurationPropertyBuilder configured to log property value and parse value using Integer.valueOf(String), proxying NumberFormatException exception.
       ConfigurationProperty<Integer> integerProperty = ConfigurationPropertyBuilder.ofInteger("retry-count")
           .build();
       System.out.println(configuration.get(integerProperty));
       
      Parameters:
      name - property name.
      Returns:
      instance of ConfigurationPropertyBuilder.
    • ofDuration

      public static ConfigurationPropertyBuilder<Duration> ofDuration(String name)
      Creates ConfigurationPropertyBuilder configured to log property value and parses value as long number of milliseconds, proxying NumberFormatException exception.
       ConfigurationProperty<Duration> timeoutProperty = ConfigurationPropertyBuilder.ofDuration("timeout")
           .build();
       System.out.println(configuration.get(timeoutProperty));
       
      Parameters:
      name - property name.
      Returns:
      instance of ConfigurationPropertyBuilder.
    • ofBoolean

      public static ConfigurationPropertyBuilder<Boolean> ofBoolean(String name)
      Creates ConfigurationPropertyBuilder configured to log property value and parse value using Boolean.parseBoolean(String).
       ConfigurationProperty<Boolean> booleanProperty = ConfigurationPropertyBuilder.ofBoolean("is-enabled")
           .build();
       System.out.println(configuration.get(booleanProperty));
       
      Parameters:
      name - property name.
      Returns:
      instance of ConfigurationPropertyBuilder.
    • defaultValue

      public ConfigurationPropertyBuilder<T> defaultValue(T defaultValue)
      Sets default property value. null by default.
      Parameters:
      defaultValue - value to be returned by Configuration.get(ConfigurationProperty) if the property isn't found.
      Returns:
      the updated ConfigurationPropertyBuilder object.
    • shared

      public ConfigurationPropertyBuilder<T> shared(boolean shared)
      Sets flag indicating that property can be provided in the shared configuration section in addition to client-specific configuration section. Default is false, indicating that property can only be provided in local configuration.
      Parameters:
      shared - If set to true, Configuration.get(ConfigurationProperty) will attempt to retrieve property from local configuration and fall back to shared section, when local property is missing. Otherwise, only local configuration will be checked.
      Returns:
      the updated ConfigurationPropertyBuilder object.
    • logValue

      public ConfigurationPropertyBuilder<T> logValue(boolean logValue)
      Sets flag indicating if property value can be logged. Default is false, indicating that property value should not be logged. When and if retrieving of corresponding configuration property is logged, Configuration will use "redacted" string instead of property value. If flag is set to true, value is populated on the logs as is.
      Parameters:
      logValue - If set to true, Configuration.get(ConfigurationProperty) will log property value, Otherwise, value is redacted.
      Returns:
      the updated ConfigurationPropertyBuilder object.
    • required

      public ConfigurationPropertyBuilder<T> required(boolean required)
      Sets flag indicating if property is required. Default is false, indicating that property is optional.
      Parameters:
      required - If set to true, Configuration.get(ConfigurationProperty) will throw when property is not found.
      Returns:
      the updated ConfigurationPropertyBuilder object.
    • aliases

      public ConfigurationPropertyBuilder<T> aliases(String... aliases)
      Sets one or more alias for property. Configuration.get(ConfigurationProperty) attempts to retrieve property by name first and only then tries to retrieve properties by alias in the order aliases are provided.
      Parameters:
      aliases - one or more alias for the property name.
      Returns:
      the updated ConfigurationPropertyBuilder object.
    • environmentVariableName

      public ConfigurationPropertyBuilder<T> environmentVariableName(String environmentVariableName)
      Sets environment variable name that can represent this property if explicit configuration is not set.

      When property value is not found by name or alias, Configuration.get(ConfigurationProperty) falls back to system properties and environment variables. When environment variable (or system property) is not set, Configuration.get(ConfigurationProperty) does not attempt to read environment configuration.

      Parameters:
      environmentVariableName - environment variable name.
      Returns:
      the updated ConfigurationPropertyBuilder object.
    • systemPropertyName

      public ConfigurationPropertyBuilder<T> systemPropertyName(String systemPropertyName)
      Sets system property name that can represent this property if explicit configuration is not set.

      When property value is not found by name or alias, Configuration.get(ConfigurationProperty) falls back to system properties and environment variables. When environment variable (or system property) is not set, Configuration.get(ConfigurationProperty) does not attempt to read environment configuration.

      Parameters:
      systemPropertyName - one or more environment variable (or system property).
      Returns:
      the updated ConfigurationPropertyBuilder object.
    • build

      public ConfigurationProperty<T> build()
      Builds configuration property instance.
      Returns:
      ConfigurationProperty instance.