@NotThreadSafe 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 ConcurrentMap<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 boolean |
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 int |
maxDepth
The max stack trace depth.
|
private ConcurrentMap<Class<?>,ConcurrentMap<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 int |
nbrOfCollectionElements
The number of collection elements.
|
private static Random |
RANDOM
A RANDOM generator
|
private ConcurrentMap<Class<?>,Class<?>> |
specificTypes
A list of user-submitted specific implementations for interfaces and
abstract classes
|
| 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> DataProviderStrategy |
addOrReplaceSpecific(Class<T> abstractClass,
Class<? extends T> specificClass)
Bind an interface/abstract class to a specific implementation.
|
void |
cacheMemoizedObject(AttributeMetadata attributeMetadata,
Object instance)
Saves object in memoization cache
|
void |
clearMemoizationCache()
Clears memoization cache
|
Boolean |
getBoolean(AttributeMetadata attributeMetadata)
It returns a boolean/Boolean value.
|
Byte |
getByte(AttributeMetadata attributeMetadata)
It returns a byte/Byte value.
|
Byte |
getByteInRange(byte minValue,
byte maxValue,
AttributeMetadata attributeMetadata)
It returns a byte/Byte within min and max value (included).
|
Character |
getCharacter(AttributeMetadata attributeMetadata)
It returns a char/Character value.
|
Character |
getCharacterInRange(char minValue,
char maxValue,
AttributeMetadata attributeMetadata)
It returns a char/Character value between min and max value (included).
|
AbstractConstructorComparator |
getConstructorHeavyComparator()
Getter for constructor heavy comparator.
|
AbstractConstructorComparator |
getConstructorLightComparator()
Getter for constructor light comparator.
|
Double |
getDouble(AttributeMetadata attributeMetadata)
It returns a double/Double value
|
Double |
getDoubleInRange(double minValue,
double maxValue,
AttributeMetadata attributeMetadata)
It returns a double/Double value between min and max value (included).
|
Float |
getFloat(AttributeMetadata attributeMetadata)
It returns a float/Float value.
|
Float |
getFloatInRange(float minValue,
float maxValue,
AttributeMetadata attributeMetadata)
It returns a float/Float value between min and max value (included).
|
Integer |
getInteger(AttributeMetadata attributeMetadata)
It returns an int/Integer value.
|
int |
getIntegerInRange(int minValue,
int maxValue,
AttributeMetadata attributeMetadata)
It returns an int/Integer value between min and max value (included).
|
Long |
getLong(AttributeMetadata attributeMetadata)
This implementation returns the current time in milliseconds.
|
Long |
getLongInRange(long minValue,
long maxValue,
AttributeMetadata attributeMetadata)
It returns a long/Long value between min and max value (included).
|
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.
|
Short |
getShort(AttributeMetadata attributeMetadata)
It returns a short/Short value.
|
Short |
getShortInRange(short minValue,
short maxValue,
AttributeMetadata attributeMetadata)
It returns a short/Short value between min and max value (included).
|
<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.
|
String |
getStringOfLength(int length,
AttributeMetadata attributeMetadata)
It returns a String of
length characters. |
String |
getStringValue(AttributeMetadata attributeMetadata)
It returns a string 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> DataProviderStrategy |
removeSpecific(Class<T> abstractClass)
Remove binding of an interface/abstract class to a specific
implementation
|
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
private static final Random RANDOM
public static final int MAX_DEPTH
private final int maxDepth
private int nbrOfCollectionElements
private boolean isMemoizationEnabled
private final ConcurrentMap<Class<?>,ConcurrentMap<Type[],Object>> memoizationTable
private final ConcurrentMap<Class<?>,Class<?>> specificTypes
private final ConcurrentMap<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 Boolean getBoolean(AttributeMetadata attributeMetadata)
getBoolean in interface DataProviderStrategyattributeMetadata - attribute metadata for instance to be fetchedpublic Byte getByte(AttributeMetadata attributeMetadata)
getByte in interface DataProviderStrategyattributeMetadata - attribute metadata for instance to be fetchedpublic Byte getByteInRange(byte minValue, byte maxValue, AttributeMetadata attributeMetadata)
getByteInRange in interface DataProviderStrategyminValue - The minimum value for the returned valuemaxValue - The maximum value for the returned valueattributeMetadata - attribute metadata for instance to be fetchedpublic Character getCharacter(AttributeMetadata attributeMetadata)
getCharacter in interface DataProviderStrategyattributeMetadata - attribute metadata for instance to be fetchedpublic Character getCharacterInRange(char minValue, char maxValue, AttributeMetadata attributeMetadata)
getCharacterInRange in interface DataProviderStrategyminValue - The minimum value for the returned valuemaxValue - The maximum value for the returned valueattributeMetadata - attribute metadata for instance to be fetchedpublic Double getDouble(AttributeMetadata attributeMetadata)
getDouble in interface DataProviderStrategyattributeMetadata - attribute metadata for instance to be fetchedpublic Double getDoubleInRange(double minValue, double maxValue, AttributeMetadata attributeMetadata)
getDoubleInRange in interface DataProviderStrategyminValue - The minimum value for the returned valuemaxValue - The maximum value for the returned valueattributeMetadata - attribute metadata for instance to be fetchedpublic Float getFloat(AttributeMetadata attributeMetadata)
getFloat in interface DataProviderStrategyattributeMetadata - attribute metadata for instance to be fetchedpublic Float getFloatInRange(float minValue, float maxValue, AttributeMetadata attributeMetadata)
getFloatInRange in interface DataProviderStrategyminValue - The minimum value for the returned valuemaxValue - The maximum value for the returned valueattributeMetadata - attribute metadata for instance to be fetchedpublic Integer getInteger(AttributeMetadata attributeMetadata)
getInteger in interface DataProviderStrategyattributeMetadata - attribute metadata for instance to be fetchedpublic int getIntegerInRange(int minValue,
int maxValue,
AttributeMetadata attributeMetadata)
getIntegerInRange in interface DataProviderStrategyminValue - The minimum value for the returned valuemaxValue - The maximum value for the returned valueattributeMetadata - attribute metadata for instance to be fetchedpublic Long getLong(AttributeMetadata attributeMetadata)
This can be useful for Date-like constructors which accept a long as argument. A complete random number would cause the instantiation of such classes to fail on a non-deterministic basis, e.g. when the random long would not be an acceptable value for, say, a YEAR field.
It returns a long/Long value.getLong in interface DataProviderStrategyattributeMetadata - attribute metadata for instance to be fetchedpublic Long getLongInRange(long minValue, long maxValue, AttributeMetadata attributeMetadata)
getLongInRange in interface DataProviderStrategyminValue - The minimum value for the returned valuemaxValue - The maximum value for the returned valueattributeMetadata - attribute metadata for instance to be fetchedpublic Short getShort(AttributeMetadata attributeMetadata)
getShort in interface DataProviderStrategyattributeMetadata - attribute metadata for instance to be fetchedpublic Short getShortInRange(short minValue, short maxValue, AttributeMetadata attributeMetadata)
getShortInRange in interface DataProviderStrategyminValue - The minimum value for the returned valuemaxValue - The maximum value for the returned valueattributeMetadata - attribute metadata for instance to be fetchedpublic String getStringValue(AttributeMetadata attributeMetadata)
getStringValue in interface DataProviderStrategyattributeMetadata - attribute metadata for instance to be fetchedpublic String getStringOfLength(int length, AttributeMetadata attributeMetadata)
length characters.getStringOfLength in interface DataProviderStrategylength - The number of characters required in the returned StringattributeMetadata - attribute metadata for instance to be fetchedlength characterspublic 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 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 © 2015. All rights reserved.