Class AbstractFormatCache<F extends java.text.Format>

  • Type Parameters:
    F - The Format type.

    abstract class AbstractFormatCache<F extends java.text.Format>
    extends java.lang.Object
    FormatCache is a cache and factory for Formats.
    Since:
    3.0
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  AbstractFormatCache.ArrayKey
      Helper class to hold multipart Map keys as arrays.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static void clear()
      Clears the cache.
      (package private) void clearInstance()
      Clears the cache.
      protected abstract F createInstance​(java.lang.String pattern, java.util.TimeZone timeZone, java.util.Locale locale)
      Create a format instance using the specified pattern, time zone and locale.
      (package private) F getDateInstance​(int dateStyle, java.util.TimeZone timeZone, java.util.Locale locale)
      Gets a date formatter instance using the specified style, time zone and locale.
      (package private) F getDateTimeInstance​(int dateStyle, int timeStyle, java.util.TimeZone timeZone, java.util.Locale locale)
      Gets a date/time formatter instance using the specified style, time zone and locale.
      private F getDateTimeInstance​(java.lang.Integer dateStyle, java.lang.Integer timeStyle, java.util.TimeZone timeZone, java.util.Locale locale)
      Gets a date/time formatter instance using the specified style, time zone and locale.
      F getInstance()
      Gets a formatter instance using the default pattern in the default time zone and locale.
      F getInstance​(java.lang.String pattern, java.util.TimeZone timeZone, java.util.Locale locale)
      Gets a formatter instance using the specified pattern, time zone and locale.
      (package private) static java.lang.String getPatternForStyle​(java.lang.Integer dateStyle, java.lang.Integer timeStyle, java.util.Locale locale)
      Gets a date/time format for the specified styles and locale.
      (package private) F getTimeInstance​(int timeStyle, java.util.TimeZone timeZone, java.util.Locale locale)
      Gets a time formatter instance using the specified style, time zone and locale.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NONE

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

        private static final java.util.concurrent.ConcurrentMap<AbstractFormatCache.ArrayKey,​java.lang.String> dateTimeInstanceCache
    • Constructor Detail

      • AbstractFormatCache

        AbstractFormatCache()
    • Method Detail

      • clear

        static void clear()
        Clears the cache.
      • getPatternForStyle

        static java.lang.String getPatternForStyle​(java.lang.Integer dateStyle,
                                                   java.lang.Integer timeStyle,
                                                   java.util.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:
        java.lang.IllegalArgumentException - if the Locale has no date/time pattern defined
      • clearInstance

        void clearInstance()
        Clears the cache.
      • createInstance

        protected abstract F createInstance​(java.lang.String pattern,
                                            java.util.TimeZone timeZone,
                                            java.util.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:
        java.lang.IllegalArgumentException - if pattern is invalid or null
      • getDateInstance

        F getDateInstance​(int dateStyle,
                          java.util.TimeZone timeZone,
                          java.util.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:
        java.lang.IllegalArgumentException - if the Locale has no date/time pattern defined
      • getDateTimeInstance

        F getDateTimeInstance​(int dateStyle,
                              int timeStyle,
                              java.util.TimeZone timeZone,
                              java.util.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:
        java.lang.IllegalArgumentException - if the Locale has no date/time pattern defined
      • getDateTimeInstance

        private F getDateTimeInstance​(java.lang.Integer dateStyle,
                                      java.lang.Integer timeStyle,
                                      java.util.TimeZone timeZone,
                                      java.util.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:
        java.lang.IllegalArgumentException - 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​(java.lang.String pattern,
                             java.util.TimeZone timeZone,
                             java.util.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:
        java.lang.NullPointerException - if pattern is null
        java.lang.IllegalArgumentException - if pattern is invalid
      • getTimeInstance

        F getTimeInstance​(int timeStyle,
                          java.util.TimeZone timeZone,
                          java.util.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:
        java.lang.IllegalArgumentException - if the Locale has no date/time pattern defined