]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - jars/icu4j-52_1/main/classes/core/src/com/ibm/icu/impl/TimeZoneGenericNames.java
Upgrade ICU4J.
[Dictionary.git] / jars / icu4j-52_1 / main / classes / core / src / com / ibm / icu / impl / TimeZoneGenericNames.java
similarity index 93%
rename from jars/icu4j-4_8_1_1/main/classes/core/src/com/ibm/icu/impl/TimeZoneGenericNames.java
rename to jars/icu4j-52_1/main/classes/core/src/com/ibm/icu/impl/TimeZoneGenericNames.java
index 81c6506c69cd5cdbbc3dd4338edef0102794a251..e1c60830e91613b7643f41ccf048a8739788390e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *******************************************************************************
- * Copyright (C) 2011, International Business Machines Corporation and         *
+ * Copyright (C) 2011-2013, International Business Machines Corporation and    *
  * others. All Rights Reserved.                                                *
  *******************************************************************************
  */
@@ -27,6 +27,7 @@ import com.ibm.icu.text.TimeZoneNames.MatchInfo;
 import com.ibm.icu.text.TimeZoneNames.NameType;
 import com.ibm.icu.util.BasicTimeZone;
 import com.ibm.icu.util.Freezable;
+import com.ibm.icu.util.Output;
 import com.ibm.icu.util.TimeZone;
 import com.ibm.icu.util.TimeZone.SystemTimeZoneType;
 import com.ibm.icu.util.TimeZoneTransition;
@@ -40,6 +41,12 @@ import com.ibm.icu.util.ULocale;
  */
 public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGenericNames> {
 
+    // Note: This class implements Serializable, but we no longer serialize instance of
+    // TimeZoneGenericNames in ICU 49. ICU 4.8 com.ibm.icu.text.TimeZoneFormat used to
+    // serialize TimeZoneGenericNames field. TimeZoneFormat no longer read TimeZoneGenericNames
+    // field, we have to keep TimeZoneGenericNames Serializable. Otherwise it fails to read
+    // (unused) TimeZoneGenericNames serialized data.
+
     private static final long serialVersionUID = 2729910342063468417L;
 
     /**
@@ -70,11 +77,12 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
      * Format pattern enum used for composing location and partial location names
      */
     public enum Pattern {
-        // The format pattern such as "{0} Time", where {0} is the country. 
+        // The format pattern such as "{0} Time", where {0} is the country or city
         REGION_FORMAT("regionFormat", "({0})"),
 
+        // Note: FALLBACK_REGION_FORMAT is no longer used since ICU 50/CLDR 22.1
         // The format pattern such as "{1} Time ({0})", where {1} is the country and {0} is a city.
-        FALLBACK_REGION_FORMAT("fallbackRegionFormat", "{1} ({0})"),
+        //FALLBACK_REGION_FORMAT("fallbackRegionFormat", "{1} ({0})"),
 
         // The format pattern such as "{1} ({0})", where {1} is the metazone, and {0} is the country or city.
         FALLBACK_FORMAT("fallbackFormat", "{1} ({0})");
@@ -225,17 +233,21 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
             return name;
         }
 
-        String countryCode = ZoneMeta.getCanonicalCountry(canonicalTzID);
+        Output<Boolean> isPrimary = new Output<Boolean>();
+        String countryCode = ZoneMeta.getCanonicalCountry(canonicalTzID, isPrimary);
         if (countryCode != null) {
-            String country = getLocaleDisplayNames().regionDisplayName(countryCode);
-            if (ZoneMeta.getSingleCountry(canonicalTzID) != null) {
-                // If the zone is only one zone in the country, do not add city
+            if (isPrimary.value) {
+                // If this is only the single zone in the country, use the country name
+                String country = getLocaleDisplayNames().regionDisplayName(countryCode);
                 name = formatPattern(Pattern.REGION_FORMAT, country);
             } else {
+                // If there are multiple zones including this in the country,
+                // use the exemplar city name
+
                 // getExemplarLocationName should return non-empty String
                 // if the time zone is associated with a location
                 String city = _tznames.getExemplarLocationName(canonicalTzID);
-                name = formatPattern(Pattern.FALLBACK_REGION_FORMAT, city, country);
+                name = formatPattern(Pattern.REGION_FORMAT, city);
             }
         }
 
@@ -367,7 +379,7 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
             }
             if (useStandard) {
                 NameType stdNameType = (nameType == NameType.LONG_GENERIC) ?
-                        NameType.LONG_STANDARD : NameType.SHORT_STANDARD_COMMONLY_USED;
+                        NameType.LONG_STANDARD : NameType.SHORT_STANDARD;
                 String stdName = _tznames.getDisplayName(tzID, stdNameType, date);
                 if (stdName != null) {
                     name = stdName;
@@ -393,7 +405,7 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
                     // golden zone at the given date.
                     String goldenID = _tznames.getReferenceZoneID(mzID, getTargetRegion());
                     if (goldenID != null && !goldenID.equals(tzID)) {
-                        TimeZone goldenZone = TimeZone.getTimeZone(goldenID);
+                        TimeZone goldenZone = TimeZone.getFrozenTimeZone(goldenID);
                         int[] offsets1 = {0, 0};
 
                         // Check offset in the golden zone with wall time.
@@ -700,7 +712,17 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
                     // and the location name. When the match is a long standard name,
                     // then we need to check if the name is same with the location name.
                     // This is probably a data error or a design bug.
-                    if (bestMatch.nameType != GenericNameType.LONG || bestMatch.timeType != TimeType.STANDARD) {
+//                    if (bestMatch.nameType != GenericNameType.LONG || bestMatch.timeType != TimeType.STANDARD) {
+//                        return bestMatch;
+//                    }
+
+                    // TODO The deprecation of commonlyUsed flag introduced the name
+                    // conflict not only for long standard names, but short standard names too.
+                    // These short names (found in zh_Hant) should be gone once we clean
+                    // up CLDR time zone display name data. Once the short name conflict
+                    // problem (with location name) is resolved, we should change the condition
+                    // below back to the original one above. -Yoshito (2011-09-14)
+                    if (bestMatch.timeType != TimeType.STANDARD) {
                         return bestMatch;
                     }
                 }
@@ -768,15 +790,16 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
         case LONG_GENERIC:
             nameType = GenericNameType.LONG;
             break;
-        case SHORT_STANDARD_COMMONLY_USED:
+        case SHORT_STANDARD:
             nameType = GenericNameType.SHORT;
             timeType = TimeType.STANDARD;
             break;
         case SHORT_GENERIC:
             nameType = GenericNameType.SHORT;
             break;
+        default:
+            throw new IllegalArgumentException("Unexpected MatchInfo name type - " + matchInfo.nameType());
         }
-        assert(nameType != null);
 
         String tzID = matchInfo.tzID();
         if (tzID == null) {
@@ -815,7 +838,7 @@ public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGen
         }
         if (types.contains(GenericNameType.SHORT)) {
             nameTypes.add(NameType.SHORT_GENERIC);
-            nameTypes.add(NameType.SHORT_STANDARD_COMMONLY_USED);
+            nameTypes.add(NameType.SHORT_STANDARD);
         }
         
         if (!nameTypes.isEmpty()) {