org.simpleflatmapper.map.setter.ContextualSetterAdapter 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.setter;
import org.simpleflatmapper.converter.Context;
import org.simpleflatmapper.reflect.Setter;
import org.simpleflatmapper.reflect.primitive.BooleanSetter;
import org.simpleflatmapper.reflect.primitive.ByteSetter;
import org.simpleflatmapper.reflect.primitive.CharacterSetter;
import org.simpleflatmapper.reflect.primitive.DoubleSetter;
import org.simpleflatmapper.reflect.primitive.FloatSetter;
import org.simpleflatmapper.reflect.primitive.IntSetter;
import org.simpleflatmapper.reflect.primitive.LongSetter;
import org.simpleflatmapper.reflect.primitive.ShortSetter;
public class ContextualSetterAdapter implements ContextualSetter {
private final Setter setter;
private ContextualSetterAdapter(Setter setter) {
this.setter = setter;
}
public static ContextualSetter of(Setter setter) {
if (setter == null) return null;
if (setter instanceof BooleanSetter) {
return (ContextualSetter) new BooleanContextualSetterAdapter((Setter)setter);
}
if (setter instanceof ByteSetter) {
return (ContextualSetter) new ByteContextualSetterAdapter((Setter)setter);
}
if (setter instanceof CharacterSetter) {
return (ContextualSetter) new CharacterContextualSetterAdapter((Setter)setter);
}
if (setter instanceof ShortSetter) {
return (ContextualSetter) new ShortContextualSetterAdapter((Setter)setter);
}
if (setter instanceof IntSetter) {
return (ContextualSetter) new IntegerContextualSetterAdapter((Setter)setter);
}
if (setter instanceof LongSetter) {
return (ContextualSetter) new LongContextualSetterAdapter((Setter)setter);
}
if (setter instanceof FloatSetter) {
return (ContextualSetter) new FloatContextualSetterAdapter((Setter)setter);
}
if (setter instanceof DoubleSetter) {
return (ContextualSetter) new DoubleContextualSetterAdapter((Setter)setter);
}
return new ContextualSetterAdapter(setter);
}
@Override
public void set(T target, P value, Context context) throws Exception {
setter.set(target, value);
}
private static class BooleanContextualSetterAdapter implements ContextualSetter, BooleanContextualSetter {
private final Setter setter;
private final BooleanSetter psetter;
private BooleanContextualSetterAdapter(Setter setter) {
this.setter = setter;
this.psetter = (BooleanSetter) setter;
}
@Override
public void setBoolean(T target, boolean value, Context context) throws Exception {
psetter.setBoolean(target, value);
}
@Override
public void set(T target, Boolean value, Context context) throws Exception {
setter.set(target, value);
}
}
private static class ByteContextualSetterAdapter implements ContextualSetter, ByteContextualSetter {
private final Setter setter;
private final ByteSetter psetter;
private ByteContextualSetterAdapter(Setter setter) {
this.setter = setter;
this.psetter = (ByteSetter) setter;
}
@Override
public void setByte(T target, byte value, Context context) throws Exception {
psetter.setByte(target, value);
}
@Override
public void set(T target, Byte value, Context context) throws Exception {
setter.set(target, value);
}
}
private static class CharacterContextualSetterAdapter implements ContextualSetter, CharacterContextualSetter {
private final Setter setter;
private final CharacterSetter psetter;
private CharacterContextualSetterAdapter(Setter setter) {
this.setter = setter;
this.psetter = (CharacterSetter) setter;
}
@Override
public void setCharacter(T target, char value, Context context) throws Exception {
psetter.setCharacter(target, value);
}
@Override
public void set(T target, Character value, Context context) throws Exception {
setter.set(target, value);
}
}
private static class ShortContextualSetterAdapter implements ContextualSetter, ShortContextualSetter {
private final Setter setter;
private final ShortSetter psetter;
private ShortContextualSetterAdapter(Setter setter) {
this.setter = setter;
this.psetter = (ShortSetter) setter;
}
@Override
public void setShort(T target, short value, Context context) throws Exception {
psetter.setShort(target, value);
}
@Override
public void set(T target, Short value, Context context) throws Exception {
setter.set(target, value);
}
}
private static class IntegerContextualSetterAdapter implements ContextualSetter, IntContextualSetter {
private final Setter setter;
private final IntSetter psetter;
private IntegerContextualSetterAdapter(Setter setter) {
this.setter = setter;
this.psetter = (IntSetter) setter;
}
@Override
public void setInt(T target, int value, Context context) throws Exception {
psetter.setInt(target, value);
}
@Override
public void set(T target, Integer value, Context context) throws Exception {
setter.set(target, value);
}
}
private static class LongContextualSetterAdapter implements ContextualSetter, LongContextualSetter {
private final Setter setter;
private final LongSetter psetter;
private LongContextualSetterAdapter(Setter setter) {
this.setter = setter;
this.psetter = (LongSetter) setter;
}
@Override
public void setLong(T target, long value, Context context) throws Exception {
psetter.setLong(target, value);
}
@Override
public void set(T target, Long value, Context context) throws Exception {
setter.set(target, value);
}
}
private static class FloatContextualSetterAdapter implements ContextualSetter, FloatContextualSetter {
private final Setter setter;
private final FloatSetter psetter;
private FloatContextualSetterAdapter(Setter setter) {
this.setter = setter;
this.psetter = (FloatSetter) setter;
}
@Override
public void setFloat(T target, float value, Context context) throws Exception {
psetter.setFloat(target, value);
}
@Override
public void set(T target, Float value, Context context) throws Exception {
setter.set(target, value);
}
}
private static class DoubleContextualSetterAdapter implements ContextualSetter, DoubleContextualSetter {
private final Setter setter;
private final DoubleSetter psetter;
private DoubleContextualSetterAdapter(Setter setter) {
this.setter = setter;
this.psetter = (DoubleSetter) setter;
}
@Override
public void setDouble(T target, double value, Context context) throws Exception {
psetter.setDouble(target, value);
}
@Override
public void set(T target, Double value, Context context) throws Exception {
setter.set(target, value);
}
}
public static BooleanContextualSetter super T> of(final BooleanSetter super T> setter) {
return new PrimitiveBooleanContextualSetterAdapter(setter);
}
private static class PrimitiveBooleanContextualSetterAdapter implements BooleanContextualSetter {
private final BooleanSetter super T> setter;
public PrimitiveBooleanContextualSetterAdapter(BooleanSetter super T> setter) {
this.setter = setter;
}
@Override
public void setBoolean(T target, boolean value, Context context) throws Exception {
setter.setBoolean(target, value);
}
}
public static ByteContextualSetter super T> of(final ByteSetter super T> setter) {
return new PrimitiveByteContextualSetterAdapter(setter);
}
private static class PrimitiveByteContextualSetterAdapter implements ByteContextualSetter {
private final ByteSetter super T> setter;
public PrimitiveByteContextualSetterAdapter(ByteSetter super T> setter) {
this.setter = setter;
}
@Override
public void setByte(T target, byte value, Context context) throws Exception {
setter.setByte(target, value);
}
}
public static ShortContextualSetter super T> of(final ShortSetter super T> setter) {
return new PrimitiveShortContextualSetterAdapter(setter);
}
private static class PrimitiveShortContextualSetterAdapter implements ShortContextualSetter {
private final ShortSetter super T> setter;
public PrimitiveShortContextualSetterAdapter(ShortSetter super T> setter) {
this.setter = setter;
}
@Override
public void setShort(T target, short value, Context context) throws Exception {
setter.setShort(target, value);
}
}
public static IntContextualSetter super T> of(final IntSetter super T> setter) {
return new PrimitiveIntContextualSetterAdapter(setter);
}
private static class PrimitiveIntContextualSetterAdapter implements IntContextualSetter {
private final IntSetter super T> setter;
public PrimitiveIntContextualSetterAdapter(IntSetter super T> setter) {
this.setter = setter;
}
@Override
public void setInt(T target, int value, Context context) throws Exception {
setter.setInt(target, value);
}
}
public static LongContextualSetter super T> of(final LongSetter super T> setter) {
return new PrimitiveLongContextualSetterAdapter(setter);
}
private static class PrimitiveLongContextualSetterAdapter implements LongContextualSetter {
private final LongSetter super T> setter;
public PrimitiveLongContextualSetterAdapter(LongSetter super T> setter) {
this.setter = setter;
}
@Override
public void setLong(T target, long value, Context context) throws Exception {
setter.setLong(target, value);
}
}
public static FloatContextualSetter super T> of(final FloatSetter super T> setter) {
return new PrimitiveFloatContextualSetterAdapter(setter);
}
private static class PrimitiveFloatContextualSetterAdapter implements FloatContextualSetter {
private final FloatSetter super T> setter;
public PrimitiveFloatContextualSetterAdapter(FloatSetter super T> setter) {
this.setter = setter;
}
@Override
public void setFloat(T target, float value, Context context) throws Exception {
setter.setFloat(target, value);
}
}
public static DoubleContextualSetter super T> of(final DoubleSetter super T> setter) {
return new PrimitiveDoubleContextualSetterAdapter(setter);
}
private static class PrimitiveDoubleContextualSetterAdapter implements DoubleContextualSetter {
private final DoubleSetter super T> setter;
public PrimitiveDoubleContextualSetterAdapter(DoubleSetter super T> setter) {
this.setter = setter;
}
@Override
public void setDouble(T target, double value, Context context) throws Exception {
setter.setDouble(target, value);
}
}
public static CharacterContextualSetter super T> of(final CharacterSetter super T> setter) {
return new PrimitiveCharacterContextualSetterAdapter(setter);
}
private static class PrimitiveCharacterContextualSetterAdapter implements CharacterContextualSetter {
private final CharacterSetter super T> setter;
public PrimitiveCharacterContextualSetterAdapter(CharacterSetter super T> setter) {
this.setter = setter;
}
@Override
public void setCharacter(T target, char value, Context context) throws Exception {
setter.setCharacter(target, value);
}
}
}