< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.util;
  27 


  28 class LocaleISOData {
  29     /**
  30      * The 2- and 3-letter ISO 639 language codes.
  31      */
  32     static final String isoLanguageTable =
  33           "aa" + "aar"  // Afar
  34         + "ab" + "abk"  // Abkhazian
  35         + "ae" + "ave"  // Avestan
  36         + "af" + "afr"  // Afrikaans
  37         + "ak" + "aka"  // Akan
  38         + "am" + "amh"  // Amharic
  39         + "an" + "arg"  // Aragonese
  40         + "ar" + "ara"  // Arabic
  41         + "as" + "asm"  // Assamese
  42         + "av" + "ava"  // Avaric
  43         + "ay" + "aym"  // Aymara
  44         + "az" + "aze"  // Azerbaijani
  45         + "ba" + "bak"  // Bashkir
  46         + "be" + "bel"  // Belarusian
  47         + "bg" + "bul"  // Bulgarian


 214         + "wo" + "wol"  // Wolof
 215         + "xh" + "xho"  // Xhosa
 216         + "yi" + "yid"  // Yiddish
 217         + "yo" + "yor"  // Yoruba
 218         + "za" + "zha"  // Zhuang
 219         + "zh" + "zho"  // Chinese
 220         + "zu" + "zul"  // Zulu
 221         ;
 222 
 223     /**
 224      * The 2- and 3-letter ISO 3166 country codes.
 225      */
 226     static final String isoCountryTable =
 227           "AD" + "AND"  // Andorra, Principality of
 228         + "AE" + "ARE"  // United Arab Emirates
 229         + "AF" + "AFG"  // Afghanistan
 230         + "AG" + "ATG"  // Antigua and Barbuda
 231         + "AI" + "AIA"  // Anguilla
 232         + "AL" + "ALB"  // Albania, People's Socialist Republic of
 233         + "AM" + "ARM"  // Armenia
 234         + "AN" + "ANT"  // Netherlands Antilles
 235         + "AO" + "AGO"  // Angola, Republic of
 236         + "AQ" + "ATA"  // Antarctica (the territory South of 60 deg S)
 237         + "AR" + "ARG"  // Argentina, Argentine Republic
 238         + "AS" + "ASM"  // American Samoa
 239         + "AT" + "AUT"  // Austria, Republic of
 240         + "AU" + "AUS"  // Australia, Commonwealth of
 241         + "AW" + "ABW"  // Aruba
 242         + "AX" + "ALA"  // \u00c5land Islands
 243         + "AZ" + "AZE"  // Azerbaijan, Republic of
 244         + "BA" + "BIH"  // Bosnia and Herzegovina
 245         + "BB" + "BRB"  // Barbados
 246         + "BD" + "BGD"  // Bangladesh, People's Republic of
 247         + "BE" + "BEL"  // Belgium, Kingdom of
 248         + "BF" + "BFA"  // Burkina Faso
 249         + "BG" + "BGR"  // Bulgaria, People's Republic of
 250         + "BH" + "BHR"  // Bahrain, Kingdom of
 251         + "BI" + "BDI"  // Burundi, Republic of
 252         + "BJ" + "BEN"  // Benin, People's Republic of
 253         + "BL" + "BLM"  // Saint Barth\u00e9lemy
 254         + "BM" + "BMU"  // Bermuda


 460         + "UM" + "UMI"  // United States Minor Outlying Islands
 461         + "US" + "USA"  // United States of America
 462         + "UY" + "URY"  // Uruguay, Eastern Republic of
 463         + "UZ" + "UZB"  // Uzbekistan
 464         + "VA" + "VAT"  // Holy See (Vatican City State)
 465         + "VC" + "VCT"  // St. Vincent and the Grenadines
 466         + "VE" + "VEN"  // Venezuela, Bolivarian Republic of
 467         + "VG" + "VGB"  // British Virgin Islands
 468         + "VI" + "VIR"  // US Virgin Islands
 469         + "VN" + "VNM"  // Viet Nam, Socialist Republic of
 470         + "VU" + "VUT"  // Vanuatu
 471         + "WF" + "WLF"  // Wallis and Futuna Islands
 472         + "WS" + "WSM"  // Samoa, Independent State of
 473         + "YE" + "YEM"  // Yemen
 474         + "YT" + "MYT"  // Mayotte
 475         + "ZA" + "ZAF"  // South Africa, Republic of
 476         + "ZM" + "ZMB"  // Zambia, Republic of
 477         + "ZW" + "ZWE"  // Zimbabwe
 478         ;
 479 























































 480     private LocaleISOData() {
 481     }
 482 }
   1 /*
   2  * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.util;
  27 
  28 import java.util.Locale.IsoCountryCode;
  29 
  30 class LocaleISOData {
  31     /**
  32      * The 2- and 3-letter ISO 639 language codes.
  33      */
  34     static final String isoLanguageTable =
  35           "aa" + "aar"  // Afar
  36         + "ab" + "abk"  // Abkhazian
  37         + "ae" + "ave"  // Avestan
  38         + "af" + "afr"  // Afrikaans
  39         + "ak" + "aka"  // Akan
  40         + "am" + "amh"  // Amharic
  41         + "an" + "arg"  // Aragonese
  42         + "ar" + "ara"  // Arabic
  43         + "as" + "asm"  // Assamese
  44         + "av" + "ava"  // Avaric
  45         + "ay" + "aym"  // Aymara
  46         + "az" + "aze"  // Azerbaijani
  47         + "ba" + "bak"  // Bashkir
  48         + "be" + "bel"  // Belarusian
  49         + "bg" + "bul"  // Bulgarian


 216         + "wo" + "wol"  // Wolof
 217         + "xh" + "xho"  // Xhosa
 218         + "yi" + "yid"  // Yiddish
 219         + "yo" + "yor"  // Yoruba
 220         + "za" + "zha"  // Zhuang
 221         + "zh" + "zho"  // Chinese
 222         + "zu" + "zul"  // Zulu
 223         ;
 224 
 225     /**
 226      * The 2- and 3-letter ISO 3166 country codes.
 227      */
 228     static final String isoCountryTable =
 229           "AD" + "AND"  // Andorra, Principality of
 230         + "AE" + "ARE"  // United Arab Emirates
 231         + "AF" + "AFG"  // Afghanistan
 232         + "AG" + "ATG"  // Antigua and Barbuda
 233         + "AI" + "AIA"  // Anguilla
 234         + "AL" + "ALB"  // Albania, People's Socialist Republic of
 235         + "AM" + "ARM"  // Armenia
 236 //      + "AN" + "ANT"  // Netherlands Antilles
 237         + "AO" + "AGO"  // Angola, Republic of
 238         + "AQ" + "ATA"  // Antarctica (the territory South of 60 deg S)
 239         + "AR" + "ARG"  // Argentina, Argentine Republic
 240         + "AS" + "ASM"  // American Samoa
 241         + "AT" + "AUT"  // Austria, Republic of
 242         + "AU" + "AUS"  // Australia, Commonwealth of
 243         + "AW" + "ABW"  // Aruba
 244         + "AX" + "ALA"  // \u00c5land Islands
 245         + "AZ" + "AZE"  // Azerbaijan, Republic of
 246         + "BA" + "BIH"  // Bosnia and Herzegovina
 247         + "BB" + "BRB"  // Barbados
 248         + "BD" + "BGD"  // Bangladesh, People's Republic of
 249         + "BE" + "BEL"  // Belgium, Kingdom of
 250         + "BF" + "BFA"  // Burkina Faso
 251         + "BG" + "BGR"  // Bulgaria, People's Republic of
 252         + "BH" + "BHR"  // Bahrain, Kingdom of
 253         + "BI" + "BDI"  // Burundi, Republic of
 254         + "BJ" + "BEN"  // Benin, People's Republic of
 255         + "BL" + "BLM"  // Saint Barth\u00e9lemy
 256         + "BM" + "BMU"  // Bermuda


 462         + "UM" + "UMI"  // United States Minor Outlying Islands
 463         + "US" + "USA"  // United States of America
 464         + "UY" + "URY"  // Uruguay, Eastern Republic of
 465         + "UZ" + "UZB"  // Uzbekistan
 466         + "VA" + "VAT"  // Holy See (Vatican City State)
 467         + "VC" + "VCT"  // St. Vincent and the Grenadines
 468         + "VE" + "VEN"  // Venezuela, Bolivarian Republic of
 469         + "VG" + "VGB"  // British Virgin Islands
 470         + "VI" + "VIR"  // US Virgin Islands
 471         + "VN" + "VNM"  // Viet Nam, Socialist Republic of
 472         + "VU" + "VUT"  // Vanuatu
 473         + "WF" + "WLF"  // Wallis and Futuna Islands
 474         + "WS" + "WSM"  // Samoa, Independent State of
 475         + "YE" + "YEM"  // Yemen
 476         + "YT" + "MYT"  // Mayotte
 477         + "ZA" + "ZAF"  // South Africa, Republic of
 478         + "ZM" + "ZMB"  // Zambia, Republic of
 479         + "ZW" + "ZWE"  // Zimbabwe
 480         ;
 481 
 482     /**
 483      * Array to hold country codes for ISO3166-3.
 484      */
 485      private static final String[] ISO3166_3 = {
 486         "AIDJ", "ANHH", "BQAQ", "BUMM", "BYAA", "CSHH", "CSXX", "CTKI", "DDDE",
 487         "DYBJ", "FQHH", "FXFR", "GEHH", "HVBF", "JTUM", "MIUM", "NHVU", "NQAQ",
 488         "NTHH", "PCHH", "PUUM", "PZPA", "RHZW", "SKIN", "SUHH", "TPTL", "VDVN",
 489         "WKUM", "YDYE", "YUCS", "ZRCD"
 490     };
 491 
 492     /**
 493      * Map to hold country codes for each ISO3166 part.
 494      */
 495      private static Map<IsoCountryCode, Set<String>> iso3166CodesMap = new HashMap<>();
 496 
 497     /**
 498      * This mapping function attempts to compute value for iso3166CodesMap
 499      * for each IsoCountryCode type key.
 500      */
 501     private static Set<String> getISOCountriesImpl(IsoCountryCode type) {
 502         switch (type) {
 503             case PART1_ALPHA2:
 504                 return Set.of(Locale.getISOCountries());
 505             case PART1_ALPHA3:
 506                 return LocaleISOData.computeISO3166_1Alpha3Countries();
 507             case PART3:
 508                 return Set.of(ISO3166_3);
 509             default:
 510                 // should not happen
 511                 assert false;
 512                 return Collections.emptySet();
 513         }
 514     }
 515 
 516     /**
 517      * This method is called from Locale class
 518      * to retrieve country code set for getISOCountries(type)
 519      */
 520     static Set<String> retrieveIsoCountryCodes(IsoCountryCode type) {
 521        return iso3166CodesMap.computeIfAbsent(type, LocaleISOData::getISOCountriesImpl);
 522     }
 523 
 524     /**
 525      * This method computes a set of ISO3166-1 alpha-3 country codes from
 526      * existing isoCountryTable.
 527      */
 528     private static Set<String> computeISO3166_1Alpha3Countries() {
 529         int tableLength = isoCountryTable.length();
 530         String[] isoTable = new String[tableLength / 5];
 531         for (int i = 0, index = 0; index < tableLength; i++, index += 5) {
 532             isoTable[i] = isoCountryTable.substring(index + 2, index + 5);
 533         }
 534         return Set.of(isoTable);
 535     }
 536 
 537     private LocaleISOData() {
 538     }
 539 }
< prev index next >