org.simpleflatmapper.converter.impl.time.JavaTimeConverterFactoryProducer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sfm-converter Show documentation
Show all versions of sfm-converter Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
package org.simpleflatmapper.converter.impl.time;
import org.simpleflatmapper.converter.AbstractConverterFactory;
import org.simpleflatmapper.converter.AbstractConverterFactoryProducer;
import org.simpleflatmapper.converter.Converter;
import org.simpleflatmapper.converter.ConverterFactory;
import org.simpleflatmapper.converter.ConvertingTypes;
import org.simpleflatmapper.converter.ToStringConverter;
import org.simpleflatmapper.util.Consumer;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.Temporal;
import java.util.Date;
public class JavaTimeConverterFactoryProducer extends AbstractConverterFactoryProducer {
@Override
public void produce(Consumer super ConverterFactory, ?>> consumer) {
constantConverter(consumer, Instant.class, Date.class, new JavaInstantTojuDateConverter());
factoryConverter(consumer, new AbstractConverterFactory(LocalDateTime.class, Date.class) {
@Override
public Converter super LocalDateTime, ? extends Date> newConverter(ConvertingTypes targetedTypes, Object... params) {
return new JavaLocalDateTimeTojuDateConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractConverterFactory(LocalDate.class, Date.class) {
@Override
public Converter super LocalDate, ? extends Date> newConverter(ConvertingTypes targetedTypes, Object... params) {
return new JavaLocalDateTojuDateConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractConverterFactory(LocalTime.class, Date.class) {
@Override
public Converter super LocalTime, ? extends Date> newConverter(ConvertingTypes targetedTypes, Object... params) {
return new JavaLocalTimeTojuDateConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
constantConverter(consumer, ZonedDateTime.class, Date.class, new JavaZonedDateTimeTojuDateConverter());
constantConverter(consumer, OffsetDateTime.class, Date.class, new JavaOffsetDateTimeTojuDateConverter());
constantConverter(consumer, OffsetTime.class, Date.class, new JavaOffsetTimeTojuDateConverter());
factoryConverter(consumer, new AbstractConverterFactory(YearMonth.class, Date.class) {
@Override
public Converter super YearMonth, ? extends Date> newConverter(ConvertingTypes targetedTypes, Object... params) {
return new JavaYearMonthTojuDateConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractConverterFactory(Year.class, Date.class) {
@Override
public Converter super Year, ? extends Date> newConverter(ConvertingTypes targetedTypes, Object... params) {
return new JavaYearTojuDateConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
constantConverter(consumer, Date.class, Instant.class, new DateToJavaInstantConverter());
factoryConverter(consumer, new AbstractConverterFactory(Date.class, LocalDateTime.class) {
@Override
public Converter super Date, ? extends LocalDateTime> newConverter(ConvertingTypes targetedTypes, Object... params) {
return new DateToJavaLocalDateTimeConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractConverterFactory(Date.class, LocalDate.class) {
@Override
public Converter super Date, ? extends LocalDate> newConverter(ConvertingTypes targetedTypes, Object... params) {
return new DateToJavaLocalDateConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractConverterFactory(Date.class, LocalTime.class) {
@Override
public Converter super Date, ? extends LocalTime> newConverter(ConvertingTypes targetedTypes, Object... params) {
return new DateToJavaLocalTimeConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractConverterFactory(Date.class, ZonedDateTime.class) {
@Override
public Converter super Date, ? extends ZonedDateTime> newConverter(ConvertingTypes targetedTypes, Object... params) {
return new DateToJavaZonedDateTimeConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractConverterFactory(Date.class, OffsetDateTime.class) {
@Override
public Converter super Date, ? extends OffsetDateTime> newConverter(ConvertingTypes targetedTypes, Object... params) {
return new DateToJavaOffsetDateTimeConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractConverterFactory(Date.class, OffsetTime.class) {
@Override
public Converter super Date, ? extends OffsetTime> newConverter(ConvertingTypes targetedTypes, Object... params) {
return new DateToJavaOffsetTimeConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractConverterFactory(Date.class, YearMonth.class) {
@Override
public Converter super Date, ? extends YearMonth> newConverter(ConvertingTypes targetedTypes, Object... params) {
return new DateToJavaYearMonthConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractConverterFactory(Date.class, Year.class) {
@Override
public Converter super Date, ? extends Year> newConverter(ConvertingTypes targetedTypes, Object... params) {
return new DateToJavaYearConverter(JavaTimeHelper.getZoneIdOrDefault(params));
}
});
factoryConverter(consumer, new AbstractConverterFactory
© 2015 - 2025 Weber Informatics LLC | Privacy Policy