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

org.simpleflatmapper.converter.impl.time.MultiDateTimeFormatterConverter 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: 9.0.2
Show newest version
package org.simpleflatmapper.converter.impl.time;

import org.simpleflatmapper.converter.Converter;

import java.time.format.DateTimeParseException;

public class MultiDateTimeFormatterConverter implements Converter {
    private final Converter[] converters;

    public MultiDateTimeFormatterConverter(Converter[] converters) {
        this.converters = converters;
    }

    @Override
    public O convert(I in) throws Exception {
        for(int i = converters.length - 1; i >= 0; i--) {
            Converter converter = converters[i];
            try {
                return converter.convert(in);
            } catch (DateTimeParseException e) {
                // ignore
            }
        }
        throw new DateTimeParseException("Unable to parse " + in,  String.valueOf(in), 0);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy