org.simpleflatmapper.map.fieldmapper.ConstantSourceFieldMapper 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.fieldmapper;
import org.simpleflatmapper.map.FieldMapper;
import org.simpleflatmapper.map.MappingContext;
import org.simpleflatmapper.map.getter.ContextualGetter;
import org.simpleflatmapper.reflect.Setter;
import static org.simpleflatmapper.util.Asserts.requireNonNull;
public final class ConstantSourceFieldMapper implements FieldMapper {
public final ContextualGetter super S, ? extends P> getter;
public final Setter super T, ? super P> setter;
public ConstantSourceFieldMapper(final ContextualGetter super S, ? extends P> getter, final Setter super T, ? super P> setter) {
this.getter = requireNonNull("getter", getter);
this.setter = requireNonNull("setter", setter);
}
@Override
public void mapTo(final S source, final T target, final MappingContext super S> mappingContext) throws Exception {
final P value = getter.get(source, mappingContext);
setter.set(target, value);
}
@Override
public String toString() {
return "ConstantSourceFieldMapperImpl{" +
"getter=" + getter +
", setter=" + setter +
'}';
}
}