org.simpleflatmapper.map.mapper.TransformSourceFieldMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sfm-map Show documentation
Show all versions of sfm-map Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
The newest version!
package org.simpleflatmapper.map.mapper;
import org.simpleflatmapper.map.FieldMapper;
import org.simpleflatmapper.map.MappingContext;
import org.simpleflatmapper.map.MappingException;
import org.simpleflatmapper.map.SourceFieldMapper;
import org.simpleflatmapper.util.Function;
public class TransformSourceFieldMapper implements SourceFieldMapper {
public final SourceFieldMapper delegate;
public final FieldMapper[] mappers;
public final Function transform;
public TransformSourceFieldMapper(SourceFieldMapper delegate, FieldMapper[] mappers, Function transform) {
this.delegate = delegate;
this.mappers = mappers;
this.transform = transform;
}
@Override
public void mapTo(S source, O target, MappingContext super S> context) throws Exception {
for(FieldMapper mapper : mappers) {
mapper.mapTo(source, target, context);
}
}
@Override
public O map(S source, MappingContext super S> context) throws MappingException {
return transform.apply(delegate.map(source, context));
}
}