Class ObjectFactory<T>
- java.lang.Object
-
- org.bytemechanics.commons.reflection.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 Summary
Constructors Modifier Constructor Description protected
ObjectFactory(Class<T> _class)
protected
ObjectFactory(Class<T> _class, Object... _attributes)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Class
autobox(Class _class)
protected <T> Optional<Constructor<T>>
findConstructor()
List<Object>
getAttributes()
Attributes to use for instantiationClass<T>
getToInstantiate()
Returns the class to instantiatestatic <TYPE> ObjectFactory<TYPE>
of(Class<TYPE> _class)
Static method to retrieve object factory for the given classSupplier<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 instantiationObjectFactory<T>
with(Object... _attributes)
Attributes to use when instance the object
-
-
-
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
-
findConstructor
protected <T> Optional<Constructor<T>> findConstructor()
-
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
-
-