All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.remondis.remap.SetTransformation Maven / Gradle / Ivy

There is a newer version: 4.3.7
Show newest version
package com.remondis.remap;

import static com.remondis.remap.Properties.asString;

import java.beans.PropertyDescriptor;
import java.util.function.Function;

import javax.xml.crypto.dsig.Transform;

/**
 * A replace transformation converts a source object into a destination object by applying the specified {@link
 * Transform} function on the source.
 *
 * @param  The input type
 * @param  The output type
 * @author schuettec
 */
class SetTransformation extends Transformation {

  private static final String MSG = "Set %s with a custom value supplier.";

  private Function transformation;

  SetTransformation(MappingConfiguration mapping, PropertyDescriptor destProperty,
      Function transformation) {
    super(mapping, null, destProperty);
    this.transformation = transformation;
  }

  @Override
  protected void performTransformation(PropertyDescriptor sourceProperty, Object source,
      PropertyDescriptor destinationProperty, Object destination) throws MappingException {
    MappedResult result = performValueTransformation(source, destination);
    if (result.hasValue()) {
      writeOrFail(destinationProperty, destination, result.getValue());
    }
  }

  @Override
  @SuppressWarnings("unchecked")
  protected MappedResult performValueTransformation(Object source, Object destination) throws MappingException {
    Object destinationValue = transformation.apply((S) source);
    return MappedResult.value(destinationValue);
  }

  @Override
  protected void validateTransformation() throws MappingException {
  }

  @Override
  public String toString(boolean detailed) {
    return String.format(MSG, asString(destinationProperty, detailed));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy