public class Factory<T> extends TreeMap<Class<?>[],Member>
Factory
base class.AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Modifier | Constructor and Description |
---|---|
|
Factory(Class<? extends T> type)
Sole public constructor.
|
protected |
Factory(Class<? extends T> type,
Object factory)
Construct a
Factory by wrapping a factory instance. |
Modifier and Type | Method and Description |
---|---|
T |
apply(Member member,
Object... arguments)
Method to apply a factory
Member (factory Method ,
static Method , or Constructor ) to manufacture or get
an Object . |
Member |
get(Object key) |
Object |
getFactory()
Method to get the underlying factory
Object . |
Member |
getFactoryMethod(Class<?>... parameters)
Method to get a factory
Member (factory Method ,
static Method , or Constructor ) to manufacture or get
an Object . |
T |
getInstance(Class<?>[] parameters,
Object... arguments)
Method to get an
Object instance. |
T |
getInstance(Object... arguments)
Method to get an
Object instance. |
Class<? extends T> |
getType()
|
boolean |
hasFactoryMethodFor(Class<?>... parameters)
Method to determine if there is a factory
Member (factory
Method , static Method , or Constructor ) to
manufacture or get an Object . |
protected static boolean |
isApplicable(Class<?>[] parameters,
Class<?>... arguments)
Method to determine if an argument of the specified types may be
applied to a method or constructor with the specified parameters.
|
protected static Class<?>[] |
typesOf(Object... arguments)
Convenience method to get the types of an argument array.
|
ceilingEntry, ceilingKey, clear, clone, comparator, containsKey, containsValue, descendingKeySet, descendingMap, entrySet, firstEntry, firstKey, floorEntry, floorKey, forEach, headMap, headMap, higherEntry, higherKey, keySet, lastEntry, lastKey, lowerEntry, lowerKey, navigableKeySet, pollFirstEntry, pollLastEntry, put, putAll, remove, replace, replace, replaceAll, size, subMap, subMap, tailMap, tailMap, values
equals, hashCode, isEmpty, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, equals, getOrDefault, hashCode, isEmpty, merge, putIfAbsent, remove
@ConstructorProperties(value="type") public Factory(Class<? extends T> type)
type
- The Class
of Object
this
Factory
will produce.NullPointerException
- If type
is null
.@ConstructorProperties(value={"type","factory"}) protected Factory(Class<? extends T> type, Object factory)
Factory
by wrapping a factory instance.type
- The Class
of Object
this
Factory
will produce.factory
- An Object
factory for this
type
(may be null
).NullPointerException
- If type
is null
.public Object getFactory()
Object
.Object
or null
if
there is none.public T getInstance(Class<?>[] parameters, Object... arguments) throws IllegalAccessException, IllegalArgumentException, InstantiationException, InvocationTargetException, NoSuchMethodException
Object
instance. This method will first
attempt to find and invoke a static factory method. If no factory
method is found, it will then attempt to construct a new instance.parameters
- The parameter types to use to search for the
Object
static factory method or
constructor.arguments
- The arguments to the Object
static
factory method or constructor.Object
instance.IllegalAccessException
- If the specified Constructor
or
Method
enforces Java language
access control and the underlying
Constructor
or Method
is
inaccessible.IllegalArgumentException
- If the number of actual and formal parameters
differ; if an unwrapping conversion for
primitive arguments fails; or if, after
possible unwrapping, a parameter value cannot
be converted to the corresponding formal
parameter type by a method invocation
conversion; if this Constructor
or
Method
pertains to an
Enum
type.InstantiationException
- If the underlying Constructor
or
Method
represents an abstract
Class
.InvocationTargetException
- If the underlying Constructor
or
Method
fails for some reason.NoSuchMethodException
- If the specified Constructor
or
Method
does not exist.public T getInstance(Object... arguments) throws IllegalAccessException, IllegalArgumentException, InstantiationException, InvocationTargetException, NoSuchMethodException
Object
instance. This method will first
attempt to find and invoke a static factory method. If no factory
method is found, it will then attempt to construct a new instance.arguments
- The arguments to the Object
static
factory method or constructor.Object
instance.IllegalAccessException
- If the specified Constructor
or
Method
enforces Java language
access control and the underlying
Constructor
or Method
is
inaccessible.IllegalArgumentException
- If the number of actual and formal parameters
differ; if an unwrapping conversion for
primitive arguments fails; or if, after
possible unwrapping, a parameter value cannot
be converted to the corresponding formal
parameter type by a method invocation
conversion; if this Constructor
or
Method
pertains to an
Enum
type.InstantiationException
- If the underlying Constructor
or
Method
represents an abstract
Class
.InvocationTargetException
- If the underlying Constructor
or
Method
fails for some reason.NoSuchMethodException
- If the specified Constructor
or
Method
does not exist.public boolean hasFactoryMethodFor(Class<?>... parameters)
Member
(factory
Method
, static Method
, or Constructor
) to
manufacture or get an Object
.parameters
- The Constructor
or Method
parameter list.true
if there is such a Member
;
false
otherwise.public Member getFactoryMethod(Class<?>... parameters) throws NoSuchMethodException
Member
(factory Method
,
static Method
, or Constructor
) to manufacture or get
an Object
.parameters
- The Constructor
or Method
parameter list.Member
.NoSuchMethodException
- If the specified Constructor
or
Method
does not exist.public T apply(Member member, Object... arguments) throws IllegalAccessException, InstantiationException, InvocationTargetException
Member
(factory Method
,
static Method
, or Constructor
) to manufacture or get
an Object
.member
- The Member
(Constructor
or
static Method
) to invoke.arguments
- The array of arguments to apply.Object
instance.IllegalAccessException
- If the specified Constructor
or
Method
enforces Java language
access control and the underlying
Constructor
or Method
is
inaccessible.InstantiationException
- If the underlying Constructor
or
Method
represents an abstract
Class
.InvocationTargetException
- If the underlying Constructor
or
Method
fails for some reason.protected static Class<?>[] typesOf(Object... arguments)
arguments
- The argument array.Class
s).protected static boolean isApplicable(Class<?>[] parameters, Class<?>... arguments)
parameters
- The parameter types.arguments
- The argument types.true
if the length of the argument array is the same
as the length of the parameter array and each parameter is
assignable from its corresponding argument; false
otherwise.Class.isAssignableFrom(Class)
Copyright © 2015–2020 Allen D. Ball. All rights reserved.