Package net.obvj.confectory
Class TypeSafeConfigurationContainer<T>
- java.lang.Object
-
- net.obvj.confectory.TypeSafeConfigurationContainer<T>
-
public final class TypeSafeConfigurationContainer<T> extends Object
An object that holds multipleConfigurationobjects of the same generic type<T>and selects the highest-precedence available ones whengetBean()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 presetConfiguration<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
Configurationbean, use thegetBean()methods.- Since:
- 1.0.0
- Author:
- oswaldo.bapvic.jr (Oswaldo Junior)
- See Also:
Configuration,ConfigurationContainer,DataFetchStrategy
-
-
Constructor Summary
Constructors Constructor Description TypeSafeConfigurationContainer(Configuration<T>... configs)Builds a newTypeSafeConfigurationContainerwith an arbitrary number of presetConfigurationobjects to be registered.TypeSafeConfigurationContainer(DataFetchStrategy dataFetchStrategy, Configuration<?>... configs)Builds a newTypeSageConfigurationContainerwith a customDataFetchStrategyand an arbitrary number of presetConfigurationobjects.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Configuration<T> configuration)Adds the specifiedConfigurationto this container.voidclear()Removes all of theConfigurationobjects from this container.TgetBean()Returns the highest-precedence mapped bean inside this container.TgetBean(String namespace)Returns the highest-precedence mapped bean associated with the specified namespace inside this container.booleanisEmpty()Returnstrueif this container contains noConfigurationobjects.longsize()Returns the number ofConfigurationobjects in this container.longsize(String namespace)Returns the number ofConfigurationobjects associated with the specifiednamespacein this container.
-
-
-
Constructor Detail
-
TypeSafeConfigurationContainer
@SafeVarargs public TypeSafeConfigurationContainer(Configuration<T>... configs)
Builds a newTypeSafeConfigurationContainerwith an arbitrary number of presetConfigurationobjects to be registered.- Parameters:
configs- an arbitrary number ofConfigurationobjects (zero or more) to be registered at constructor time
-
TypeSafeConfigurationContainer
@SafeVarargs public TypeSafeConfigurationContainer(DataFetchStrategy dataFetchStrategy, Configuration<?>... configs)
Builds a newTypeSageConfigurationContainerwith a customDataFetchStrategyand an arbitrary number of presetConfigurationobjects.- Parameters:
dataFetchStrategy- an optionalDataFetchStrategyto be applied by this container;nullis allowed and indicates that the default strategy defined inConfectory.settings()will be appliedconfigs- an arbitrary number ofConfigurationobjects (zero or more) to be registered at constructor time- Since:
- 2.4.0
- See Also:
ConfectorySettings
-
-
Method Detail
-
add
public void add(Configuration<T> configuration)
Adds the specifiedConfigurationto this container.- Parameters:
configuration- theConfigurationto be added to the container
-
clear
public void clear()
Removes all of theConfigurationobjects from this container.
-
getBean
public T getBean()
Returns the highest-precedence mapped bean inside this container.- Returns:
- the highest-precedence mapped bean inside this container, or
nullif no bean available
-
getBean
public T getBean(String namespace)
Returns the highest-precedence mapped bean associated with the specified namespace inside this container.- Parameters:
namespace- the namespace to query- Returns:
- the highest-precedence mapped bean associated with the specified namespace, or
nullif no bean available in the namespace
-
size
public long size()
Returns the number ofConfigurationobjects in this container.- Returns:
- the number of
Configurationobjects in this container
-
size
public long size(String namespace)
Returns the number ofConfigurationobjects associated with the specifiednamespacein this container.- Parameters:
namespace- the namespace to be tested- Returns:
- the number of
Configurationobjects associated with the specifiednamespace
-
isEmpty
public boolean isEmpty()
Returnstrueif this container contains noConfigurationobjects.- Returns:
trueif this container contains noConfigurationobjects
-
-