org.sfm.map.impl.MapperImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simpleFlatMapper Show documentation
Show all versions of simpleFlatMapper Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
package org.sfm.map.impl;
import org.sfm.map.FieldMapper;
import org.sfm.map.MappingContext;
import org.sfm.map.MappingContextFactory;
import org.sfm.reflect.Instantiator;
import java.util.Arrays;
public class MapperImpl extends AbstractMapperImpl {
private final FieldMapper[] fieldMappers;
private final FieldMapper[] constructorMappers;
public MapperImpl(final FieldMapper[] fieldMappers,
final FieldMapper[] constructorMappers,
final Instantiator instantiator,
final MappingContextFactory mappingContextFactory) {
super(instantiator, mappingContextFactory);
this.fieldMappers = fieldMappers;
this.constructorMappers = constructorMappers;
}
protected final void mapFields(final S source, final T target, final MappingContext mappingContext) throws Exception {
for (FieldMapper fieldMapper : fieldMappers) {
fieldMapper.mapTo(source, target, mappingContext);
}
}
@Override
protected final void mapToFields(S source, T target, final MappingContext 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();
}
}