Class ObjectFactory<T>

  • Type Parameters:
    T - Type of class to instantiate

    public class ObjectFactory<T>
    extends Object
    Factory to create objects looking for the appropiate constructor
    Since:
    1.2.0
    Author:
    afarre
    • Constructor Detail

      • ObjectFactory

        protected ObjectFactory​(Class<T> _class)
      • ObjectFactory

        protected ObjectFactory​(Class<T> _class,
                                Object... _attributes)
    • Method Detail

      • getToInstantiate

        public Class<T> getToInstantiate()
        Returns the class to instantiate
        Returns:
        class to instantiate
      • getAttributes

        public List<Object> getAttributes()
        Attributes to use for instantiation
        Returns:
        List of attributes to use for instantiation
      • autobox

        protected Class autobox​(Class _class)
      • of

        public static final <TYPE> ObjectFactory<TYPE> of​(Class<TYPE> _class)
        Static method to retrieve object factory for the given class
        Type Parameters:
        TYPE - type of the object factory
        Parameters:
        _class - class to produce the factory
        Returns:
        ObjectFactory for this class
      • with

        public final ObjectFactory<T> with​(Object... _attributes)
        Attributes to use when instance the object
        Parameters:
        _attributes - attributes to use when instance the object
        Returns:
        an object factory from the current class and with the given attributes to use on instance
      • supplier

        public Supplier<Optional<T>> supplier()
        Returns the supplier for the class of this factory using, if provided, the attributes Note: this supplier throws an exception if an error occurs during instantiation
        Returns:
        Supplier for the current factory class
        See Also:
        Supplier