use of org.simpleflatmapper.map.fieldmapper.IntFieldMapper in project SimpleFlatMapper by arnaudroger.
the class FieldMapperToAppendableFactory method newFieldMapper.
@Override
@SuppressWarnings("unchecked")
public <S, P> FieldMapper<S, Appendable> newFieldMapper(PropertyMapping<S, P, CsvColumnKey, FieldMapperColumnDefinition<CsvColumnKey>> pm, MappingContextFactoryBuilder builder, MapperBuilderErrorHandler mappingErrorHandler) {
if (pm == null)
throw new NullPointerException("pm is null");
Getter<? super S, ? extends P> getter;
Getter<?, ?> customGetter = pm.getColumnDefinition().getCustomGetterFrom(pm.getPropertyMeta().getOwnerType());
if (customGetter != null) {
getter = (Getter<S, P>) customGetter;
} else {
getter = pm.getPropertyMeta().getGetter();
}
ColumnDefinition<CsvColumnKey, ?> columnDefinition = pm.getColumnDefinition();
Type type = pm.getPropertyMeta().getPropertyType();
if (TypeHelper.isPrimitive(type) && !columnDefinition.has(FormatProperty.class)) {
if (getter instanceof BooleanGetter) {
return new BooleanFieldMapper<S, Appendable>((BooleanGetter) getter, new BooleanAppendableSetter(cellWriter));
} else if (getter instanceof ByteGetter) {
return new ByteFieldMapper<S, Appendable>((ByteGetter) getter, new ByteAppendableSetter(cellWriter));
} else if (getter instanceof CharacterGetter) {
return new CharacterFieldMapper<S, Appendable>((CharacterGetter) getter, new CharacterAppendableSetter(cellWriter));
} else if (getter instanceof ShortGetter) {
return new ShortFieldMapper<S, Appendable>((ShortGetter) getter, new ShortAppendableSetter(cellWriter));
} else if (getter instanceof IntGetter) {
return new IntFieldMapper<S, Appendable>((IntGetter) getter, new IntegerAppendableSetter(cellWriter));
} else if (getter instanceof LongGetter) {
return new LongFieldMapper<S, Appendable>((LongGetter) getter, new LongAppendableSetter(cellWriter));
} else if (getter instanceof FloatGetter) {
return new FloatFieldMapper<S, Appendable>((FloatGetter) getter, new FloatAppendableSetter(cellWriter));
} else if (getter instanceof DoubleGetter) {
return new DoubleFieldMapper<S, Appendable>((DoubleGetter) getter, new DoubleAppendableSetter(cellWriter));
}
}
Setter<Appendable, ? super P> setter = null;
if (TypeHelper.isEnum(type) && columnDefinition.has(EnumOrdinalFormatProperty.class)) {
setter = (Setter) new EnumOrdinalAppendableSetter(cellWriter);
}
Format format = null;
if (columnDefinition.has(FormatProperty.class)) {
format = columnDefinition.lookFor(FormatProperty.class).format();
} else if (TypeHelper.areEquals(type, Date.class)) {
String df = DEFAULT_DATE_FORMAT;
DateFormatProperty dfp = columnDefinition.lookFor(DateFormatProperty.class);
if (dfp != null) {
df = dfp.get();
}
format = new SimpleDateFormat(df);
}
if (format != null) {
final Format f = format;
builder.addSupplier(pm.getColumnKey().getIndex(), new CloneFormatSupplier(f));
return new FormatingAppender<S>(getter, new MappingContextFormatGetter<S>(pm.getColumnKey().getIndex()), cellWriter);
}
if (setter == null) {
setter = getSetter(pm, cellWriter);
}
if (setter == null) {
Converter<? super P, ? extends CharSequence> converter = converterService.findConverter(pm.getPropertyMeta().getPropertyType(), CharSequence.class, columnDefinition != null ? columnDefinition.properties() : new Object[0]);
if (converter != null) {
return new ConvertingAppender<S, P>(getter, converter, cellWriter);
}
}
return new FieldMapperImpl<S, Appendable, P>(getter, setter);
}
Aggregations