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 Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractDateTimeConverter(DateTimeFormatter formatter) Creates a new instance that throws aConversionExceptionif an error occurs.protectedAbstractDateTimeConverter(DateTimeFormatter formatter, @Nullable TemporalAccessor defaultValue) Creates a new instance that returns a default value if an error occurs. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddParsers(DateTimeFormatter... parsers) Adds specified parsers to the temporal value parsers.voidaddParsers(Collection<DateTimeFormatter> parsers) Adds specified parsers to the temporal value parsers.protected StringconvertToString(Object value) protected <T> TconvertToType(Class<T> type, Object value) protected abstract <T extends TemporalAccessor>
TfromTemporalAccessor(Class<T> type, TemporalAccessor value) Converts theTemporalAccessorpassed as argument to the specified type.protected abstract Class<?>Returns the temporal value formatter and default parser.protected org.slf4j.LoggerReturns the logger for this instanceReturns the extra temporal value parsers.protected <T extends TemporalAccessor>
Tparse(Class<T> type, DateTimeFormatter parser, String value) Tries to parse aTemporalAccessorof the specified type from the specified value.protected <T extends TemporalAccessor>
TparseString(Class<T> type, String value) Tries to parse aTemporalAccessorof the specified type from the specifiedStringvalue.voidsetParsers(DateTimeFormatter... parsers) Sets the temporal value parsers.voidsetParsers(Collection<DateTimeFormatter> parsers) Sets the temporal value parsers.Methods inherited from class org.apache.commons.beanutils.converters.AbstractConverter
conversionException, convert, convertArray, getDefault, handleError, handleMissing, isUseDefault, setDefaultValue, toString
-
Constructor Details
-
AbstractDateTimeConverter
Creates a new instance that throws aConversionExceptionif 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 parserdefaultValue- The default value to be returned if the value to be converted is missing or an error occurs converting the value
-
-
Method Details
-
getFormatter
Returns the temporal value formatter and default parser.- Returns:
- The temporal value formatter and default parser
-
getParsers
Returns the extra temporal value parsers.- Returns:
- The extra temporal value parsers
-
setParsers
Sets the temporal value parsers.- Parameters:
parsers- The temporal value parsers
-
setParsers
Sets the temporal value parsers.- Parameters:
parsers- The temporal value parsers
-
addParsers
Adds specified parsers to the temporal value parsers.- Parameters:
parsers- The temporal value parsers to add
-
addParsers
Adds specified parsers to the temporal value parsers.- Parameters:
parsers- The temporal value parsers to add
-
getDefaultType
- Specified by:
getDefaultTypein classorg.apache.commons.beanutils.converters.AbstractConverter
-
convertToType
- Specified by:
convertToTypein classorg.apache.commons.beanutils.converters.AbstractConverter
-
parseString
Tries to parse aTemporalAccessorof the specified type from the specifiedStringvalue. Tries the parses in order callingparse(Class, DateTimeFormatter, String). If all parsers fail throws exception thrown by first parser.- Type Parameters:
T- The expected type ofTemporalAccessor- Parameters:
type- The expected type ofTemporalAccessorvalue- The value to parse- Returns:
- The parsed
TemporalAccessorof 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 aTemporalAccessorof the specified type from the specified value.- Type Parameters:
T- The expected type ofTemporalAccessor- Parameters:
type- The expected type ofTemporalAccessorparser- The parser to use for parsing the valuevalue- The value to parse- Returns:
- The parsed
TemporalAccessorof 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 theTemporalAccessorpassed as argument to the specified type.- Type Parameters:
T- The expected type ofTemporalAccessor- Parameters:
type- The expected type ofTemporalAccessorvalue- TheTemporalAccessorto convert to the expected type- Returns:
- The converted
TemporalAccessorof the expected type - Throws:
DateTimeException- If the value cannot be converted
-
convertToString
- Overrides:
convertToStringin classorg.apache.commons.beanutils.converters.AbstractConverter
-
getLogger
protected org.slf4j.Logger getLogger()Returns the logger for this instance- Returns:
- The logger for this instance
-