java.lang.Object
de.iip_ecosphere.platform.connectors.formatter.FormatCache

public class FormatCache extends Object
Caches formatter instances.
Author:
Holger Eichelberger, SSE
  • Field Details

  • Constructor Details

    • FormatCache

      public FormatCache()
  • Method Details

    • registerConverter

      public static void registerConverter(FormatCache.DateConverter<?> converter)
      Registers an additional converter.
      Parameters:
      converter - the converter
    • registerFormat

      public static void registerFormat(String name, String pattern)
      Registers a default format for SimpleDateFormat.
      Parameters:
      name - the symbolic name of the format
      pattern - the pattern format to apply
      Throws:
      IllegalArgumentException - if pattern is illegal
    • format

      public static String format(Date data, String format) throws IOException
      Formats a date object to a given format.
      Parameters:
      data - the data/date
      format - the format, may be from SimpleDateFormat or ISO8601_FORMAT
      Returns:
      if no format can be constructed
      Throws:
      IOException - if formatting is not possible or the format is unknown
    • convertToDate

      private static <T> Date convertToDate(Class<T> cls, Object data)
      Uses one of the registered data converters to convert data.
      Type Parameters:
      T - the type of data
      Parameters:
      cls - the type of data
      data - the data (must not be null)
      Returns:
      the converted instance, may be null if there is no conversion
    • parse

      public static Date parse(Object data, String format) throws IOException
      Parses a date from the given data for the specified format.
      Parameters:
      data - the data (may be null, the the result will be null)
      format - the format may be from SimpleDateFormat or ISO8601_FORMAT
      Returns:
      the parsed date
      Throws:
      IOException - if parsing is not possible or the format is unknown
    • getDateFormatter

      public static SimpleDateFormat getDateFormatter(String format) throws IOException
      Returns a (cached) simple date formatter.
      Parameters:
      format - the format for the requested formatter for a string for SimpleDateFormat
      Returns:
      the formatter instance
      Throws:
      IOException - if format is not valid
    • toLocalDateTime

      public static LocalDateTime toLocalDateTime(Date date)
      Converts a Date value to LocalDateTime using instant and the system default time zone.
      Parameters:
      date - the date to convert (may be null)
      Returns:
      the converted date (may be null)
    • toDate

      public static Date toDate(LocalDateTime date)
      Converts a LocalDateTime value to Date using instant and the system default time zone.
      Parameters:
      date - the date to convert (may be null)
      Returns:
      the converted date (may be null)