Class AbstractFormatCache<F extends Format>

java.lang.Object
org.apache.commons.lang3.time.AbstractFormatCache<F>
Type Parameters:
F - The Format type.

abstract class AbstractFormatCache<F extends Format> extends Object
Caches for Format instances.
Since:
3.0
  • Field Details

    • NONE

      static final int NONE
      No date or no time. Used in same parameters as DateFormat.SHORT or DateFormat.LONG.
      See Also:
    • MAX_CACHE_SIZE

      static final int MAX_CACHE_SIZE
      Maximum number of entries a static cache in this package may hold before it is flushed. These caches live for the lifetime of the JVM and are keyed by caller-supplied values (pattern, time zone, locale), so without a bound, unbounded-cardinality inputs would pin memory forever. The bound is approximate under concurrency; flushing only costs re-creation of evicted entries.
      See Also:
    • dateTimeInstanceCache

      private static final ConcurrentMap<AbstractFormatCache.ArrayKey,String> dateTimeInstanceCache
    • instanceCache

      private final ConcurrentMap<AbstractFormatCache.ArrayKey,F extends Format> instanceCache
  • Constructor Details

    • AbstractFormatCache

      AbstractFormatCache()
  • Method Details

    • clear

      static void clear()
      Clears the cache.
    • 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 - Thrown if the Locale has no date/time pattern defined.
    • clearInstance

      void clearInstance()
      Clears the cache.
    • 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 - Thrown if pattern is invalid or null.
    • 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 - Thrown 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 - Thrown if the Locale has no date/time pattern defined.
    • 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 - Thrown if the Locale has no date/time pattern defined.
    • 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 - Thrown if pattern is null.
      IllegalArgumentException - Thrown if pattern is invalid.
    • 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 - Thrown if the Locale has no date/time pattern defined.