All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sfm.csv.impl.writer.JodaTimeFormattingAppender Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

There is a newer version: 2.9.8
Show newest version
package org.sfm.csv.impl.writer;

import org.joda.time.ReadableInstant;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.sfm.csv.CellWriter;
import org.sfm.map.FieldMapper;
import org.sfm.map.MappingContext;
import org.sfm.reflect.Getter;


public class JodaTimeFormattingAppender implements FieldMapper {
    private final CellWriter cellWriter;
    private final DateTimeFormatter formatter;
    private final Getter getter;

    @SuppressWarnings("unchecked")
    public JodaTimeFormattingAppender(Getter getter, DateTimeFormatter formatter, CellWriter cellWriter) {
        this.getter = (Getter)getter;
        this.formatter = formatter;
        this.cellWriter = cellWriter;
    }

    @SuppressWarnings("unchecked")
    public JodaTimeFormattingAppender(Getter getter, String pattern, CellWriter cellWriter) {
        this.getter = (Getter)getter;
        this.formatter = DateTimeFormat.forPattern(pattern);
        this.cellWriter = cellWriter;
    }

    @Override
    public void mapTo(T source, Appendable target, MappingContext context) throws Exception {
        cellWriter.writeValue(formatter.print(getter.get(source)), target);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy