< prev index next >

src/java.base/share/classes/java/util/LocaleISOData.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -23,10 +23,12 @@
  * questions.
  */
 
 package java.util;
 
+import java.util.Locale.IsoCountryCode;
+
 class LocaleISOData {
     /**
      * The 2- and 3-letter ISO 639 language codes.
      */
     static final String isoLanguageTable =

@@ -229,11 +231,11 @@
         + "AF" + "AFG"  // Afghanistan
         + "AG" + "ATG"  // Antigua and Barbuda
         + "AI" + "AIA"  // Anguilla
         + "AL" + "ALB"  // Albania, People's Socialist Republic of
         + "AM" + "ARM"  // Armenia
-        + "AN" + "ANT"  // Netherlands Antilles
+//      + "AN" + "ANT"  // Netherlands Antilles
         + "AO" + "AGO"  // Angola, Republic of
         + "AQ" + "ATA"  // Antarctica (the territory South of 60 deg S)
         + "AR" + "ARG"  // Argentina, Argentine Republic
         + "AS" + "ASM"  // American Samoa
         + "AT" + "AUT"  // Austria, Republic of

@@ -475,8 +477,63 @@
         + "ZA" + "ZAF"  // South Africa, Republic of
         + "ZM" + "ZMB"  // Zambia, Republic of
         + "ZW" + "ZWE"  // Zimbabwe
         ;
 
+    /**
+     * Array to hold country codes for ISO3166-3.
+     */
+     private static final String[] ISO3166_3 = {
+        "AIDJ", "ANHH", "BQAQ", "BUMM", "BYAA", "CSHH", "CSXX", "CTKI", "DDDE",
+        "DYBJ", "FQHH", "FXFR", "GEHH", "HVBF", "JTUM", "MIUM", "NHVU", "NQAQ",
+        "NTHH", "PCHH", "PUUM", "PZPA", "RHZW", "SKIN", "SUHH", "TPTL", "VDVN",
+        "WKUM", "YDYE", "YUCS", "ZRCD"
+    };
+
+    /**
+     * Map to hold country codes for each ISO3166 part.
+     */
+     private static Map<IsoCountryCode, Set<String>> iso3166CodesMap = new HashMap<>();
+
+    /**
+     * This mapping function attempts to compute value for iso3166CodesMap
+     * for each IsoCountryCode type key.
+     */
+    private static Set<String> getISOCountriesImpl(IsoCountryCode type) {
+        switch (type) {
+            case PART1_ALPHA2:
+                return Set.of(Locale.getISOCountries());
+            case PART1_ALPHA3:
+                return LocaleISOData.computeISO3166_1Alpha3Countries();
+            case PART3:
+                return Set.of(ISO3166_3);
+            default:
+                // should not happen
+                assert false;
+                return Collections.emptySet();
+        }
+    }
+
+    /**
+     * This method is called from Locale class
+     * to retrieve country code set for getISOCountries(type)
+     */
+    static Set<String> retrieveIsoCountryCodes(IsoCountryCode type) {
+       return iso3166CodesMap.computeIfAbsent(type, LocaleISOData::getISOCountriesImpl);
+    }
+
+    /**
+     * This method computes a set of ISO3166-1 alpha-3 country codes from
+     * existing isoCountryTable.
+     */
+    private static Set<String> computeISO3166_1Alpha3Countries() {
+        int tableLength = isoCountryTable.length();
+        String[] isoTable = new String[tableLength / 5];
+        for (int i = 0, index = 0; index < tableLength; i++, index += 5) {
+            isoTable[i] = isoCountryTable.substring(index + 2, index + 5);
+        }
+        return Set.of(isoTable);
+    }
+
     private LocaleISOData() {
     }
 }
< prev index next >