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

org.simpleflatmapper.converter.impl.time.MultiDateTimeFormatterConverter Maven / Gradle / Ivy

package org.simpleflatmapper.converter.impl.time;

import org.simpleflatmapper.converter.Context;
import org.simpleflatmapper.converter.ContextualConverter;

import java.time.format.DateTimeParseException;

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

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

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy