T - the target configuration typepublic final class Configuration<T> extends Object implements ConfigurationDataRetriever<T>, ConfigurationMetadataRetriever<T>
A Configuration may also be defined as a combination of a Source and a
Mapper, producing either a properties list, a JSON object, or a user-defined
bean.
Each Configuration may be assigned a namespace and precedence number, which
determines an order of importance. So, once stored in a common configuration container,
the object with the highest precedence value will be chosen first, taking precedence
over the other ones in the same namespace.
A Configuration may also be optional, which means that the configuration will
be loaded quietly.
Note: Use a ConfigurationBuilder to create a
Configuration object. A builder instance can be retrieved by calling
builder(). For example:
Configuration<Properties> config = Configuration.<Properties>builder().source(new ClasspathFileSource<>("my.properties")).mapper(new PropertiesMapper()).namespace("my-properties").precedence(10).build();
Source,
Mapper,
ConfigurationBuilder| Modifier and Type | Method and Description |
|---|---|
static <T> ConfigurationBuilder<T> |
builder()
Creates a new configuration builder.
|
boolean |
equals(Object other)
Indicates whether some other object is "equal to" this one.
|
Optional<T> |
getBean()
Returns the target configuration object used by this data retriever, typically for
manual handling and/or troubleshooting purposes.
|
boolean |
getBoolean(String key)
Returns the
boolean value associated with the specified key. |
double |
getDouble(String key)
Returns the
double value associated with the specified key. |
ConfigurationHelper<T> |
getHelper()
Returns the
ConfigurationHelper associated with this Configuration. |
int |
getInt(String key)
Returns the
int value associated with the specified key. |
long |
getLong(String key)
Returns the
long value associated with the specified key. |
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. |
String |
getString(String key)
Returns the
String value associated with the specified key. |
int |
hashCode() |
boolean |
isOptional()
Returns a flag indicating whether this
Configuration is optional. |
String |
toString() |
public static <T> ConfigurationBuilder<T> builder()
T - the target configuration typeConfigurationBuilderpublic 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 instancepublic ConfigurationHelper<T> getHelper()
ConfigurationHelper associated with this Configuration.ConfigurationHelperpublic Optional<T> getBean()
ConfigurationDataRetrievergetBean in interface ConfigurationDataRetriever<T>Optional, possibly containing the target configuration objectpublic boolean getBoolean(String key)
ConfigurationDataRetrieverboolean value associated with the specified key.getBoolean in interface ConfigurationDataRetriever<T>key - the property keyboolean value associated with the specified keypublic int getInt(String key)
ConfigurationDataRetrieverint value associated with the specified key.getInt in interface ConfigurationDataRetriever<T>key - the property keyint value associated with the specified keypublic long getLong(String key)
ConfigurationDataRetrieverlong value associated with the specified key.getLong in interface ConfigurationDataRetriever<T>key - the property keylong value associated with the specified keypublic double getDouble(String key)
ConfigurationDataRetrieverdouble value associated with the specified key.getDouble in interface ConfigurationDataRetriever<T>key - the property keydouble value associated with the specified keypublic String getString(String key)
ConfigurationDataRetrieverString value associated with the specified key.getString in interface ConfigurationDataRetriever<T>key - the property keyString value associated with the specified keypublic boolean equals(Object other)
Two Configuration objects can be considered equal if both share the same
namespace and Source.
Copyright © 2021. All rights reserved.