Package com.azure.core.util
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 Summary
Constructors Constructor Description ConfigurationPropertyBuilder(String name, Function<String,T> converter)ConstructsConfigurationPropertyBuilderinstance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ConfigurationPropertyBuilder<T>aliases(String... aliases)Sets one or more alias for property.ConfigurationProperty<T>build()Builds configuration property instance.ConfigurationPropertyBuilder<T>defaultValue(T defaultValue)Sets default property value.ConfigurationPropertyBuilder<T>environmentVariableName(String environmentVariableName)Sets environment variable name that can represent this property if explicit configuration is not set.ConfigurationPropertyBuilder<T>logValue(boolean logValue)Sets flag indicating if property value can be logged.static ConfigurationPropertyBuilder<Boolean>ofBoolean(String name)CreatesConfigurationPropertyBuilderconfigured to log property value and parse value usingBoolean.parseBoolean(String).static ConfigurationPropertyBuilder<Duration>ofDuration(String name)CreatesConfigurationPropertyBuilderconfigured to log property value and parses value as long number of milliseconds, proxyingNumberFormatExceptionexception.static ConfigurationPropertyBuilder<Integer>ofInteger(String name)CreatesConfigurationPropertyBuilderconfigured to log property value and parse value usingInteger.valueOf(String), proxyingNumberFormatExceptionexception.static ConfigurationPropertyBuilder<String>ofString(String name)Creates defaultConfigurationPropertyBuilder.ConfigurationPropertyBuilder<T>required(boolean required)Sets flag indicating if property is required.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.ConfigurationPropertyBuilder<T>systemPropertyName(String systemPropertyName)Sets system property name that can represent this property if explicit configuration is not set.
-
-
-
Constructor Detail
-
ConfigurationPropertyBuilder
public ConfigurationPropertyBuilder(String name, Function<String,T> converter)
ConstructsConfigurationPropertyBuilderinstance.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 toT.
-
-
Method Detail
-
ofString
public static ConfigurationPropertyBuilder<String> ofString(String name)
Creates defaultConfigurationPropertyBuilder. String property values are redacted in logs by default. If property value does not contain sensitive information, uselogValue(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)
CreatesConfigurationPropertyBuilderconfigured to log property value and parse value usingInteger.valueOf(String), proxyingNumberFormatExceptionexception.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)
CreatesConfigurationPropertyBuilderconfigured to log property value and parses value as long number of milliseconds, proxyingNumberFormatExceptionexception.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)
CreatesConfigurationPropertyBuilderconfigured to log property value and parse value usingBoolean.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.nullby default.- Parameters:
defaultValue- value to be returned byConfiguration.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 isfalse, indicating that property can only be provided in local configuration.- Parameters:
shared- If set totrue,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 isfalse, indicating that property value should not be logged. When and if retrieving of corresponding configuration property is logged,Configurationwill use "redacted" string instead of property value. If flag is set totrue, value is populated on the logs as is.- Parameters:
logValue- If set totrue,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 isfalse, indicating that property is optional.- Parameters:
required- If set totrue,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
nameoralias,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
nameoralias,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:
ConfigurationPropertyinstance.
-
-