Class AbstractDateTimeConverter

java.lang.Object
org.apache.commons.beanutils.converters.AbstractConverter
dev.orne.beans.converters.AbstractDateTimeConverter
All Implemented Interfaces:
org.apache.commons.beanutils.Converter
Direct Known Subclasses:
DayOfWeekConverter, InstantConverter, LocalDateConverter, LocalDateTimeConverter, LocalTimeConverter, MonthConverter, MonthDayConverter, OffsetDateTimeConverter, OffsetTimeConverter, YearConverter, YearMonthConverter, ZonedDateTimeConverter, ZoneOffsetConverter

@API(status=STABLE, since="0.1") public abstract class AbstractDateTimeConverter extends org.apache.commons.beanutils.converters.AbstractConverter
Implementation of Converter that converts LocalDate instances to and from String using ISO-8601 as String representation by default.
Since:
0.1
Version:
1.0, 2020-05
Author:
(w) Iker Hernaez
  • Constructor Details

    • AbstractDateTimeConverter

      protected AbstractDateTimeConverter(DateTimeFormatter formatter)
      Creates a new instance that throws a ConversionException if an error occurs.
      Parameters:
      formatter - The temporal value formatter and default parser
    • AbstractDateTimeConverter

      protected AbstractDateTimeConverter(DateTimeFormatter formatter, @Nullable TemporalAccessor defaultValue)
      Creates a new instance that returns a default value if an error occurs.
      Parameters:
      formatter - The temporal value formatter and default parser
      defaultValue - The default value to be returned if the value to be converted is missing or an error occurs converting the value
  • Method Details

    • getFormatter

      public DateTimeFormatter getFormatter()
      Returns the temporal value formatter and default parser.
      Returns:
      The temporal value formatter and default parser
    • getParsers

      public List<DateTimeFormatter> getParsers()
      Returns the extra temporal value parsers.
      Returns:
      The extra temporal value parsers
    • setParsers

      public void setParsers(DateTimeFormatter... parsers)
      Sets the temporal value parsers.
      Parameters:
      parsers - The temporal value parsers
    • setParsers

      public void setParsers(Collection<DateTimeFormatter> parsers)
      Sets the temporal value parsers.
      Parameters:
      parsers - The temporal value parsers
    • addParsers

      public void addParsers(DateTimeFormatter... parsers)
      Adds specified parsers to the temporal value parsers.
      Parameters:
      parsers - The temporal value parsers to add
    • addParsers

      public void addParsers(Collection<DateTimeFormatter> parsers)
      Adds specified parsers to the temporal value parsers.
      Parameters:
      parsers - The temporal value parsers to add
    • getDefaultType

      protected abstract Class<?> getDefaultType()
      Specified by:
      getDefaultType in class org.apache.commons.beanutils.converters.AbstractConverter
    • convertToType

      protected <T> T convertToType(Class<T> type, Object value)
      Specified by:
      convertToType in class org.apache.commons.beanutils.converters.AbstractConverter
    • parseString

      protected <T extends TemporalAccessor> T parseString(Class<T> type, String value)
      Tries to parse a TemporalAccessor of the specified type from the specified String value. Tries the parses in order calling parse(Class, DateTimeFormatter, String). If all parsers fail throws exception thrown by first parser.
      Type Parameters:
      T - The expected type of TemporalAccessor
      Parameters:
      type - The expected type of TemporalAccessor
      value - The value to parse
      Returns:
      The parsed TemporalAccessor of the expected type
      Throws:
      DateTimeException - If the value cannot be parsed
    • parse

      protected <T extends TemporalAccessor> T parse(Class<T> type, DateTimeFormatter parser, String value)
      Tries to parse a TemporalAccessor of the specified type from the specified value.
      Type Parameters:
      T - The expected type of TemporalAccessor
      Parameters:
      type - The expected type of TemporalAccessor
      parser - The parser to use for parsing the value
      value - The value to parse
      Returns:
      The parsed TemporalAccessor of the expected type
      Throws:
      DateTimeException - If the value cannot be parsed
    • fromTemporalAccessor

      protected abstract <T extends TemporalAccessor> T fromTemporalAccessor(Class<T> type, TemporalAccessor value)
      Converts the TemporalAccessor passed as argument to the specified type.
      Type Parameters:
      T - The expected type of TemporalAccessor
      Parameters:
      type - The expected type of TemporalAccessor
      value - The TemporalAccessor to convert to the expected type
      Returns:
      The converted TemporalAccessor of the expected type
      Throws:
      DateTimeException - If the value cannot be converted
    • convertToString

      protected String convertToString(Object value)
      Overrides:
      convertToString in class org.apache.commons.beanutils.converters.AbstractConverter
    • getLogger

      protected org.slf4j.Logger getLogger()
      Returns the logger for this instance
      Returns:
      The logger for this instance