org.simpleflatmapper.GetterWithDefaultValue Maven / Gradle / Ivy
package org.simpleflatmapper;
import org.simpleflatmapper.reflect.Getter;
public class GetterWithDefaultValue implements Getter {
private final Getter delegate;
private final P defaultValue;
public GetterWithDefaultValue(Getter delegate, P defaultValue) {
this.delegate = delegate;
this.defaultValue = defaultValue;
}
@Override
public P get(T target) throws Exception {
P p = delegate.get(target);
if (p == null) return defaultValue;
return p;
}
}