@ThreadSafe public abstract class AbstractRandomDataProviderStrategy extends Object implements RandomDataProviderStrategy
DataProviderStrategy
This default implementation returns values based on a random generator. Convinient for subclassing and redefining behaviour. Don't use this implementation if you seek deterministic values
All values returned by this implementation are different from zero.
DataProviderStrategy.Order| Modifier and Type | Field and Description |
|---|---|
private Map<Class<? extends Annotation>,Class<AttributeStrategy<?>>> |
attributeStrategies
Mapping between annotations and attribute strategies
|
private AbstractConstructorComparator |
constructorHeavyComparator
The constructor comparator
|
private AbstractConstructorComparator |
constructorLightComparator
The constructor comparator
|
private Map<Class<?>,Class<?>> |
factoryTypes
A list of user-submitted factories to build interfaces and abstract classes
|
private AtomicBoolean |
isMemoizationEnabled
Flag to enable/disable the memoization setting.
|
private static org.slf4j.Logger |
LOG
Application logger
|
static int |
MAX_DEPTH
How many times it is allowed to PODAM to create an instance of the same
class in a recursive hierarchy
|
private AtomicInteger |
maxDepth
The max stack trace depth.
|
private Map<Class<?>,Map<Type[],Object>> |
memoizationTable
A map to keep one object for each class.
|
private AbstractMethodComparator |
methodHeavyComparator
The constructor comparator
|
private AbstractMethodComparator |
methodLightComparator
The constructor comparator
|
private AtomicInteger |
nbrOfCollectionElements
The number of collection elements.
|
private Map<Class<?>,Class<?>> |
specificTypes
A list of user-submitted specific implementations for interfaces and
abstract classes
|
private ConcurrentHashMap<Class<?>,TypeManufacturer<?>> |
typeManufacturers
A mapping between types and their registered manufacturers
|
| Constructor and Description |
|---|
AbstractRandomDataProviderStrategy()
Implementation of the Singleton pattern
|
AbstractRandomDataProviderStrategy(int nbrOfCollectionElements) |
| Modifier and Type | Method and Description |
|---|---|
RandomDataProviderStrategy |
addOrReplaceAttributeStrategy(Class<? extends Annotation> annotationClass,
Class<AttributeStrategy<?>> strategyClass)
Bind an annotation to attribute strategy class.
|
<T> AbstractRandomDataProviderStrategy |
addOrReplaceFactory(Class<T> abstractClass,
Class<?> factoryClass)
Binds an interface/abstract class to its factory.
|
<T> DataProviderStrategy |
addOrReplaceSpecific(Class<T> abstractClass,
Class<? extends T> specificClass)
Bind an interface/abstract class to a specific implementation.
|
<T> DataProviderStrategy |
addOrReplaceTypeManufacturer(Class<? extends T> type,
TypeManufacturer<T> typeManufacturer)
Registers @TypeManufacturer implementation, which will be used to
instantiate objects of a specified type.
|
void |
cacheMemoizedObject(AttributeMetadata attributeMetadata,
Object instance)
Saves object in memoization cache
|
void |
clearMemoizationCache()
Clears memoization cache
|
AbstractConstructorComparator |
getConstructorHeavyComparator()
Getter for constructor heavy comparator.
|
AbstractConstructorComparator |
getConstructorLightComparator()
Getter for constructor light comparator.
|
Class<?> |
getFactoryClass(Class<?> nonInstantiatableClass)
Resolves factory classes for abstract classes and interfaces.
|
int |
getMaxDepth(Class<?> type)
Returns how many times it is allowed to PODAM to create an instance
of the same class in a recursive hierarchy
|
Object |
getMemoizedObject(AttributeMetadata attributeMetadata)
Obtains object from memoization cache
|
AbstractMethodComparator |
getMethodHeavyComparator()
Getter for method heavy comparator.
|
AbstractMethodComparator |
getMethodLightComparator()
Getter for method light comparator.
|
int |
getNumberOfCollectionElements(Class<?> type)
Returns the number of default collection elements.
|
<T> Class<? extends T> |
getSpecificClass(Class<T> nonInstantiatableClass)
Resolves abstract classes and interfaces.
|
Class<AttributeStrategy<?>> |
getStrategyForAnnotation(Class<? extends Annotation> annotationClass)
Finds attribute strategies for annotations.
|
<T> T |
getTypeValue(AttributeMetadata attributeMetadata,
Map<String,Type> genericTypesArgumentsMap,
Class<T> pojoType)
Obtains a type value
|
boolean |
isMemoizationEnabled()
Returns whether the memoization setting is enabled.
|
private void |
log(AttributeMetadata attributeMetadata) |
RandomDataProviderStrategy |
removeAttributeStrategy(Class<? extends Annotation> annotationClass)
Remove binding of an annotation to attribute strategy
|
<T> AbstractRandomDataProviderStrategy |
removeFactory(Class<T> abstractClass)
Remove binding of an interface/abstract class to its factory
|
<T> DataProviderStrategy |
removeSpecific(Class<T> abstractClass)
Remove binding of an interface/abstract class to a specific
implementation
|
<T> DataProviderStrategy |
removeTypeManufacturer(Class<T> type)
Remove binding of a class type to a specific
implementation of type manufacturer
|
void |
setConstructorHeavyComparator(AbstractConstructorComparator constructorHeavyComparator)
Setter for constructor heavy comparator.
|
void |
setConstructorLightComparator(AbstractConstructorComparator constructorLightComparator)
Setter for constructor öight comparator.
|
void |
setDefaultNumberOfCollectionElements(int newNumberOfCollectionElements)
Sets the new default number of default collection elements.
|
void |
setMemoization(boolean isMemoizationEnabled)
Sets whether memoization is enabled
|
void |
setMethodHeavyComparator(AbstractMethodComparator methodHeavyComparator)
Setter for method heavy comparator.
|
void |
setMethodLightComparator(AbstractMethodComparator methodLightComparator)
Setter for method light comparator.
|
void |
sort(Constructor<?>[] constructors,
DataProviderStrategy.Order order)
Rearranges POJO's constructors in order they will be tried to produce the
POJO.
|
void |
sort(Method[] methods,
DataProviderStrategy.Order order)
Rearranges POJO's methods in order they will be tried to produce the
POJO.
|
private static final org.slf4j.Logger LOG
public static final int MAX_DEPTH
private final AtomicInteger maxDepth
private final AtomicInteger nbrOfCollectionElements
private final AtomicBoolean isMemoizationEnabled
private final Map<Class<?>,Map<Type[],Object>> memoizationTable
private final ConcurrentHashMap<Class<?>,TypeManufacturer<?>> typeManufacturers
private final Map<Class<?>,Class<?>> specificTypes
private final Map<Class<?>,Class<?>> factoryTypes
private final Map<Class<? extends Annotation>,Class<AttributeStrategy<?>>> attributeStrategies
private AbstractConstructorComparator constructorHeavyComparator
private AbstractConstructorComparator constructorLightComparator
private AbstractMethodComparator methodHeavyComparator
private AbstractMethodComparator methodLightComparator
public AbstractRandomDataProviderStrategy()
public AbstractRandomDataProviderStrategy(int nbrOfCollectionElements)
public int getNumberOfCollectionElements(Class<?> type)
Implementations of this interface need to provide this value.
getNumberOfCollectionElements in interface DataProviderStrategytype - Type of collection's elementspublic void setDefaultNumberOfCollectionElements(int newNumberOfCollectionElements)
setDefaultNumberOfCollectionElements in interface DataProviderStrategynewNumberOfCollectionElements - The new number of collection elements.public int getMaxDepth(Class<?> type)
Implementations of this interface need to provide this value.
getMaxDepth in interface DataProviderStrategytype - Type of POJO to be createdpublic boolean isMemoizationEnabled()
Implementations of this interface need to provide this value.
isMemoizationEnabled in interface DataProviderStrategypublic void setMemoization(boolean isMemoizationEnabled)
setMemoization in interface DataProviderStrategyisMemoizationEnabled - whether memoization is enabledpublic Object getMemoizedObject(AttributeMetadata attributeMetadata)
getMemoizedObject in interface DataProviderStrategyattributeMetadata - attribute metadata for instance to be fetchedpublic void cacheMemoizedObject(AttributeMetadata attributeMetadata, Object instance)
cacheMemoizedObject in interface DataProviderStrategyattributeMetadata - attribute metadata for instance being memoizedinstance - object instance to save in memoization cachepublic void clearMemoizationCache()
clearMemoizationCache in interface DataProviderStrategypublic void sort(Constructor<?>[] constructors, DataProviderStrategy.Order order)
sort in interface DataProviderStrategyconstructors - Array of POJO's constructorsorder - DataProviderStrategy.Order how to sort constructorspublic void sort(Method[] methods, DataProviderStrategy.Order order)
sort in interface DataProviderStrategymethods - Array of POJO's methodsorder - DataProviderStrategy.Order how to sort constructorspublic <T> DataProviderStrategy addOrReplaceTypeManufacturer(Class<? extends T> type, TypeManufacturer<T> typeManufacturer)
addOrReplaceTypeManufacturer in interface DataProviderStrategyT - type of objects to be produced by the manufacturertype - the specific class type the specified manufacturer
will instantiate.typeManufacturer - type manufacturer implementation to be registeredpublic <T> DataProviderStrategy removeTypeManufacturer(Class<T> type)
removeTypeManufacturer in interface DataProviderStrategyT - type of objects to be produced by the manufacturertype - the specific class type to remove bindingpublic <T> T getTypeValue(AttributeMetadata attributeMetadata, Map<String,Type> genericTypesArgumentsMap, Class<T> pojoType)
getTypeValue in interface DataProviderStrategyT - type of returned objectattributeMetadata - The AttributeMetadata informationgenericTypesArgumentsMap - The generic attribute type argument typespojoType - The class of the requested typepublic <T> AbstractRandomDataProviderStrategy addOrReplaceFactory(Class<T> abstractClass, Class<?> factoryClass)
addOrReplaceFactory in interface RandomDataProviderStrategyT - return typeabstractClass - the interface/abstract class to bindfactoryClass - factory class for instantiation of
abstractClass.public <T> AbstractRandomDataProviderStrategy removeFactory(Class<T> abstractClass)
removeFactory in interface RandomDataProviderStrategyT - return typeabstractClass - the interface/abstract class to remove bindingpublic Class<?> getFactoryClass(Class<?> nonInstantiatableClass)
Should return factory class type, which can be used to instantiate an abstract class type or interface.
getFactoryClass in interface DataProviderStrategynonInstantiatableClass - Abstract class type or interfacenonInstantiatableClass.public <T> DataProviderStrategy addOrReplaceSpecific(Class<T> abstractClass, Class<? extends T> specificClass)
addOrReplaceSpecific in interface DataProviderStrategyT - return typeabstractClass - the interface/abstract class to bindspecificClass - the specific class implementing or extending
abstractClass.public <T> DataProviderStrategy removeSpecific(Class<T> abstractClass)
removeSpecific in interface DataProviderStrategyT - return typeabstractClass - the interface/abstract class to remove bindingpublic <T> Class<? extends T> getSpecificClass(Class<T> nonInstantiatableClass)
Should return specific class type, which can be instantiated and assigned to abstract class type or interface.
getSpecificClass in interface DataProviderStrategyT - The type of class being resolvednonInstantiatableClass - Abstract class type or interfacenonInstantiatableClass.public RandomDataProviderStrategy addOrReplaceAttributeStrategy(Class<? extends Annotation> annotationClass, Class<AttributeStrategy<?>> strategyClass)
addOrReplaceAttributeStrategy in interface RandomDataProviderStrategyannotationClass - the annotation classstrategyClass - the attribute strategy classpublic RandomDataProviderStrategy removeAttributeStrategy(Class<? extends Annotation> annotationClass)
removeAttributeStrategy in interface RandomDataProviderStrategyannotationClass - the annotation class to remove bindingpublic Class<AttributeStrategy<?>> getStrategyForAnnotation(Class<? extends Annotation> annotationClass)
Searches for mapping between annotations and attribute strategies, which will be used then for populating fields or constructor parameters.
getStrategyForAnnotation in interface DataProviderStrategyannotationClass - Annotation class to inspectpublic AbstractConstructorComparator getConstructorLightComparator()
getConstructorLightComparator in interface RandomDataProviderStrategypublic void setConstructorLightComparator(AbstractConstructorComparator constructorLightComparator)
Default implementations are
ConstructorHeavyFirstComparator and
ConstructorLightFirstComparator.
setConstructorLightComparator in interface RandomDataProviderStrategyconstructorLightComparator - constructor comparator to setpublic AbstractConstructorComparator getConstructorHeavyComparator()
getConstructorHeavyComparator in interface RandomDataProviderStrategypublic void setConstructorHeavyComparator(AbstractConstructorComparator constructorHeavyComparator)
Default implementations are
ConstructorHeavyFirstComparator and
ConstructorLightFirstComparator.
setConstructorHeavyComparator in interface RandomDataProviderStrategyconstructorHeavyComparator - constructor comparator to setpublic AbstractMethodComparator getMethodLightComparator()
getMethodLightComparator in interface RandomDataProviderStrategypublic void setMethodLightComparator(AbstractMethodComparator methodLightComparator)
Default implementations is
MethodHeavyFirstComparator.
setMethodLightComparator in interface RandomDataProviderStrategymethodLightComparator - method comparator to setpublic AbstractMethodComparator getMethodHeavyComparator()
getMethodHeavyComparator in interface RandomDataProviderStrategypublic void setMethodHeavyComparator(AbstractMethodComparator methodHeavyComparator)
Default implementations is
MethodHeavyFirstComparator.
setMethodHeavyComparator in interface RandomDataProviderStrategymethodHeavyComparator - method comparator to setprivate void log(AttributeMetadata attributeMetadata)
Copyright © 2016. All rights reserved.