Package dev.orne.beans.converters
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 Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractDateTimeConverter(@NotNull DateTimeFormatter formatter) Creates a new instance that throws aConversionExceptionif an error occurs.protectedAbstractDateTimeConverter(@NotNull DateTimeFormatter formatter, TemporalAccessor defaultValue) Creates a new instance that returns a default value if an error occurs. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddParsers(@NotNull DateTimeFormatter... parsers) Adds specified parsers to the temporal value parsers.voidaddParsers(@NotNull Collection<DateTimeFormatter> parsers) Adds specified parsers to the temporal value parsers.protected StringconvertToString(Object value) protected <T> TconvertToType(@NotNull Class<T> type, Object value) protected abstract <T extends TemporalAccessor>
TfromTemporalAccessor(@NotNull Class<T> type, @NotNull TemporalAccessor value) Converts theTemporalAccessorpassed as argument to the specified type.protected abstract Class<?>@NotNull DateTimeFormatterReturns the temporal value formatter and default parser.protected @NotNull org.slf4j.LoggerReturns the logger for this instance@NotNull List<DateTimeFormatter>Returns the extra temporal value parsers.protected <T extends TemporalAccessor>
Tparse(@NotNull Class<T> type, @NotNull DateTimeFormatter parser, @NotNull String value) Tries to parse aTemporalAccessorof the specified type from the specified value.protected <T extends TemporalAccessor>
TparseString(@NotNull Class<T> type, @NotNull String value) Tries to parse aTemporalAccessorof the specified type from the specifiedStringvalue.voidsetParsers(@NotNull DateTimeFormatter... parsers) Sets the temporal value parsers.voidsetParsers(@NotNull 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(@NotNull @NotNull DateTimeFormatter formatter, 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
protected <T extends TemporalAccessor> T parseString(@NotNull @NotNull Class<T> type, @NotNull @NotNull String value) 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(@NotNull @NotNull Class<T> type, @NotNull @NotNull DateTimeFormatter parser, @NotNull @NotNull 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(@NotNull @NotNull Class<T> type, @NotNull @NotNull 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
@NotNull protected @NotNull org.slf4j.Logger getLogger()Returns the logger for this instance- Returns:
- The logger for this instance
-