Interface DataProviderStrategy
-
- All Known Subinterfaces:
RandomDataProviderStrategy
- All Known Implementing Classes:
AbstractRandomDataProviderStrategy
,RandomDataProviderStrategyImpl
public interface DataProviderStrategy
This interface defines the contact for PODAM data providers.PODAM is a tool to fill POJOs with data. There are different requirements when it comes to which data POJOs should be filled with. The default strategy adopted by PODAM is to fill POJOs with random data. However other requirements might dictate to assign deterministic data using sequences, or other predictable sources of data. In order to do so, clients of PODAM will have to provide an implementation of this interface and pass it to the constructor of the
PodamFactoryImpl
class.- Since:
- 1.0.0
- Author:
- mtedone
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
DataProviderStrategy.Order
Specifies how to sort constructors
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <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 cachevoid
clearMemoizationCache()
Clears memoization cacheClass<?>
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 hierarchyObject
getMemoizedObject(AttributeMetadata attributeMetadata)
Obtains object from memoization cacheint
getNumberOfCollectionElements(Class<?> type)
Returns the number of default collection elements.<T> Class<? extends T>
getSpecificClass(Class<T> nonInstantiatableClass)
Resolves abstract classes and interfaces.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 valueboolean
isMemoizationEnabled()
Returns whether the memoization setting is enabled.<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 manufacturervoid
setDefaultNumberOfCollectionElements(int newNumberOfCollectionElements)
Sets the new default number of default collection elements.void
setMemoization(boolean isMemoizationEnabled)
Sets whether memoization is enabledvoid
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.
-
-
-
Method Detail
-
addOrReplaceTypeManufacturer
<T> DataProviderStrategy addOrReplaceTypeManufacturer(Class<? extends T> type, TypeManufacturer<T> typeManufacturer)
Registers @TypeManufacturer implementation, which will be used to instantiate objects of a specified type. Use this to alter factory behaviour.- Type Parameters:
T
- type of objects to be produced by the manufacturer- Parameters:
type
- the specific class type the specified manufacturer will instantiate.typeManufacturer
- type manufacturer implementation to be registered- Returns:
- itself
-
removeTypeManufacturer
<T> DataProviderStrategy removeTypeManufacturer(Class<T> type)
Remove binding of a class type to a specific implementation of type manufacturer- Type Parameters:
T
- type of objects to be produced by the manufacturer- Parameters:
type
- the specific class type to remove binding- Returns:
- itself
-
getTypeValue
<T> T getTypeValue(AttributeMetadata attributeMetadata, Map<String,Type> genericTypesArgumentsMap, Class<T> pojoType)
Obtains a type value- Type Parameters:
T
- type of returned object- Parameters:
attributeMetadata
- The AttributeMetadata informationgenericTypesArgumentsMap
- The generic attribute type argument typespojoType
- The class of the requested type- Returns:
- The type value
-
addOrReplaceSpecific
<T> DataProviderStrategy addOrReplaceSpecific(Class<T> abstractClass, Class<? extends T> specificClass)
Bind an interface/abstract class to a specific implementation. If the strategy previously contained a binding for the interface/abstract class, the old value will be replaced by the new value. If you want to implement more sophisticated binding strategy, override this class.- Type Parameters:
T
- return type- Parameters:
abstractClass
- the interface/abstract class to bindspecificClass
- the specific class implementing or extendingabstractClass
.- Returns:
- itself
-
removeSpecific
<T> DataProviderStrategy removeSpecific(Class<T> abstractClass)
Remove binding of an interface/abstract class to a specific implementation- Type Parameters:
T
- return type- Parameters:
abstractClass
- the interface/abstract class to remove binding- Returns:
- itself
-
getNumberOfCollectionElements
int getNumberOfCollectionElements(Class<?> type)
Returns the number of default collection elements.Implementations of this interface need to provide this value.
- Parameters:
type
- Type of collection's elements- Returns:
- The number of default collection elements
-
setDefaultNumberOfCollectionElements
void setDefaultNumberOfCollectionElements(int newNumberOfCollectionElements)
Sets the new default number of default collection elements.- Parameters:
newNumberOfCollectionElements
- The new number of collection elements.
-
getMaxDepth
int getMaxDepth(Class<?> type)
Returns how many times it is allowed to PODAM to create an instance of the same class in a recursive hierarchyImplementations of this interface need to provide this value.
- Parameters:
type
- Type of POJO to be created- Returns:
- How many times it is allowed to create an instance of the same class in a recursive hierarchy
-
isMemoizationEnabled
boolean isMemoizationEnabled()
Returns whether the memoization setting is enabled. When memoization is enabled, only one object will be created for each type. Every next property of the same type will be a reference to the same object. This can dramatically improve performance but with the expense of not having objects with different values.Implementations of this interface need to provide this value.
- Returns:
- Whether the memoization setting is enabled.
-
setMemoization
void setMemoization(boolean isMemoizationEnabled)
Sets whether memoization is enabled- Parameters:
isMemoizationEnabled
- whether memoization is enabled
-
getMemoizedObject
Object getMemoizedObject(AttributeMetadata attributeMetadata)
Obtains object from memoization cache- Parameters:
attributeMetadata
- attribute metadata for instance to be fetched- Returns:
- object instance from memoization cache
-
cacheMemoizedObject
void cacheMemoizedObject(AttributeMetadata attributeMetadata, Object instance)
Saves object in memoization cache- Parameters:
attributeMetadata
- attribute metadata for instance being memoizedinstance
- object instance to save in memoization cache
-
clearMemoizationCache
void clearMemoizationCache()
Clears memoization cache
-
sort
void sort(Constructor<?>[] constructors, DataProviderStrategy.Order order)
Rearranges POJO's constructors in order they will be tried to produce the POJO. Default strategy consists of putting constructors with less parameters to be tried first.- Parameters:
constructors
- Array of POJO's constructorsorder
-DataProviderStrategy.Order
how to sort constructors
-
sort
void sort(Method[] methods, DataProviderStrategy.Order order)
Rearranges POJO's methods in order they will be tried to produce the POJO. Default strategy consists of putting factory methods with more parameters to be tried first.- Parameters:
methods
- Array of POJO's methodsorder
-DataProviderStrategy.Order
how to sort constructors
-
getFactoryClass
Class<?> getFactoryClass(Class<?> nonInstantiatableClass)
Resolves factory classes for abstract classes and interfaces.Should return factory class type, which can be used to instantiate an abstract class type or interface.
- Parameters:
nonInstantiatableClass
- Abstract class type or interface- Returns:
- Non-abstract factory class type to instantiate
nonInstantiatableClass
.
-
getSpecificClass
<T> Class<? extends T> getSpecificClass(Class<T> nonInstantiatableClass)
Resolves abstract classes and interfaces.Should return specific class type, which can be instantiated and assigned to abstract class type or interface.
- Type Parameters:
T
- The type of class being resolved- Parameters:
nonInstantiatableClass
- Abstract class type or interface- Returns:
- Non-abstract class type derived from
nonInstantiatableClass
.
-
getStrategyForAnnotation
AttributeStrategy<?> getStrategyForAnnotation(Class<? extends Annotation> annotationClass)
Finds attribute strategies for annotations.Searches for mapping between annotations and attribute strategies, which will be used then for populating fields or constructor parameters.
- Parameters:
annotationClass
- Annotation class to inspect- Returns:
- attribute strategy associated with given annotation
-
-