Class TypeSafeConfigurationContainer<T>


  • public final class TypeSafeConfigurationContainer<T>
    extends Object
    An object that holds multiple 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.

    Since:
    1.0.0
    Author:
    oswaldo.bapvic.jr (Oswaldo Junior)
    See Also:
    Configuration, ConfigurationContainer, DataFetchStrategy
    • Constructor Detail

      • TypeSafeConfigurationContainer

        @SafeVarargs
        public TypeSafeConfigurationContainer​(Configuration<T>... configs)
        Builds a new TypeSafeConfigurationContainer with an arbitrary number of preset Configuration objects to be registered.
        Parameters:
        configs - an arbitrary number of Configuration objects (zero or more) to be registered at constructor time
      • TypeSafeConfigurationContainer

        @SafeVarargs
        public TypeSafeConfigurationContainer​(DataFetchStrategy dataFetchStrategy,
                                              Configuration<?>... configs)
        Builds a new TypeSageConfigurationContainer with a custom DataFetchStrategy and an arbitrary number of preset Configuration objects.
        Parameters:
        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 applied
        configs - an arbitrary number of Configuration objects (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 specified Configuration to this container.
        Parameters:
        configuration - the Configuration to be added to the container
      • clear

        public void clear()
        Removes all of the Configuration objects 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 null if 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 null if no bean available in the namespace
      • size

        public long size()
        Returns the number of Configuration objects in this container.
        Returns:
        the number of Configuration objects in this container
      • size

        public long size​(String namespace)
        Returns the number of Configuration objects associated with the specified namespace in this container.
        Parameters:
        namespace - the namespace to be tested
        Returns:
        the number of Configuration objects associated with the specified namespace
      • isEmpty

        public boolean isEmpty()
        Returns true if this container contains no Configuration objects.
        Returns:
        true if this container contains no Configuration objects