T - the target configuration typepublic class ConfigurationBuilder<T> extends Object implements ConfigurationMetadataRetriever<T>
Configuration objects.
For example:
Configuration<Properties> config = new ConfigurationBuilder<Properties>().source(new ClasspathFileSource<>("my.properties")).mapper(new PropertiesMapper()).namespace("my-properties").precedence(10).build();
Configuration| Constructor and Description |
|---|
ConfigurationBuilder()
Creates a new, empty
ConfigurationBuilder. |
ConfigurationBuilder(Configuration<T> sourceConfiguration)
Creates a new
ConfigurationBuilder filled with the attributes of an existing
base Configuration. |
| Modifier and Type | Method and Description |
|---|---|
Configuration<T> |
build()
Builds the target
Configuration. |
Mapper<T> |
getMapper()
Returns the
Mapper object associated with this Configuration. |
String |
getNamespace()
Returns the namespace defined for this
Configuration object. |
NullValueProvider |
getNullValueProvider()
Returns the
NullValueProvider associated with this Configuration. |
int |
getPrecedence()
Returns the precedence value defined for this
Configuration object. |
Source<T> |
getSource()
Returns the
Source object associated with this Configuration. |
boolean |
isOptional()
Returns a flag indicating whether this
Configuration is optional. |
ConfigurationBuilder<T> |
mapper(Mapper<T> mapper)
Defines the
Mapper of the new Configuration. |
ConfigurationBuilder<T> |
namespace(String namespace)
Declares a namespace to be assigned to the new
Configuration object. |
ConfigurationBuilder<T> |
nullValueProvider(NullValueProvider provider)
Defines an optional
NullValueProvider to be used when keys are not found. |
ConfigurationBuilder<T> |
optional()
Marks the new
Configuration as optional. |
ConfigurationBuilder<T> |
precedence(int precedence)
Defines the level of precedence of the new
Configuration compared to similar
objects in the same namespace. |
ConfigurationBuilder<T> |
required()
Marks the new
Configuration as required (default). |
ConfigurationBuilder<T> |
source(Source<T> source)
Defines the
Source of the new Configuration. |
ConfigurationBuilder<T> |
source(String path)
Defines a
DynamicSource with the specified path for the new
Configuration. |
public ConfigurationBuilder()
ConfigurationBuilder.public ConfigurationBuilder(Configuration<T> sourceConfiguration)
ConfigurationBuilder filled with the attributes of an existing
base Configuration.sourceConfiguration - a preset Configuration object whose attributes are
to be copied; null is allowedpublic ConfigurationBuilder<T> namespace(String namespace)
Configuration object.
Note: The namespace is optional, but usually recommended to organize the scope of the target object and to prevent key collisions.
namespace - the namespace to set; null is allowedConfigurationBuilder for chained callspublic ConfigurationBuilder<T> precedence(int precedence)
Configuration compared to similar
objects in the same namespace.
In a common configuration container, the object with the highest precedence level may be selected first in the occurrence of a key collision in the same namespace.
Note: This precedence value is optional and the default value is
0 (zero).
precedence - an integer number representing the order of importance given to the
target configurationConfigurationBuilder for chained callspublic ConfigurationBuilder<T> source(Source<T> source)
Source of the new Configuration.source - the Source to be set; not nullConfigurationBuilder for chained callspublic ConfigurationBuilder<T> source(String path)
DynamicSource with the specified path for the new
Configuration.path - the path to be set; not nullConfigurationBuilder for chained callspublic ConfigurationBuilder<T> mapper(Mapper<T> mapper)
Mapper of the new Configuration.mapper - the Mapper to be set; not nullConfigurationBuilder for chained callspublic ConfigurationBuilder<T> optional()
Configuration as optional.
The configuration source will be loaded quietly, i.e., not throwing an exception if the source is not found or not loaded successfully.
ConfigurationBuilder for chained callspublic ConfigurationBuilder<T> required()
Configuration as required (default).ConfigurationBuilder for chained callspublic ConfigurationBuilder<T> nullValueProvider(NullValueProvider provider)
NullValueProvider to be used when keys are not found.
Note: This setting is optional and a default object will be applied if no custom provider is specified.
provider - the provider to set; null is allowedConfigurationBuilder for chained callspublic Configuration<T> build()
Configuration.Configuration objectNullPointerException - if either the Source or Mapper
configuration parameters are missingConfigurationSourceException - in the event of a failure loading the
configuration sourcepublic String getNamespace()
ConfigurationMetadataRetrieverConfiguration object.getNamespace in interface ConfigurationMetadataRetriever<T>Configurationpublic int getPrecedence()
ConfigurationMetadataRetrieverConfiguration object.
In a common container, objects with higher-precedence may be selected first in case of key collision.
getPrecedence in interface ConfigurationMetadataRetriever<T>Configurationpublic Source<T> getSource()
ConfigurationMetadataRetrieverSource object associated with this Configuration.getSource in interface ConfigurationMetadataRetriever<T>Source instancepublic Mapper<T> getMapper()
ConfigurationMetadataRetrieverMapper object associated with this Configuration.getMapper in interface ConfigurationMetadataRetriever<T>Mapper instancepublic boolean isOptional()
ConfigurationMetadataRetrieverConfiguration is optional.
An optional Configuration object may behave quietly in the event of a failure
to load the data.
isOptional in interface ConfigurationMetadataRetriever<T>true if this Configuration setup is optional; false,
otherwisepublic NullValueProvider getNullValueProvider()
ConfigurationMetadataRetrieverNullValueProvider associated with this Configuration.getNullValueProvider in interface ConfigurationMetadataRetriever<T>NullValueProvider instanceCopyright © 2021. All rights reserved.