org.sfm.jdbc.impl.getter.MapperGetterAdapter 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.jdbc.impl.getter;
import org.sfm.map.Mapper;
import org.sfm.reflect.Getter;
import org.sfm.utils.Predicate;
public final class MapperGetterAdapter implements Getter {
private final Mapper mapper;
private final Predicate nullChecker;
public MapperGetterAdapter(Mapper mapper, Predicate nullChecker) {
if (mapper == null) {
throw new NullPointerException("mapper is null");
}
if (nullChecker == null) {
throw new NullPointerException("nullChecker is null");
}
this.mapper = mapper;
this.nullChecker = nullChecker;
}
@Override
public P get(S target) throws Exception {
if (nullChecker.test(target)){
return null;
}
return mapper.map(target);
}
@Override
public String toString() {
return "MapperGetterAdapter{" +
"mapper=" + mapper +
'}';
}
}