Class FormatCache<F extends Format>

java.lang.Object
org.apache.commons.lang3.time.FormatCache<F>

abstract class FormatCache<F extends Format> extends Object
FormatCache is a cache and factory for Formats.
Since:
3.0
  • Field Details

  • Constructor Details

    • FormatCache

      FormatCache()
  • Method Details

    • getInstance

      public F getInstance()
      Gets a formatter instance using the default pattern in the default time zone and locale.
      Returns:
      a date/time formatter
    • getInstance

      public F getInstance(String pattern, TimeZone timeZone, Locale locale)
      Gets a formatter instance using the specified pattern, time zone and locale.
      Parameters:
      pattern - SimpleDateFormat compatible pattern, non-null
      timeZone - the time zone, null means use the default TimeZone
      locale - the locale, null means use the default Locale
      Returns:
      a pattern based date/time formatter
      Throws:
      NullPointerException - if pattern is null
      IllegalArgumentException - if pattern is invalid
    • createInstance

      protected abstract F createInstance(String pattern, TimeZone timeZone, Locale locale)
      Create a format instance using the specified pattern, time zone and locale.
      Parameters:
      pattern - SimpleDateFormat compatible pattern, this will not be null.
      timeZone - time zone, this will not be null.
      locale - locale, this will not be null.
      Returns:
      a pattern based date/time formatter
      Throws:
      IllegalArgumentException - if pattern is invalid or null
    • getDateTimeInstance

      private F getDateTimeInstance(Integer dateStyle, Integer timeStyle, TimeZone timeZone, Locale locale)
      Gets a date/time formatter instance using the specified style, time zone and locale.
      Parameters:
      dateStyle - date style: FULL, LONG, MEDIUM, or SHORT, null indicates no date in format
      timeStyle - time style: FULL, LONG, MEDIUM, or SHORT, null indicates no time in format
      timeZone - optional time zone, overrides time zone of formatted date, null means use default Locale
      locale - optional locale, overrides system locale
      Returns:
      a localized standard date/time formatter
      Throws:
      IllegalArgumentException - if the Locale has no date/time pattern defined
    • getDateTimeInstance

      F getDateTimeInstance(int dateStyle, int timeStyle, TimeZone timeZone, Locale locale)
      Gets a date/time formatter instance using the specified style, time zone and locale.
      Parameters:
      dateStyle - date style: FULL, LONG, MEDIUM, or SHORT
      timeStyle - time style: FULL, LONG, MEDIUM, or SHORT
      timeZone - optional time zone, overrides time zone of formatted date, null means use default Locale
      locale - optional locale, overrides system locale
      Returns:
      a localized standard date/time formatter
      Throws:
      IllegalArgumentException - if the Locale has no date/time pattern defined
    • getDateInstance

      F getDateInstance(int dateStyle, TimeZone timeZone, Locale locale)
      Gets a date formatter instance using the specified style, time zone and locale.
      Parameters:
      dateStyle - date style: FULL, LONG, MEDIUM, or SHORT
      timeZone - optional time zone, overrides time zone of formatted date, null means use default Locale
      locale - optional locale, overrides system locale
      Returns:
      a localized standard date/time formatter
      Throws:
      IllegalArgumentException - if the Locale has no date/time pattern defined
    • getTimeInstance

      F getTimeInstance(int timeStyle, TimeZone timeZone, Locale locale)
      Gets a time formatter instance using the specified style, time zone and locale.
      Parameters:
      timeStyle - time style: FULL, LONG, MEDIUM, or SHORT
      timeZone - optional time zone, overrides time zone of formatted date, null means use default Locale
      locale - optional locale, overrides system locale
      Returns:
      a localized standard date/time formatter
      Throws:
      IllegalArgumentException - if the Locale has no date/time pattern defined
    • getPatternForStyle

      static String getPatternForStyle(Integer dateStyle, Integer timeStyle, Locale locale)
      Gets a date/time format for the specified styles and locale.
      Parameters:
      dateStyle - date style: FULL, LONG, MEDIUM, or SHORT, null indicates no date in format
      timeStyle - time style: FULL, LONG, MEDIUM, or SHORT, null indicates no time in format
      locale - The non-null locale of the desired format
      Returns:
      a localized standard date/time format
      Throws:
      IllegalArgumentException - if the Locale has no date/time pattern defined