org.jjoost.util
Class Factories
java.lang.Object
org.jjoost.util.Factories
public class Factories
- extends java.lang.Object
A class providing methods acting on factories, and default factory implementations
- Author:
- b.elliottsmith
|
Nested Class Summary |
static class |
Factories.CastFactory<E>
A simple factory which wraps another factory (ordinarily a SimpleObjectFactory) and
(unsafely) casts the result to the type parameter provided. |
static class |
Factories.SimpleObjectFactory<E>
A simple factory that creates objects of the type of the class provided, providing it has an empty constructor |
|
Method Summary |
static
|
cast(Factory<E> factory)
Creates a factory which delegates to the provided factory and (unsafely) casts its result to the type F |
static
|
forClass(java.lang.Class<E> clazz)
Returns a new SimpleObjectFactory which constructs objects of type clazz with its no-args constructor |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Factories
public Factories()
forClass
public static <E> Factory<E> forClass(java.lang.Class<E> clazz)
throws java.lang.SecurityException,
java.lang.NoSuchMethodException,
java.lang.InstantiationException,
java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException
- Returns a new
SimpleObjectFactory which constructs objects of type clazz with its no-args constructor
- Parameters:
clazz - the type of object to create
- Returns:
- a new
SimpleObjectFactory which constructs objects of type clazz with its no-args constructor
- Throws:
java.lang.SecurityException - if clazz.getConstructor throws a SecurityException
java.lang.NoSuchMethodException - if a matching constructor is not found
java.lang.InstantiationException - if an object cannot be constructed using the found constructor
java.lang.IllegalAccessException - if the constructor's access is restricted
java.lang.reflect.InvocationTargetException - if the constructor throws an exception
cast
public static <E,F> Factory<F> cast(Factory<E> factory)
- Creates a factory which delegates to the provided factory and (unsafely) casts its result to the type
F
- Type Parameters:
E - type of provided factoryF - type to unsafely cast to- Parameters:
factory - factory to delegate to
- Returns: