Package com.ibm.icu.impl
Class TimeZoneGenericNames
java.lang.Object
com.ibm.icu.impl.TimeZoneGenericNames
- All Implemented Interfaces:
Freezable<TimeZoneGenericNames>
,Serializable
,Cloneable
public class TimeZoneGenericNames
extends Object
implements 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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
TimeZoneGenericNames
cache implementation.static class
A class used for returning the name search result used byfind(String, int, EnumSet)
.private static class
A private class implementing the search callback interface inTextTrieMap
for collecting match results.static enum
Generic name type enumprivate static class
A private class used for storing the name information in the local trie.static enum
Format pattern enum used for composing location and partial location names -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private ConcurrentHashMap
<String, String> private ConcurrentHashMap
<String, String> private TextTrieMap
<TimeZoneGenericNames.NameInfo> private boolean
private final ULocale
private WeakReference
<LocaleDisplayNames> private MessageFormat[]
private String
private TimeZoneNames
private static final long
private static TimeZoneGenericNames.Cache
private static final TimeZoneNames.NameType[]
private static final long
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
TimeZoneGenericNames
(ULocale locale) Constructs aTimeZoneGenericNames
with the given locale.TimeZoneGenericNames
(ULocale locale, TimeZoneNames tznames) Constructs aTimeZoneGenericNames
with the given locale and theTimeZoneNames
. -
Method Summary
Modifier and TypeMethodDescriptionProvides for the clone operation.createGenericMatchInfo
(TimeZoneNames.MatchInfo matchInfo) Returns aGenericMatchInfo
for the givenMatchInfo
.find
(String text, int start, 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.findBestMatch
(String text, int start, 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.findLocal
(String text, int start, 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.private Collection
<TimeZoneNames.MatchInfo> findTimeZoneNames
(String text, int start, 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.private String
formatGenericNonLocationName
(TimeZone tz, TimeZoneGenericNames.GenericNameType type, long date) Private method to get a generic string, with fallback logics involved, that is, 1.private String
formatPattern
(TimeZoneGenericNames.Pattern pat, String... args) Private simple pattern formatter used for formatting generic location names and partial location names.freeze()
Freezes the object.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.getGenericLocationName
(String canonicalTzID) Returns the generic location name for the given canonical time zone ID.static TimeZoneGenericNames
getInstance
(ULocale locale) The factory method ofTimeZoneGenericNames
.private LocaleDisplayNames
Private method returning LocaleDisplayNames instance for the locale of this instance.private String
getPartialLocationName
(String tzID, String mzID, boolean isLong, String mzDisplayName) Private method for formatting partial location names.private String
Private method returning the target region.private void
init()
Private method initializing the instance ofTimeZoneGenericName
.boolean
isFrozen()
Determines whether the object has been frozen or not.private void
loadStrings
(String tzCanonicalID) private void
setFormatPattern
(TimeZoneGenericNames.Pattern patType, String patStr) Sets the pattern string for the pattern type.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
_locale
-
_tznames
-
_frozen
private transient volatile boolean _frozen -
_region
-
_localeDisplayNamesRef
-
_patternFormatters
-
_genericLocationNamesMap
-
_genericPartialLocationNamesMap
-
_gnamesTrie
-
_gnamesTrieFullyLoaded
private transient boolean _gnamesTrieFullyLoaded -
GENERIC_NAMES_CACHE
-
DST_CHECK_RANGE
private static final long DST_CHECK_RANGE- See Also:
-
GENERIC_NON_LOCATION_TYPES
-
-
Constructor Details
-
TimeZoneGenericNames
Constructs aTimeZoneGenericNames
with the given locale and theTimeZoneNames
.- Parameters:
locale
- the localetznames
- the TimeZoneNames
-
TimeZoneGenericNames
Constructs aTimeZoneGenericNames
with the given locale. This constructor is private and called fromgetInstance(ULocale)
.- Parameters:
locale
- the locale
-
-
Method Details
-
init
private void init()Private method initializing the instance ofTimeZoneGenericName
. This method should be called from a constructor and readObject. -
getInstance
The factory method ofTimeZoneGenericNames
. This static method returns a frozen instance of cachedTimeZoneGenericNames
.- Parameters:
locale
- the locale- Returns:
- A frozen
TimeZoneGenericNames
.
-
getDisplayName
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 zonetype
- the generic name type - seeTimeZoneGenericNames.GenericNameType
date
- the date- Returns:
- the display name of the time zone for the given name type at the given date, or null.
-
getGenericLocationName
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
Sets the pattern string for the pattern type. Note: This method is designed for CLDR ST - not for common use.- Parameters:
patType
- the pattern typepatStr
- the pattern string- Returns:
- this object.
-
formatGenericNonLocationName
private 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 zonetype
- the generic name type, either LONG or SHORTdate
- the date- 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 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 enumargs
- the format argument(s)- Returns:
- the formatted string
-
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
-
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 String getPartialLocationName(String tzID, String mzID, boolean isLong, 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 IDmzID
- the meta zone IDisLong
- true when long generic namemzDisplayName
- the meta zone generic display name- Returns:
- the partial location format string
-
findBestMatch
public TimeZoneGenericNames.GenericMatchInfo findBestMatch(String text, int start, 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 textstart
- the start offset in the textgenericTypes
- the set of name types.- Returns:
- the best matching name info.
-
find
public Collection<TimeZoneGenericNames.GenericMatchInfo> find(String text, int start, 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 textstart
- the start offset in the textgenericTypes
- the set of name types.- Returns:
- A collection of match info.
-
createGenericMatchInfo
private TimeZoneGenericNames.GenericMatchInfo createGenericMatchInfo(TimeZoneNames.MatchInfo matchInfo) Returns aGenericMatchInfo
for the givenMatchInfo
.- Parameters:
matchInfo
- the MatchInfo- Returns:
- A GenericMatchInfo
-
findTimeZoneNames
private Collection<TimeZoneNames.MatchInfo> findTimeZoneNames(String text, int start, 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 textstart
- the start offset in the texttypes
- the set of name types.- Returns:
- A collection of match info.
-
findLocal
private Collection<TimeZoneGenericNames.GenericMatchInfo> findLocal(String text, int start, 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 textstart
- the start offset in the texttypes
- the set of name types.- Returns:
- A collection of match info.
-
readObject
- Throws:
IOException
ClassNotFoundException
-
isFrozen
public boolean isFrozen()Determines whether the object has been frozen or not.- Specified by:
isFrozen
in interfaceFreezable<TimeZoneGenericNames>
-
freeze
Freezes the object.- Specified by:
freeze
in interfaceFreezable<TimeZoneGenericNames>
- Returns:
- the object itself.
-
cloneAsThawed
Provides for the clone operation. Any clone is initially unfrozen.- Specified by:
cloneAsThawed
in interfaceFreezable<TimeZoneGenericNames>
-