cdc.mf.transform.MfModelTransformer Maven / Gradle / Ivy
package cdc.mf.transform;
import cdc.mf.model.MfModel;
/**
* Interface used to locally transform a {@link MfModel model}.
*
* For a deep transformation, use {@link MfTransformer}.
*
* @author Damien Carbonne
*/
@FunctionalInterface
public interface MfModelTransformer {
/**
* Converts a source model to a target one.
*
* @param srcModel The source model.
* @return The target model.
*/
public MfModel transform(MfModel srcModel);
/**
* @return An instance of {@link MfModelTransformer} that duplicates the source model.
*/
public static MfModelTransformer cloner() {
return MfModel::duplicate;
}
/**
* @param fixer The model fixer.
* @return An instance of {@link MfModelTransformer} that duplicates the source model and then fix it.
*/
public static MfModelTransformer of(MfElementFixer fixer) {
return srcModel -> {
final MfModel.Builder tgtBuilder = MfModel.builder();
srcModel.set(tgtBuilder);
fixer.fix(srcModel, tgtBuilder);
return tgtBuilder.build();
};
}
}