public class FactoryUtils
extends java.lang.Object
FactoryUtils
provides reference implementations and utilities
for the Factory functor interface. The supplied factories are:
Since v4.1 only factories which are considered to be unsafe are Serializable. Factories considered to be unsafe for serialization are:
Modifier and Type | Method and Description |
---|---|
static <T> Factory<T> |
constantFactory(T constantToReturn)
Creates a Factory that will return the same object each time the factory
is used.
|
static <T> Factory<T> |
exceptionFactory()
Gets a Factory that always throws an exception.
|
static <T> Factory<T> |
instantiateFactory(java.lang.Class<T> classToInstantiate)
Creates a Factory that can create objects of a specific type using
a no-args constructor.
|
static <T> Factory<T> |
instantiateFactory(java.lang.Class<T> classToInstantiate,
java.lang.Class<?>[] paramTypes,
java.lang.Object[] args)
Creates a Factory that can create objects of a specific type using
the arguments specified to this method.
|
static <T> Factory<T> |
nullFactory()
Gets a Factory that will return null each time the factory is used.
|
static <T> Factory<T> |
prototypeFactory(T prototype)
Creates a Factory that will return a clone of the same prototype object
each time the factory is used.
|
public static <T> Factory<T> exceptionFactory()
T
- the type that the factory createsExceptionFactory
public static <T> Factory<T> nullFactory()
T
- the "type" of null object the factory should return.ConstantFactory
public static <T> Factory<T> constantFactory(T constantToReturn)
T
- the type that the factory createsconstantToReturn
- the constant object to return each time in the factoryconstant
factory.ConstantFactory
public static <T> Factory<T> prototypeFactory(T prototype)
T
- the type that the factory createsprototype
- the object to clone each time in the factoryprototype
factory, or a ConstantFactory.NULL_INSTANCE
if
the prototype
is null
java.lang.IllegalArgumentException
- if the prototype cannot be clonedPrototypeFactory
public static <T> Factory<T> instantiateFactory(java.lang.Class<T> classToInstantiate)
T
- the type that the factory createsclassToInstantiate
- the Class to instantiate each time in the factoryreflection
factoryjava.lang.NullPointerException
- if the classToInstantiate is nullInstantiateFactory
public static <T> Factory<T> instantiateFactory(java.lang.Class<T> classToInstantiate, java.lang.Class<?>[] paramTypes, java.lang.Object[] args)
T
- the type that the factory createsclassToInstantiate
- the Class to instantiate each time in the factoryparamTypes
- parameter types for the constructor, can be nullargs
- the arguments to pass to the constructor, can be nullreflection
factoryjava.lang.NullPointerException
- if the classToInstantiate is nulljava.lang.IllegalArgumentException
- if the paramTypes and args don't matchjava.lang.IllegalArgumentException
- if the constructor doesn't existInstantiateFactory
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"