All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sfm.jdbc.impl.getter.MapperGetterAdapter Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

There is a newer version: 1.10.3
Show newest version
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 +
                '}';
    }
}