Class TimeZoneGenericNames

  • All Implemented Interfaces:
    Freezable<TimeZoneGenericNames>, java.io.Serializable, java.lang.Cloneable

    public class TimeZoneGenericNames
    extends java.lang.Object
    implements java.io.Serializable, Freezable<TimeZoneGenericNames>
    This class interact with TimeZoneNames and LocaleDisplayNames to format and parse time zone's generic display names. It is not recommended to use this class directly, instead use com.ibm.icu.text.TimeZoneFormat.
    See Also:
    Serialized Form
    • Field Detail

      • _locale

        private final ULocale _locale
      • _frozen

        private transient volatile boolean _frozen
      • _region

        private transient java.lang.String _region
      • _localeDisplayNamesRef

        private transient java.lang.ref.WeakReference<LocaleDisplayNames> _localeDisplayNamesRef
      • _patternFormatters

        private transient java.text.MessageFormat[] _patternFormatters
      • _genericLocationNamesMap

        private transient java.util.concurrent.ConcurrentHashMap<java.lang.String,​java.lang.String> _genericLocationNamesMap
      • _genericPartialLocationNamesMap

        private transient java.util.concurrent.ConcurrentHashMap<java.lang.String,​java.lang.String> _genericPartialLocationNamesMap
      • _gnamesTrieFullyLoaded

        private transient boolean _gnamesTrieFullyLoaded
    • Constructor Detail

      • TimeZoneGenericNames

        public TimeZoneGenericNames​(ULocale locale,
                                    TimeZoneNames tznames)
        Constructs a TimeZoneGenericNames with the given locale and the TimeZoneNames.
        Parameters:
        locale - the locale
        tznames - the TimeZoneNames
      • TimeZoneGenericNames

        private TimeZoneGenericNames​(ULocale locale)
        Constructs a TimeZoneGenericNames with the given locale. This constructor is private and called from getInstance(ULocale).
        Parameters:
        locale - the locale
    • Method Detail

      • init

        private void init()
        Private method initializing the instance of TimeZoneGenericName. This method should be called from a constructor and readObject.
      • getInstance

        public static TimeZoneGenericNames getInstance​(ULocale locale)
        The factory method of TimeZoneGenericNames. This static method returns a frozen instance of cached TimeZoneGenericNames.
        Parameters:
        locale - the locale
        Returns:
        A frozen TimeZoneGenericNames.
      • getDisplayName

        public java.lang.String getDisplayName​(TimeZone tz,
                                               TimeZoneGenericNames.GenericNameType type,
                                               long date)
        Returns the display name of the time zone for the given name type at the given date, or null if the display name is not available.
        Parameters:
        tz - the time zone
        type - the generic name type - see TimeZoneGenericNames.GenericNameType
        date - the date
        Returns:
        the display name of the time zone for the given name type at the given date, or null.
      • getGenericLocationName

        public java.lang.String getGenericLocationName​(java.lang.String canonicalTzID)
        Returns the generic location name for the given canonical time zone ID.
        Parameters:
        canonicalTzID - the canonical time zone ID
        Returns:
        the generic location name for the given canonical time zone ID.
      • setFormatPattern

        public TimeZoneGenericNames setFormatPattern​(TimeZoneGenericNames.Pattern patType,
                                                     java.lang.String patStr)
        Sets the pattern string for the pattern type. Note: This method is designed for CLDR ST - not for common use.
        Parameters:
        patType - the pattern type
        patStr - the pattern string
        Returns:
        this object.
      • formatGenericNonLocationName

        private java.lang.String formatGenericNonLocationName​(TimeZone tz,
                                                              TimeZoneGenericNames.GenericNameType type,
                                                              long date)
        Private method to get a generic string, with fallback logics involved, that is, 1. If a generic non-location string is available for the zone, return it. 2. If a generic non-location string is associated with a meta zone and the zone never use daylight time around the given date, use the standard string (if available). 3. If a generic non-location string is associated with a meta zone and the offset at the given time is different from the preferred zone for the current locale, then return the generic partial location string (if available) 4. If a generic non-location string is not available, use generic location string.
        Parameters:
        tz - the requested time zone
        date - the date
        type - the generic name type, either LONG or SHORT
        Returns:
        the name used for a generic name type, which could be the generic name, or the standard name (if the zone does not observes DST around the date), or the partial location name.
      • formatPattern

        private java.lang.String formatPattern​(TimeZoneGenericNames.Pattern pat,
                                               java.lang.String... args)
        Private simple pattern formatter used for formatting generic location names and partial location names. We intentionally use JDK MessageFormat for performance reason.
        Parameters:
        pat - the message pattern enum
        args - the format argument(s)
        Returns:
        the formatted string
      • getLocaleDisplayNames

        private LocaleDisplayNames getLocaleDisplayNames()
        Private method returning LocaleDisplayNames instance for the locale of this instance. Because LocaleDisplayNames is only used for generic location format and partial location format, the LocaleDisplayNames is instantiated lazily.
        Returns:
        the instance of LocaleDisplayNames for the locale of this object.
      • loadStrings

        private void loadStrings​(java.lang.String tzCanonicalID)
      • getTargetRegion

        private java.lang.String getTargetRegion()
        Private method returning the target region. The target regions is determined by the locale of this instance. When a generic name is coming from a meta zone, this region is used for checking if the time zone is a reference zone of the meta zone.
        Returns:
        the target region
      • getPartialLocationName

        private java.lang.String getPartialLocationName​(java.lang.String tzID,
                                                        java.lang.String mzID,
                                                        boolean isLong,
                                                        java.lang.String mzDisplayName)
        Private method for formatting partial location names. This format is used when a generic name of a meta zone is available, but the given time zone is not a reference zone (golden zone) of the meta zone.
        Parameters:
        tzID - the canonical time zone ID
        mzID - the meta zone ID
        isLong - true when long generic name
        mzDisplayName - the meta zone generic display name
        Returns:
        the partial location format string
      • findBestMatch

        public TimeZoneGenericNames.GenericMatchInfo findBestMatch​(java.lang.String text,
                                                                   int start,
                                                                   java.util.EnumSet<TimeZoneGenericNames.GenericNameType> genericTypes)
        Returns the best match of time zone display name for the specified types in the given text at the given offset.
        Parameters:
        text - the text
        start - the start offset in the text
        genericTypes - the set of name types.
        Returns:
        the best matching name info.
      • find

        public java.util.Collection<TimeZoneGenericNames.GenericMatchInfo> find​(java.lang.String text,
                                                                                int start,
                                                                                java.util.EnumSet<TimeZoneGenericNames.GenericNameType> genericTypes)
        Returns a collection of time zone display name matches for the specified types in the given text at the given offset.
        Parameters:
        text - the text
        start - the start offset in the text
        genericTypes - the set of name types.
        Returns:
        A collection of match info.
      • findTimeZoneNames

        private java.util.Collection<TimeZoneNames.MatchInfo> findTimeZoneNames​(java.lang.String text,
                                                                                int start,
                                                                                java.util.EnumSet<TimeZoneGenericNames.GenericNameType> types)
        Returns a collection of time zone display name matches for the specified types in the given text at the given offset. This method only finds matches from the TimeZoneNames used by this object.
        Parameters:
        text - the text
        start - the start offset in the text
        types - the set of name types.
        Returns:
        A collection of match info.
      • findLocal

        private java.util.Collection<TimeZoneGenericNames.GenericMatchInfo> findLocal​(java.lang.String text,
                                                                                      int start,
                                                                                      java.util.EnumSet<TimeZoneGenericNames.GenericNameType> types)
        Returns a collection of time zone display name matches for the specified types in the given text at the given offset. This method only finds matches from the local trie, that contains 1) generic location names and 2) long/short generic partial location names, used by this object.
        Parameters:
        text - the text
        start - the start offset in the text
        types - the set of name types.
        Returns:
        A collection of match info.
      • readObject

        private void readObject​(java.io.ObjectInputStream in)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException