public class ConfigurationContainer extends Object
Configuration objects and retrieves configuration
data seamlessly, by namespace and key.
The Configuration objects are sorted by precedence (from highest to lowest).
So, in case of key collision, the object with the highest precedence will be selected
first. The container may still select other lower-precedence Configuration
objects if a key is not found in the highest-precedence Configuration.
To create a new empty container, use the default constructor
new ConfigurationContainer(). To create a new container with preset
Configuration objects, pass them as "var-args".
Use the add(Configuration) method at any time to register new objects inside
the container.
To retrieve Configuration data, use any of the getter methods, specifying a
namespace and key.
Single-argument getter methods can be used to retrieve data from Configuration
objects that do not have a declared namespace. These methods may also retrieve data
from all Configuration objects if the selected data-fetch strategy is
LENIENT.
Each container may have a custom DataFetchStrategy and
NullValueProvider. Both objects may be specified at container construction time
and modified using the setter methods at anytime. If not specified, the container uses
the default objects configured via ConfectorySettings.
Configuration,
DataFetchStrategy| Constructor and Description |
|---|
ConfigurationContainer(Configuration<?>... configs)
Builds a new
ConfigurationContainer with an arbitrary number of preset
Configuration objects to be registered. |
ConfigurationContainer(DataFetchStrategy dataFetchStrategy,
Configuration<?>... configs)
Builds a new
ConfigurationContainer with a custom DataFetchStrategy and
an arbitrary number of preset Configuration objects. |
ConfigurationContainer(DataFetchStrategy dataFetchStrategy,
NullValueProvider nullValueProvider,
Configuration<?>... configs)
Builds a new
ConfigurationContainer with custom DataFetchStrategy and
NullValueProvider and an arbitrary number of preset Configuration
objects. |
ConfigurationContainer(NullValueProvider nullValueProvider,
Configuration<?>... configs)
Builds a new
ConfigurationContainer with a custom NullValueProvider and
an arbitrary number of preset Configuration objects. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(Configuration<?> configuration)
Adds the specified
Configuration to this container. |
void |
addAll(ConfigurationContainer source)
Copies all of the
Configuration objects from another container to this
container. |
void |
clear()
Removes all of the
Configuration objects from this container. |
boolean |
getBooleanProperty(String key)
Returns the
boolean value associated with the specified key in the
default namespace. |
boolean |
getBooleanProperty(String namespace,
String key)
Returns the
boolean value associated with the specified key in the
specified namespace. |
DataFetchStrategy |
getDataFetchStrategy()
Returns the
DataFetchStrategy associated with this container. |
double |
getDoubleProperty(String key)
Returns the
double value associated with the specified key in the
default namespace. |
double |
getDoubleProperty(String namespace,
String key)
Returns the
double value associated with the specified key in the
specified namespace. |
int |
getIntProperty(String key)
Returns the
int value associated with the specified key in the default
namespace. |
int |
getIntProperty(String namespace,
String key)
Returns the
int value associated with the specified key in the
specified namespace. |
long |
getLongProperty(String key)
Returns the
long value associated with the specified key in the default
namespace. |
long |
getLongProperty(String namespace,
String key)
Returns the
long value associated with the specified key in the
specified namespace. |
Collection<String> |
getNamespaces()
Returns all of the namespaces defined inside this container.
|
NullValueProvider |
getNullValueProvider()
Returns the
NullValueProvider associated with this container. |
String |
getStringProperty(String key)
Returns the
String value associated with the specified key in the
default namespace. |
String |
getStringProperty(String namespace,
String key)
Returns the
String value associated with the specified key in the
specified namespace. |
void |
setDataFetchStrategy(DataFetchStrategy strategy)
Defines a custom
DataFetchStrategy for this container. |
void |
setNullValueProvider(NullValueProvider provider)
Defines a custom
NullValueProvider for this container. |
long |
size(String namespace)
Returns the number of
Configuration objects associated with the specified
namespace in this container. |
public ConfigurationContainer(Configuration<?>... configs)
ConfigurationContainer with an arbitrary number of preset
Configuration objects to be registered.configs - an arbitrary number of Configuration objects (zero or more) to
be registered at constructor timepublic ConfigurationContainer(DataFetchStrategy dataFetchStrategy, Configuration<?>... configs)
ConfigurationContainer with a custom DataFetchStrategy and
an arbitrary number of preset Configuration objects.dataFetchStrategy - an optional DataFetchStrategy to be applied by this
container; null is allowed and means the default
strategy will be appliedconfigs - an arbitrary number of Configuration objects (zero or
more) to be registered at constructor timepublic ConfigurationContainer(NullValueProvider nullValueProvider, Configuration<?>... configs)
ConfigurationContainer with a custom NullValueProvider and
an arbitrary number of preset Configuration objects.nullValueProvider - an optional NullValueProvider to be used when keys are
not found; null is allowed and means the default
provider will be appliedconfigs - an arbitrary number of Configuration objects (zero or
more) to be registered at constructor timepublic ConfigurationContainer(DataFetchStrategy dataFetchStrategy, NullValueProvider nullValueProvider, Configuration<?>... configs)
ConfigurationContainer with custom DataFetchStrategy and
NullValueProvider and an arbitrary number of preset Configuration
objects.dataFetchStrategy - an optional DataFetchStrategy to be applied by this
container; null is allowed and means the default
strategy will be appliednullValueProvider - an optional NullValueProvider to be used when keys are
not found; null is allowed and means the default
provider will be appliedconfigs - an arbitrary number of Configuration objects (zero or
more) to be registered at constructor timepublic DataFetchStrategy getDataFetchStrategy()
DataFetchStrategy associated with this container.DataFetchStrategypublic void setDataFetchStrategy(DataFetchStrategy strategy)
DataFetchStrategy for this container.strategy - the DataFetchStrategy to set; not nullNullPointerException - if the specified strategy is nullpublic NullValueProvider getNullValueProvider()
NullValueProvider associated with this container.NullValueProvider instancepublic void setNullValueProvider(NullValueProvider provider)
NullValueProvider for this container.provider - the NullValueProvider to set; not nullNullPointerException - if the specified provider is nullpublic void add(Configuration<?> configuration)
Configuration to this container.configuration - the Configuration to be added to the containerpublic void addAll(ConfigurationContainer source)
Configuration objects from another container to this
container.source - the source container which Configuration objects are to be stored
in this container; null is allowedpublic void clear()
Configuration objects from this container.public boolean getBooleanProperty(String key)
boolean value associated with the specified key in the
default namespace.key - the property keyboolean value associated with the specified keypublic boolean getBooleanProperty(String namespace, String key)
boolean value associated with the specified key in the
specified namespace.namespace - the namespace to be usedkey - the property keyboolean value associated with the specified keypublic int getIntProperty(String key)
int value associated with the specified key in the default
namespace.key - the property keyint value associated with the specified keypublic int getIntProperty(String namespace, String key)
int value associated with the specified key in the
specified namespace.namespace - the namespace to be usedkey - the property keyint value associated with the specified keypublic long getLongProperty(String key)
long value associated with the specified key in the default
namespace.key - the property keylong value associated with the specified keypublic long getLongProperty(String namespace, String key)
long value associated with the specified key in the
specified namespace.namespace - the namespace to be usedkey - the property keylong value associated with the specified keypublic double getDoubleProperty(String key)
double value associated with the specified key in the
default namespace.key - the property keydouble value associated with the specified keypublic double getDoubleProperty(String namespace, String key)
double value associated with the specified key in the
specified namespace.namespace - the namespace to be usedkey - the property keydouble value associated with the specified keypublic String getStringProperty(String key)
String value associated with the specified key in the
default namespace.key - the property keyString value associated with the specified keypublic String getStringProperty(String namespace, String key)
String value associated with the specified key in the
specified namespace.namespace - the namespace to be usedkey - the property keyString value associated with the specified keypublic long size(String namespace)
Configuration objects associated with the specified
namespace in this container.namespace - the namespace to be testedConfiguration objects associated with the specified
namespacepublic Collection<String> getNamespaces()
Copyright © 2021. All rights reserved.