Package com.expediagroup.transformer
Class AbstractTransformer<T extends Transformer,P,S extends TransformerSettings<P>>
java.lang.Object
com.expediagroup.transformer.AbstractTransformer<T,P,S>
- Type Parameters:
T
- theTransformer
implementation.S
- theTransformerSettings
implementation.P
- theFieldMapping
andFieldTransformer
key class type.
- All Implemented Interfaces:
Transformer<T>
- Direct Known Subclasses:
MapTransformerImpl
,TransformerImpl
public abstract class AbstractTransformer<T extends Transformer,P,S extends TransformerSettings<P>> extends java.lang.Object implements Transformer<T>
Abstract class containing all method implementation that will be common to any
Transformer
.-
Field Summary
Fields Modifier and Type Field Description protected CacheManager
cacheManager
CacheManager instanceCacheManager
.protected ClassUtils
classUtils
Class utils instanceClassUtils
.protected ReflectionUtils
reflectionUtils
Reflection utils instanceReflectionUtils
.protected S
settings
Contains both the field name mapping and the lambda function to be applied on fields.protected java.lang.String
transformerFunctionRegex
A regex that returns all the transformer function cached items. -
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractTransformer(java.lang.String transformerFunctionCachePrefix, java.lang.String cacheName, S transformerSettings)
Default constructor. -
Method Summary
Modifier and Type Method Description void
removeFieldMapping(java.lang.String destFieldName)
Removes the field mapping for the given field.void
removeFieldTransformer(java.lang.String destFieldName)
Removes the field transformer for the given field.void
reset()
Removes all the configured settings.void
resetFieldsMapping()
Removes all the configured fields mapping.void
resetFieldsTransformer()
Removes all the configured fields transformer.T
withFieldMapping(FieldMapping... fieldMapping)
Initializes the mapping between fields in the source object and the destination one.T
withFieldTransformer(FieldTransformer... fieldTransformer)
Initializes the field transformer functions.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
reflectionUtils
Reflection utils instanceReflectionUtils
. -
classUtils
Class utils instanceClassUtils
. -
cacheManager
CacheManager instanceCacheManager
. -
transformerFunctionRegex
protected final java.lang.String transformerFunctionRegexA regex that returns all the transformer function cached items. -
settings
Contains both the field name mapping and the lambda function to be applied on fields.
-
-
Constructor Details
-
AbstractTransformer
protected AbstractTransformer(java.lang.String transformerFunctionCachePrefix, java.lang.String cacheName, S transformerSettings)Default constructor.- Parameters:
transformerFunctionCachePrefix
- the cache key prefix for the Transformer Functions.cacheName
- the cache key prefix for the transformer.transformerSettings
- contains the transformer configuration.
-
-
Method Details
-
withFieldMapping
Initializes the mapping between fields in the source object and the destination one.- Specified by:
withFieldMapping
in interfaceTransformer<T extends Transformer>
- Parameters:
fieldMapping
- the field mapping- Returns:
- the
Transformer
instance
-
withFieldTransformer
Initializes the field transformer functions. The transformer function returns directly the field value.- Specified by:
withFieldTransformer
in interfaceTransformer<T extends Transformer>
- Parameters:
fieldTransformer
- the fields transformer function- Returns:
- the
Transformer
instance
-
removeFieldMapping
public final void removeFieldMapping(java.lang.String destFieldName)Removes the field mapping for the given field.- Specified by:
removeFieldMapping
in interfaceTransformer<T extends Transformer>
- Parameters:
destFieldName
- the field name in the destination object
-
resetFieldsMapping
public final void resetFieldsMapping()Removes all the configured fields mapping.- Specified by:
resetFieldsMapping
in interfaceTransformer<T extends Transformer>
-
removeFieldTransformer
public final void removeFieldTransformer(java.lang.String destFieldName)Removes the field transformer for the given field.- Specified by:
removeFieldTransformer
in interfaceTransformer<T extends Transformer>
- Parameters:
destFieldName
- the field name in the destination object
-
resetFieldsTransformer
public final void resetFieldsTransformer()Removes all the configured fields transformer.- Specified by:
resetFieldsTransformer
in interfaceTransformer<T extends Transformer>
-
reset
public final void reset()Removes all the configured settings.- Specified by:
reset
in interfaceTransformer<T extends Transformer>
-