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 which may be specified at
container construction time and modified using the setter method anytime. If not
specified, the container uses the default choice configured via
ConfectorySettings.
IMPORTANT: This class works only with map-based Configuration
objects (e.g.: Properties, JSONObject, JsonNode, etc.). In
other words, only "container" objects which values can be accessed using either a key
or path expression (e.g. JSONPath). POJO-based Configuration objects
are not supported inside a the ConfigurationContainer.
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. |
| 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 |
getBoolean(String key)
Returns the
Boolean object associated with the specified key in the
default namespace (or in all namespaces depending on the DataFetchStrategy in
scope). |
Boolean |
getBoolean(String namespace,
String key)
Returns the
Boolean object associated with the specified key in the
specified namespace. |
DataFetchStrategy |
getDataFetchStrategy()
Returns the
DataFetchStrategy associated with this container. |
Double |
getDouble(String key)
Returns the
Double object associated with the specified key in the
default namespace (or in all namespaces depending on the DataFetchStrategy in
scope). |
Double |
getDouble(String namespace,
String key)
Returns the
Double object associated with the specified key in the
specified namespace. |
Integer |
getInteger(String key)
Returns the
Integer object associated with the specified key in the
default namespace (or in all namespaces depending on the DataFetchStrategy in
scope). |
Integer |
getInteger(String namespace,
String key)
Returns the
Integer object associated with the specified key in the
specified namespace. |
Long |
getLong(String key)
Returns the
Long object associated with the specified key in the
default namespace (or in all namespaces depending on the DataFetchStrategy in
scope). |
Long |
getLong(String namespace,
String key)
Returns the
Long object associated with the specified key in the
specified namespace. |
Collection<String> |
getNamespaces()
Returns all of the namespaces defined inside this container.
|
String |
getString(String key)
Returns the
String object associated with the specified key in the
default namespace (or in all namespaces depending on the DataFetchStrategy in
scope). |
String |
getString(String namespace,
String key)
Returns the
String object associated with the specified key in the
specified namespace. |
boolean |
isEmpty()
Returns
true if this container contains no Configuration objects. |
void |
setDataFetchStrategy(DataFetchStrategy strategy)
Defines a custom
DataFetchStrategy for this container. |
long |
size()
Returns the number of
Configuration objects in 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 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 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 getBoolean(String key)
Boolean object associated with the specified key in the
default namespace (or in all namespaces depending on the DataFetchStrategy in
scope).key - the object key (or path)Boolean object associated with the specified key;
null if not foundDataFetchStrategypublic Boolean getBoolean(String namespace, String key)
Boolean object associated with the specified key in the
specified namespace.namespace - the namespace to be usedkey - the object key (or path)Boolean object associated with the specified key;
null if not foundpublic Integer getInteger(String key)
Integer object associated with the specified key in the
default namespace (or in all namespaces depending on the DataFetchStrategy in
scope).key - the object key (or path)Integer object associated with the specified key;
null if not foundDataFetchStrategypublic Integer getInteger(String namespace, String key)
Integer object associated with the specified key in the
specified namespace.namespace - the namespace to be usedkey - the object key (or path)Integer object associated with the specified key;
null if not foundpublic Long getLong(String key)
Long object associated with the specified key in the
default namespace (or in all namespaces depending on the DataFetchStrategy in
scope).key - the object key (or path)Long object associated with the specified key; null
if not foundDataFetchStrategypublic Long getLong(String namespace, String key)
Long object associated with the specified key in the
specified namespace.namespace - the namespace to be usedkey - the object key (or path)Long object associated with the specified key; null
if not foundpublic Double getDouble(String key)
Double object associated with the specified key in the
default namespace (or in all namespaces depending on the DataFetchStrategy in
scope).key - the object key (or path)Double value associated with the specified key;
null if not foundDataFetchStrategypublic Double getDouble(String namespace, String key)
Double object associated with the specified key in the
specified namespace.namespace - the namespace to be usedkey - the object key (or path)Double object associated with the specified key;
null if not foundpublic String getString(String key)
String object associated with the specified key in the
default namespace (or in all namespaces depending on the DataFetchStrategy in
scope).key - the object key (or path)String object associated with the specified key;
null if not foundDataFetchStrategypublic String getString(String namespace, String key)
String object associated with the specified key in the
specified namespace.namespace - the namespace to be usedkey - the object key (or path)String object associated with the specified key;
null if not foundpublic long size()
Configuration objects in this container.Configuration objects in this containerpublic 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 boolean isEmpty()
true if this container contains no Configuration objects.true if this container contains no Configuration objectspublic Collection<String> getNamespaces()
Copyright © 2022. All rights reserved.