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 protectedObjectFactory(Class<T> _class)protectedObjectFactory(Class<T> _class, Object... _attributes)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Classautobox(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
-
-