Package io.pravega.common.util
Class ConfigBuilder<T>
- java.lang.Object
-
- io.pravega.common.util.ConfigBuilder<T>
-
- Type Parameters:
T- Type of the configuration.
public class ConfigBuilder<T> extends java.lang.ObjectA builder for a generic Property-based configuration.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceConfigBuilder.ConfigConstructor<R>
-
Constructor Summary
Constructors Constructor Description ConfigBuilder(java.lang.String namespace, ConfigBuilder.ConfigConstructor<T> constructor)Creates a new instance of the ConfigBuilder class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tbuild()Creates a new instance of the given Configuration class as defined by this builder with the information contained herein.voidcopyTo(java.util.Map<java.lang.Object,java.lang.Object> target)Copies the contents of this builder to the given target.ConfigBuilder<T>rebase(java.util.Properties properties)Creates a new instance of the ConfigBuilder class that uses the given java.util.Properties object as a base.<V> ConfigBuilder<T>with(Property<V> property, V value)Includes the given property and its value in the builder.ConfigBuilder<T>withUnsafe(Property<?> property, java.lang.Object value)Includes the given property and its value in the builder, without Property-Value type-enforcement.
-
-
-
Constructor Detail
-
ConfigBuilder
public ConfigBuilder(java.lang.String namespace, ConfigBuilder.ConfigConstructor<T> constructor)Creates a new instance of the ConfigBuilder class.- Parameters:
namespace- The configuration namespace to use.constructor- A Function that, given a TypedProperties object, returns a new instance of T using the given property values.
-
-
Method Detail
-
rebase
public ConfigBuilder<T> rebase(java.util.Properties properties)
Creates a new instance of the ConfigBuilder class that uses the given java.util.Properties object as a base. This method does not touch the current instance.- Parameters:
properties- A java.util.Properties object to wrap.- Returns:
- A new instance of the ConfigBuilder class with the same arguments as the current one, except that it uses the given Properties object.
-
with
public <V> ConfigBuilder<T> with(Property<V> property, V value)
Includes the given property and its value in the builder.- Type Parameters:
V- Type of the property.- Parameters:
property- The property to set.value- The value of the property. This must be of the same type as accepted by the Property. In case a `null` value is sent, the value of the property will be set to empty string.- Returns:
- This instance.
-
withUnsafe
public ConfigBuilder<T> withUnsafe(Property<?> property, java.lang.Object value)
Includes the given property and its value in the builder, without Property-Value type-enforcement.- Parameters:
property- The property to set.value- The value of the property.- Returns:
- This instance.
-
copyTo
public void copyTo(java.util.Map<java.lang.Object,java.lang.Object> target)
Copies the contents of this builder to the given target.- Parameters:
target- A Map to copy to.
-
build
public T build() throws ConfigurationException
Creates a new instance of the given Configuration class as defined by this builder with the information contained herein.- Returns:
- The newly created instance.
- Throws:
ConfigurationException- When a configuration issue has been detected. This can be: MissingPropertyException (a required Property is missing from the given properties collection), NumberFormatException (a Property has a value that is invalid for it).java.lang.NullPointerException- If any of the arguments are null.java.lang.IllegalArgumentException- If namespace is an empty string..
-
-