public abstract class AbstractRandomDataProviderStrategy extends Object implements DataProviderStrategy
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.
| Modifier and Type | Field and Description |
|---|---|
private static ConstructorComparator |
CONSTRUCTOR_COMPARATOR
The constructor comparator
|
static int |
DEFAULT_NBR_COLLECTION_ELEMENTS
The default number of collection elements for this strategy
|
private Set<Class<? extends Annotation>> |
excludedAnnotations
Set of annotations, which mark fields to be skipped from populating.
|
private boolean |
isMemoizationEnabled
Flag to enable/disable the memoization setting.
|
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 static MethodComparator |
METHOD_COMPARATOR
The constructor comparator
|
private int |
nbrOfCollectionElements
The number of collection elements.
|
static char[] |
NICE_ASCII_CHARACTERS
An array of valid String characters
|
private static Random |
RANDOM
A RANDOM generator
|
private Map<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 |
|---|---|
AbstractRandomDataProviderStrategy |
addExcludedAnnotation(Class<? extends Annotation> annotation)
Adds the specified
Annotation to set of excluded annotations,
if it is not already present. |
<T> AbstractRandomDataProviderStrategy |
addSpecific(Class<T> abstractClass,
Class<? extends T> specificClass)
Bind an interface/abstract class to a specific implementation
|
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).
|
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).
|
Set<Class<? extends Annotation>> |
getExcludedAnnotations()
Identifies
Annotations for fields to be skipped. |
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
|
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.
|
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.
|
AbstractRandomDataProviderStrategy |
removeExcludedAnnotation(Class<? extends Annotation> annotation)
Adds the specified
Annotation from set of excluded annotations. |
<T> AbstractRandomDataProviderStrategy |
removeSpecific(Class<T> abstractClass)
Remove binding of an interface/abstract class to a specific
implementation
|
void |
setMaxDepth(int newMaxDepth)
Sets the new max stack trace depth.
|
void |
setMemoizationEnabled(boolean value)
When memoization is enabled, only one object will be created for each type.
|
void |
setNumberOfCollectionElements(int newNumberOfCollectionElements)
Sets the new number of default collection elements.
|
void |
sort(Constructor<?>[] constructors)
Rearranges POJO's constructors in order they will be tried to produce the
POJO.
|
void |
sort(Method[] methods)
Rearranges POJO's methods in order they will be tried to produce the
POJO.
|
private static final Random RANDOM
private static final ConstructorComparator CONSTRUCTOR_COMPARATOR
private static final MethodComparator METHOD_COMPARATOR
public static final char[] NICE_ASCII_CHARACTERS
public static final int MAX_DEPTH
public static final int DEFAULT_NBR_COLLECTION_ELEMENTS
private int maxDepth
private int nbrOfCollectionElements
private boolean isMemoizationEnabled
private final Map<Class<?>,Class<?>> specificTypes
private final Set<Class<? extends Annotation>> excludedAnnotations
public AbstractRandomDataProviderStrategy()
public AbstractRandomDataProviderStrategy(int nbrOfCollectionElements)
public Boolean getBoolean(AttributeMetadata attributeMetadata)
getBoolean in interface DataProviderStrategypublic Byte getByte(AttributeMetadata attributeMetadata)
getByte in interface DataProviderStrategypublic 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 valuepublic Character getCharacter(AttributeMetadata attributeMetadata)
getCharacter in interface DataProviderStrategypublic 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 valuepublic Double getDouble(AttributeMetadata attributeMetadata)
getDouble in interface DataProviderStrategypublic 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 valuepublic Float getFloat(AttributeMetadata attributeMetadata)
getFloat in interface DataProviderStrategypublic 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 valuepublic Integer getInteger(AttributeMetadata attributeMetadata)
getInteger in interface DataProviderStrategypublic 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 valuepublic 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 DataProviderStrategypublic 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 valuepublic Short getShort(AttributeMetadata attributeMetadata)
getShort in interface DataProviderStrategypublic 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 valuepublic String getStringValue(AttributeMetadata attributeMetadata)
getStringValue in interface DataProviderStrategypublic String getStringOfLength(int length, AttributeMetadata attributeMetadata)
length characters.getStringOfLength in interface DataProviderStrategylength - The number of characters required in the returned Stringlength characterspublic int getNumberOfCollectionElements(Class<?> type)
Implementations of this interface need to provide this value.
getNumberOfCollectionElements in interface DataProviderStrategytype - Type of collection's elementspublic void setNumberOfCollectionElements(int newNumberOfCollectionElements)
newNumberOfCollectionElements - 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 void setMaxDepth(int newMaxDepth)
newMaxDepth - The new max stack trace depth.public boolean isMemoizationEnabled()
Implementations of this interface need to provide this value.
isMemoizationEnabled in interface DataProviderStrategypublic void setMemoizationEnabled(boolean value)
value - True to enable, false to disable.public void sort(Constructor<?>[] constructors)
sort in interface DataProviderStrategyconstructors - Array of POJO's constructorspublic void sort(Method[] methods)
sort in interface DataProviderStrategymethods - Array of POJO's methodspublic <T> AbstractRandomDataProviderStrategy addSpecific(Class<T> abstractClass, Class<? extends T> specificClass)
abstractClass - the interface/abstract class to bindspecificClass - the specific class implementing or extending
abstractClass.public <T> AbstractRandomDataProviderStrategy removeSpecific(Class<T> abstractClass)
abstractClass - 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 DataProviderStrategynonInstantiatableClass - Abstract class type or interfacenonInstantiatableClass.public AbstractRandomDataProviderStrategy addExcludedAnnotation(Class<? extends Annotation> annotation)
Annotation to set of excluded annotations,
if it is not already present.annotation - the annotation to use as an exlusion markpublic AbstractRandomDataProviderStrategy removeExcludedAnnotation(Class<? extends Annotation> annotation)
Annotation from set of excluded annotations.annotation - the annotation used as an exlusion markpublic Set<Class<? extends Annotation>> getExcludedAnnotations()
Annotations for fields to be skipped.
Should return set of annotations, which will be treated as notion for
PodamFactory to skip production of these particular fields.
getExcludedAnnotations in interface DataProviderStrategyCopyright © 2015. All rights reserved.