org.simpleflatmapper.map.mapper.MapperFieldMapperGetterAdapter 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.converter.Context;
import org.simpleflatmapper.map.SourceMapper;
import org.simpleflatmapper.map.MappingContext;
import org.simpleflatmapper.map.getter.ContextualGetter;
import org.simpleflatmapper.util.Predicate;
import static org.simpleflatmapper.util.Asserts.requireNonNull;
public final class MapperFieldMapperGetterAdapter implements ContextualGetter {
public final SourceMapper mapper;
public final Predicate nullChecker;
public final int valueIndex;
public MapperFieldMapperGetterAdapter(SourceMapper mapper, Predicate nullChecker, int valueIndex) {
this.mapper = requireNonNull("jdbcMapper", mapper);
this.nullChecker = requireNonNull("nullChecker", nullChecker);
this.valueIndex = valueIndex;
}
@Override
public String toString() {
return "MapperBiFunctionAdapter{" +
"jdbcMapper=" + mapper +
'}';
}
@Override
public P get(S s, Context context) {
if (nullChecker.test(s)){
return null;
}
MappingContext super S> mappingContext = (MappingContext super S>) context;
P value = mapper.map(s, mappingContext);
if (mappingContext != null) {
mappingContext.setCurrentValue(valueIndex, value);
}
return value;
}
}