public class DefaultInstances extends java.lang.Object implements InstanceProvider
Modifier and Type | Field and Description |
---|---|
static DefaultInstances |
DEFAULT
Standard default instance provider.
|
Constructor and Description |
---|
DefaultInstances(DefaultInstances other)
Copy a given instance provider.
|
DefaultInstances(com.google.common.collect.ImmutableList<InstanceProvider> registered)
Construct a default instance generator using the given instance providers.
|
DefaultInstances(InstanceProvider... instaceProviders)
Construct a default instance generator using the given instance providers.
|
Modifier and Type | Method and Description |
---|---|
protected <T> boolean |
contains(T[] elements,
T elementToFind) |
java.lang.Object |
create(java.lang.Class<?> type)
Create an instance given a type, if possible.
|
protected <T> T |
createInstance(java.lang.Class<T> type,
java.lang.reflect.Constructor<T> constructor,
java.lang.Class<?>[] types,
java.lang.Object[] params)
Used by the default instance provider to create a class from a given constructor.
|
DefaultInstances |
forEnhancer(net.sf.cglib.proxy.Enhancer enhancer)
Construct default instances using the CGLIB enhancer object instead.
|
static DefaultInstances |
fromArray(InstanceProvider... instanceProviders)
Construct a default instance generator using the given instance providers.
|
static DefaultInstances |
fromCollection(java.util.Collection<InstanceProvider> instanceProviders)
Construct a default instance generator using the given instance providers.
|
<T> T |
getDefault(java.lang.Class<T> type)
Retrieves a default instance or value that is assignable to this type.
|
<T> T |
getDefault(java.lang.Class<T> type,
java.util.List<InstanceProvider> providers)
Retrieves a default instance or value that is assignable to this type.
|
int |
getMaximumRecursion()
Retrieve the the maximum height of the hierachy of creates types.
|
<T> java.lang.reflect.Constructor<T> |
getMinimumConstructor(java.lang.Class<T> type)
Retrieve the constructor with the fewest number of parameters.
|
com.google.common.collect.ImmutableList<InstanceProvider> |
getRegistered()
Retrieves a immutable list of every default object providers that generates instances.
|
boolean |
isNonNull()
Retrieve whether or not the constructor's parameters must be non-null.
|
void |
setMaximumRecursion(int maximumRecursion)
Set the maximum height of the hierachy of creates types.
|
void |
setNonNull(boolean nonNull)
Set whether or not the constructor's parameters must be non-null.
|
public static final DefaultInstances DEFAULT
public DefaultInstances(com.google.common.collect.ImmutableList<InstanceProvider> registered)
registered
- - list of instance providers.public DefaultInstances(DefaultInstances other)
other
- - instance provider to copy.public DefaultInstances(InstanceProvider... instaceProviders)
instaceProviders
- - array of instance providers.public static DefaultInstances fromArray(InstanceProvider... instanceProviders)
instanceProviders
- - array of instance providers.public static DefaultInstances fromCollection(java.util.Collection<InstanceProvider> instanceProviders)
instanceProviders
- - collection of instance providers.public com.google.common.collect.ImmutableList<InstanceProvider> getRegistered()
public boolean isNonNull()
public void setNonNull(boolean nonNull)
nonNull
- - TRUE if they must be non-null, FALSE otherwise.public int getMaximumRecursion()
public void setMaximumRecursion(int maximumRecursion)
maximumRecursion
- - maximum recursion height.public <T> T getDefault(java.lang.Class<T> type)
This includes, but isn't limited too:
type
- - the type to construct a default value.public <T> java.lang.reflect.Constructor<T> getMinimumConstructor(java.lang.Class<T> type)
type
- - type to construct.public <T> T getDefault(java.lang.Class<T> type, java.util.List<InstanceProvider> providers)
This includes, but isn't limited too:
type
- - the type to construct a default value.providers
- - instance providers used during the construction.public DefaultInstances forEnhancer(net.sf.cglib.proxy.Enhancer enhancer)
enhancer
- - a CGLIB enhancer to use.protected <T> T createInstance(java.lang.Class<T> type, java.lang.reflect.Constructor<T> constructor, java.lang.Class<?>[] types, java.lang.Object[] params)
type
- - the type to create.constructor
- - the constructor to use.types
- - type of each parameter in order.params
- - value of each parameter in order.protected <T> boolean contains(T[] elements, T elementToFind)
public java.lang.Object create(@Nullable java.lang.Class<?> type)
InstanceProvider
create
in interface InstanceProvider
type
- - type to create.