public final class TypeSafeConfigurationContainer<T> extends Object
Configuration objects of the same generic type
<T> and selects the highest-precedence available ones when getBean() is
called. This is particularly useful for source prioritization or handling multiple
versions of the same configuration bean.
To create a new empty container, use the default constructor
new TypeSafeConfigurationContainer<T>(). To create a new container with preset
Configuration<T> objects, pass them as "var-args", provided that all objects
have the same mapped bean type <T>
Use the add(Configuration<T>) method at any time to register new objects inside
the container.
To retrieve the highest-precedence Configuration bean, use the
getBean() methods.
Configuration,
ConfigurationContainer,
DataFetchStrategy| Constructor and Description |
|---|
TypeSafeConfigurationContainer(Configuration<T>... configs)
Builds a new
TypeSafeConfigurationContainer with an arbitrary number of preset
Configuration objects to be registered. |
TypeSafeConfigurationContainer(DataFetchStrategy dataFetchStrategy,
Configuration<?>... configs)
Builds a new
TypeSageConfigurationContainer with a custom
DataFetchStrategy and an arbitrary number of preset Configuration
objects. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(Configuration<T> configuration)
Adds the specified
Configuration to this container. |
void |
clear()
Removes all of the
Configuration objects from this container. |
T |
getBean()
Returns the highest-precedence mapped bean inside this container.
|
T |
getBean(String namespace)
Returns the highest-precedence mapped bean associated with the specified namespace
inside this container.
|
boolean |
isEmpty()
Returns
true if this container contains no Configuration objects. |
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. |
@SafeVarargs public TypeSafeConfigurationContainer(Configuration<T>... configs)
TypeSafeConfigurationContainer 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 time@SafeVarargs public TypeSafeConfigurationContainer(DataFetchStrategy dataFetchStrategy, Configuration<?>... configs)
TypeSageConfigurationContainer 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 indicates that the
default strategy defined in Confectory.settings() will
be appliedconfigs - an arbitrary number of Configuration objects (zero or
more) to be registered at constructor timeConfectorySettingspublic void add(Configuration<T> configuration)
Configuration to this container.configuration - the Configuration to be added to the containerpublic void clear()
Configuration objects from this container.public T getBean()
null if no
bean availablepublic T getBean(String namespace)
namespace - the namespace to querynull if no bean available in the namespacepublic 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 objectsCopyright © 2023. All rights reserved.