org.simpleflatmapper.map.getter.ContextualGetterWithDefaultValue 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.getter;
import org.simpleflatmapper.converter.Context;
import org.simpleflatmapper.map.getter.ContextualGetter;
public class ContextualGetterWithDefaultValue implements ContextualGetter {
private final P defaultValue;
private final ContextualGetter super T, ? extends P> delegate;
public ContextualGetterWithDefaultValue(ContextualGetter super T, ? extends P> delegate, P defaultValue) {
this.delegate = delegate;
this.defaultValue = defaultValue;
}
@Override
public P get(T t, Context context) throws Exception {
P p = delegate.get(t, context);
if (p == null) return defaultValue;
return p;
}
}