Class FormatCache
java.lang.Object
de.iip_ecosphere.platform.connectors.formatter.FormatCache
Caches formatter instances.
- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn abstract basic date converter.static interfacePlugin to extend the date time conversion. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Map<Class<?>, FormatCache.DateConverter<?>> private static final Map<String, SimpleDateFormat> static final StringPre-defined known format for ISO8601. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T> DateconvertToDate(Class<T> cls, Object data) Uses one of the registered data converters to convertdata.static StringFormats a date object to a given format.static SimpleDateFormatgetDateFormatter(String format) Returns a (cached) simple date formatter.static DateParses a date from the givendatafor the specifiedformat.static voidregisterConverter(FormatCache.DateConverter<?> converter) Registers an additional converter.static voidregisterFormat(String name, String pattern) Registers a default format forSimpleDateFormat.static DatetoDate(LocalDateTime date) Converts aLocalDateTimevalue toDateusing instant and the system default time zone.static LocalDateTimetoLocalDateTime(Date date) Converts aDatevalue toLocalDateTimeusing instant and the system default time zone.
-
Field Details
-
ISO8601_FORMAT
Pre-defined known format for ISO8601.- See Also:
-
DATE_FORMATTER
-
CONVERTERS
-
-
Constructor Details
-
FormatCache
public FormatCache()
-
-
Method Details
-
registerConverter
Registers an additional converter.- Parameters:
converter- the converter
-
registerFormat
Registers a default format forSimpleDateFormat.- Parameters:
name- the symbolic name of the formatpattern- the pattern format to apply- Throws:
IllegalArgumentException- ifpatternis illegal
-
format
Formats a date object to a given format.- Parameters:
data- the data/dateformat- the format, may be fromSimpleDateFormatorISO8601_FORMAT- Returns:
- if no format can be constructed
- Throws:
IOException- if formatting is not possible or the format is unknown
-
convertToDate
Uses one of the registered data converters to convertdata.- Type Parameters:
T- the type ofdata- Parameters:
cls- the type ofdatadata- the data (must not be null)- Returns:
- the converted instance, may be null if there is no conversion
-
parse
Parses a date from the givendatafor the specifiedformat.- Parameters:
data- the data (may be null, the the result will be null)format- the format may be fromSimpleDateFormatorISO8601_FORMAT- Returns:
- the parsed date
- Throws:
IOException- if parsing is not possible or the format is unknown
-
getDateFormatter
Returns a (cached) simple date formatter.- Parameters:
format- the format for the requested formatter for a string forSimpleDateFormat- Returns:
- the formatter instance
- Throws:
IOException- ifformatis not valid
-
toLocalDateTime
Converts aDatevalue toLocalDateTimeusing instant and the system default time zone.- Parameters:
date- the date to convert (may be null)- Returns:
- the converted date (may be null)
-
toDate
Converts aLocalDateTimevalue toDateusing instant and the system default time zone.- Parameters:
date- the date to convert (may be null)- Returns:
- the converted date (may be null)
-