Class AbstractTransformer<T extends Transformer,​P,​S extends TransformerSettings<P>>

java.lang.Object
com.expediagroup.transformer.AbstractTransformer<T,​P,​S>
Type Parameters:
T - the Transformer implementation.
S - the TransformerSettings implementation.
P - the FieldMapping and FieldTransformer 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 instance CacheManager.
    protected ClassUtils classUtils
    Class utils instance ClassUtils.
    protected ReflectionUtils reflectionUtils
    Reflection utils instance ReflectionUtils.
    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

      protected final ReflectionUtils reflectionUtils
      Reflection utils instance ReflectionUtils.
    • classUtils

      protected final ClassUtils classUtils
      Class utils instance ClassUtils.
    • cacheManager

      protected final CacheManager cacheManager
      CacheManager instance CacheManager.
    • transformerFunctionRegex

      protected final java.lang.String transformerFunctionRegex
      A regex that returns all the transformer function cached items.
    • settings

      protected S extends TransformerSettings<P> 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

      public final T withFieldMapping​(FieldMapping... fieldMapping)
      Initializes the mapping between fields in the source object and the destination one.
      Specified by:
      withFieldMapping in interface Transformer<T extends Transformer>
      Parameters:
      fieldMapping - the field mapping
      Returns:
      the Transformer instance
    • withFieldTransformer

      public final T withFieldTransformer​(FieldTransformer... fieldTransformer)
      Initializes the field transformer functions. The transformer function returns directly the field value.
      Specified by:
      withFieldTransformer in interface Transformer<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 interface Transformer<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 interface Transformer<T extends Transformer>
    • removeFieldTransformer

      public final void removeFieldTransformer​(java.lang.String destFieldName)
      Removes the field transformer for the given field.
      Specified by:
      removeFieldTransformer in interface Transformer<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 interface Transformer<T extends Transformer>
    • reset

      public final void reset()
      Removes all the configured settings.
      Specified by:
      reset in interface Transformer<T extends Transformer>