org.simpleflatmapper.map.mapper.MapperImpl 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.
package org.simpleflatmapper.map.mapper;
import org.simpleflatmapper.map.FieldMapper;
import org.simpleflatmapper.map.MappingContext;
import org.simpleflatmapper.reflect.BiInstantiator;
import java.util.Arrays;
public class MapperImpl extends AbstractMapper {
private final FieldMapper[] fieldMappers;
private final FieldMapper[] constructorMappers;
public MapperImpl(final FieldMapper[] fieldMappers,
final FieldMapper[] constructorMappers,
final BiInstantiator super S,MappingContext super S>, T> instantiator) {
super(instantiator);
this.fieldMappers = fieldMappers;
this.constructorMappers = constructorMappers;
}
protected final void mapFields(final S source, final T target, final MappingContext super S> mappingContext) throws Exception {
for (FieldMapper fieldMapper : fieldMappers) {
fieldMapper.mapTo(source, target, mappingContext);
}
}
@Override
protected final void mapToFields(S source, T target, final MappingContext super S> mappingContext) throws Exception {
for (FieldMapper constructorMapper : constructorMappers) {
constructorMapper.mapTo(source, target, mappingContext);
}
mapFields(source, target, mappingContext);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName())
.append("{");
super.appendToStringBuilder(sb);
sb.append(", fieldMappers=").append(Arrays.toString(fieldMappers));
sb.append("}");
return sb.toString();
}
}