org.simpleflatmapper.map.getter.ContextualGetterAdapter 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.getter;
import org.simpleflatmapper.converter.Context;
import org.simpleflatmapper.reflect.Getter;
import org.simpleflatmapper.reflect.primitive.BooleanGetter;
import org.simpleflatmapper.reflect.primitive.ByteGetter;
import org.simpleflatmapper.reflect.primitive.CharacterGetter;
import org.simpleflatmapper.reflect.primitive.DoubleGetter;
import org.simpleflatmapper.reflect.primitive.FloatGetter;
import org.simpleflatmapper.reflect.primitive.IntGetter;
import org.simpleflatmapper.reflect.primitive.LongGetter;
import org.simpleflatmapper.reflect.primitive.ShortGetter;
public final class ContextualGetterAdapter implements ContextualGetter {
private final Getter super S, ? extends P> getter;
public ContextualGetterAdapter(Getter super S, ? extends P> getter) {
this.getter = getter;
}
@Override
public P get(S s, Context context) throws Exception {
return getter.get(s);
}
public static ContextualGetter of(Getter super S, ? extends P> getter) {
if (getter == null) return null;
if (getter instanceof BooleanGetter) {
return (ContextualGetter) new FieldMapperBooleanGetterAdapter((Getter super S, Boolean>) getter);
}
if (getter instanceof ByteGetter) {
return (ContextualGetter) new FieldMapperByteGetterAdapter((Getter super S, Byte>) getter);
}
if (getter instanceof CharacterGetter) {
return (ContextualGetter) new FieldMapperCharacterGetterAdapter((Getter super S, Character>) getter);
}
if (getter instanceof ShortGetter) {
return (ContextualGetter) new FieldMapperShortGetterAdapter((Getter super S, Short>) getter);
}
if (getter instanceof IntGetter) {
return (ContextualGetter) new FieldMapperIntGetterAdapter((Getter super S, Integer>) getter);
}
if (getter instanceof LongGetter) {
return (ContextualGetter) new FieldMapperLongGetterAdapter((Getter super S, Long>) getter);
}
if (getter instanceof FloatGetter) {
return (ContextualGetter) new FieldMapperFloatGetterAdapter((Getter super S, Float>) getter);
}
if (getter instanceof DoubleGetter) {
return (ContextualGetter) new FieldMapperDoubleGetterAdapter((Getter super S, Double>) getter);
}
return new ContextualGetterAdapter(getter);
}
private static class FieldMapperBooleanGetterAdapter implements ContextualGetter, BooleanContextualGetter {
private final Getter super S, Boolean> getter;
private final BooleanGetter super S> pGetter;
public FieldMapperBooleanGetterAdapter(Getter super S, Boolean> getter) {
this.getter = getter;
this.pGetter = (BooleanGetter super S>) getter;
}
@Override
public Boolean get(S s, Context context) throws Exception {
return getter.get(s);
}
@Override
public boolean getBoolean(S s, Context mappingContext) throws Exception {
return pGetter.getBoolean(s);
}
}
private static class FieldMapperByteGetterAdapter implements ContextualGetter, ByteContextualGetter {
private final Getter super S, Byte> getter;
private final ByteGetter super S> pGetter;
public FieldMapperByteGetterAdapter(Getter super S, Byte> getter) {
this.getter = getter;
this.pGetter = (ByteGetter super S>) getter;
}
@Override
public Byte get(S s, Context context) throws Exception {
return getter.get(s);
}
@Override
public byte getByte(S s, Context mappingContext) throws Exception {
return pGetter.getByte(s);
}
}
private static class FieldMapperCharacterGetterAdapter implements ContextualGetter, CharacterContextualGetter {
private final Getter super S, Character> getter;
private final CharacterGetter super S> pGetter;
public FieldMapperCharacterGetterAdapter(Getter super S, Character> getter) {
this.getter = getter;
this.pGetter = (CharacterGetter super S>) getter;
}
@Override
public Character get(S s, Context context) throws Exception {
return getter.get(s);
}
@Override
public char getCharacter(S s, Context mappingContext) throws Exception {
return pGetter.getCharacter(s);
}
}
private static class FieldMapperShortGetterAdapter implements ContextualGetter, ShortContextualGetter {
private final Getter super S, Short> getter;
private final ShortGetter super S> pGetter;
public FieldMapperShortGetterAdapter(Getter super S, Short> getter) {
this.getter = getter;
this.pGetter = (ShortGetter super S>) getter;
}
@Override
public Short get(S s, Context context) throws Exception {
return getter.get(s);
}
@Override
public short getShort(S s, Context mappingContext) throws Exception {
return pGetter.getShort(s);
}
}
private static class FieldMapperIntGetterAdapter implements ContextualGetter, IntContextualGetter {
private final Getter super S, Integer> getter;
private final IntGetter super S> pGetter;
public FieldMapperIntGetterAdapter(Getter super S, Integer> getter) {
this.getter = getter;
this.pGetter = (IntGetter super S>) getter;
}
@Override
public Integer get(S s, Context context) throws Exception {
return getter.get(s);
}
@Override
public int getInt(S s, Context mappingContext) throws Exception {
return pGetter.getInt(s);
}
}
private static class FieldMapperLongGetterAdapter implements ContextualGetter, LongContextualGetter {
private final Getter super S, Long> getter;
private final LongGetter super S> pGetter;
public FieldMapperLongGetterAdapter(Getter super S, Long> getter) {
this.getter = getter;
this.pGetter = (LongGetter super S>) getter;
}
@Override
public Long get(S s, Context context) throws Exception {
return getter.get(s);
}
@Override
public long getLong(S s, Context mappingContext) throws Exception {
return pGetter.getLong(s);
}
}
private static class FieldMapperFloatGetterAdapter implements ContextualGetter, FloatContextualGetter {
private final Getter super S, Float> getter;
private final FloatGetter super S> pGetter;
public FieldMapperFloatGetterAdapter(Getter super S, Float> getter) {
this.getter = getter;
this.pGetter = (FloatGetter super S>) getter;
}
@Override
public Float get(S s, Context context) throws Exception {
return getter.get(s);
}
@Override
public float getFloat(S s, Context mappingContext) throws Exception {
return pGetter.getFloat(s);
}
}
private static class FieldMapperDoubleGetterAdapter implements ContextualGetter, DoubleContextualGetter {
private final Getter super S, Double> getter;
private final DoubleGetter super S> pGetter;
public FieldMapperDoubleGetterAdapter(Getter super S, Double> getter) {
this.getter = getter;
this.pGetter = (DoubleGetter super S>) getter;
}
@Override
public Double get(S s, Context context) throws Exception {
return getter.get(s);
}
@Override
public double getDouble(S s, Context mappingContext) throws Exception {
return pGetter.getDouble(s);
}
}
public static BooleanContextualGetter super S> of(final BooleanGetter super S> getter) {
return new BooleanContextualGetterAdapter(getter);
}
private static class BooleanContextualGetterAdapter implements BooleanContextualGetter {
private final BooleanGetter super S> getter;
public BooleanContextualGetterAdapter(BooleanGetter super S> getter) {
this.getter = getter;
}
@Override
public boolean getBoolean(S s, Context mappingContext) throws Exception {
return getter.getBoolean(s);
}
}
public static ByteContextualGetter super S> of(final ByteGetter super S> getter) {
return new ByteContextualGetterAdapter(getter);
}
private static class ByteContextualGetterAdapter implements ByteContextualGetter {
private final ByteGetter super S> getter;
public ByteContextualGetterAdapter(ByteGetter super S> getter) {
this.getter = getter;
}
@Override
public byte getByte(S s, Context mappingContext) throws Exception {
return getter.getByte(s);
}
}
public static CharacterContextualGetter super S> of(final CharacterGetter super S> getter) {
return new CharacterContextualGetterAdapter(getter);
}
private static class CharacterContextualGetterAdapter implements CharacterContextualGetter {
private final CharacterGetter super S> getter;
public CharacterContextualGetterAdapter(CharacterGetter super S> getter) {
this.getter = getter;
}
@Override
public char getCharacter(S s, Context mappingContext) throws Exception {
return getter.getCharacter(s);
}
}
public static ShortContextualGetter super S> of(final ShortGetter super S> getter) {
return new ShortContextualGetterAdapter(getter);
}
private static class ShortContextualGetterAdapter implements ShortContextualGetter {
private final ShortGetter super S> getter;
public ShortContextualGetterAdapter(ShortGetter super S> getter) {
this.getter = getter;
}
@Override
public short getShort(S s, Context mappingContext) throws Exception {
return getter.getShort(s);
}
}
public static IntContextualGetter super S> of(final IntGetter super S> getter) {
return new IntContextualGetterAdapter(getter);
}
private static class IntContextualGetterAdapter implements IntContextualGetter {
private final IntGetter super S> getter;
public IntContextualGetterAdapter(IntGetter super S> getter) {
this.getter = getter;
}
@Override
public int getInt(S s, Context mappingContext) throws Exception {
return getter.getInt(s);
}
}
public static LongContextualGetter super S> of(final LongGetter super S> getter) {
return new LongContextualGetterAdapter(getter);
}
private static class LongContextualGetterAdapter implements LongContextualGetter {
private final LongGetter super S> getter;
public LongContextualGetterAdapter(LongGetter super S> getter) {
this.getter = getter;
}
@Override
public long getLong(S s, Context mappingContext) throws Exception {
return getter.getLong(s);
}
}
public static FloatContextualGetter super S> of(final FloatGetter super S> getter) {
return new FloatContextualGetterAdapter(getter);
}
private static class FloatContextualGetterAdapter implements FloatContextualGetter {
private final FloatGetter super S> getter;
public FloatContextualGetterAdapter(FloatGetter super S> getter) {
this.getter = getter;
}
@Override
public float getFloat(S s, Context mappingContext) throws Exception {
return getter.getFloat(s);
}
}
public static DoubleContextualGetter super S> of(final DoubleGetter super S> getter) {
return new DoubleContextualGetterAdapter(getter);
}
private static class DoubleContextualGetterAdapter implements DoubleContextualGetter {
private final DoubleGetter super S> getter;
public DoubleContextualGetterAdapter(DoubleGetter super S> getter) {
this.getter = getter;
}
@Override
public double getDouble(S s, Context mappingContext) throws Exception {
return getter.getDouble(s);
}
}
}