1. Patrick Mézard
  2. libphonenumber-csharp

Commits

jia....@ee073f10-1060-11df-b6a4-87a95322a99c  committed 7e3c848

Initialize country calling code to region code map in PhoneNumberUtil to further improve startup speed.

  • Participants
  • Parent commits 25f0569
  • Branches default

Comments (0)

Files changed (7)

File java/release_notes.txt

View file
+August 4th, 2010
+
+* Further improve startup performance
+  - Preload no country specific metadata at startup.
+  - Stop creating the file containing mapping from country calling code to region code
+    and loading it at startup; instead, do the initialization in PhoneNumberUtil.
+
 July 31th, 2010
 
 * Improve startup performance
 
 * Code improvement
   - China local number formatting for AsYouTypeFormatter
-  - improve extension parsing to handle number in the form of +1 (645) 123 1234 ext. 910# 
+  - improve extension parsing to handle number in the form of +1 (645) 123 1234 ext. 910#

File java/resources/com/google/i18n/phonenumbers/BuildMetadataProtoFromXml.java

View file
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
 
-import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
 import java.io.ObjectOutputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.regex.Pattern;
   private static final Logger LOGGER = Logger.getLogger(BuildMetadataProtoFromXml.class.getName());
   private static Boolean liteBuild;
 
-  // A mapping from a country code to the region codes which denote the country/region
-  // represented by that country code. In the case of multiple countries sharing a calling code,
-  // such as the NANPA countries, the one indicated with "isMainCountryForCode" in the metadata
-  // should be first. The initial capacity is set to 300 as there are roughly 200 different
-  // country codes, and this offers a load factor of roughly 0.75.
-  private static final HashMap<Integer, List<String> > COUNTRY_CODE_TO_REGION_CODE_MAP =
-      new HashMap<Integer, List<String> >(310);
-
   public static void main(String[] args) throws Exception {
     String inputFile = args[0];
     String filePrefix = args[1];
-    String outputMappingFile = filePrefix +
-        PhoneNumberUtil.COUNTRY_CODE_TO_REGION_CODE_MAP_FILE_SUFFIX;
     liteBuild = args.length > 2 && Boolean.getBoolean(args[2]);
     File xmlFile = new File(inputFile);
 
       Element territoryElement = (Element) territory.item(i);
       String regionCode = territoryElement.getAttribute("id");
       PhoneMetadata metadata = loadCountryMetadata(regionCode, territoryElement);
-      fillCountryCodeToRegionCodeMap(metadata, regionCode);
       metadataCollection.addMetadata(metadata);
       FileOutputStream outputForRegion = new FileOutputStream(filePrefix + "_" + regionCode);
       ObjectOutputStream out = new ObjectOutputStream(outputForRegion);
       out.close();
       metadataCollection.clear();
     }
-    writeCountryCallingCodeMappingToFile(outputMappingFile);
-  }
-
-  private static void writeCountryCallingCodeMappingToFile(String file) throws IOException {
-    BufferedWriter writer =
-        new BufferedWriter(new FileWriter(file));
-    for (Integer countryCallingCode : COUNTRY_CODE_TO_REGION_CODE_MAP.keySet()) {
-      writer.write(countryCallingCode.toString());
-      writer.newLine();
-      for (String regionCode : COUNTRY_CODE_TO_REGION_CODE_MAP.get(countryCallingCode)) {
-        writer.write(' ');
-        writer.write(regionCode);
-      }
-      writer.newLine();
-    }
-    writer.flush();
-    writer.close();
-  }
-
-  static void fillCountryCodeToRegionCodeMap(PhoneMetadata metadata, String regionCode) {
-    int countryCode = metadata.getCountryCode();
-    if (COUNTRY_CODE_TO_REGION_CODE_MAP.containsKey(countryCode)) {
-      if (metadata.getMainCountryForCode()) {
-        COUNTRY_CODE_TO_REGION_CODE_MAP.get(countryCode).add(0, regionCode);
-      } else {
-        COUNTRY_CODE_TO_REGION_CODE_MAP.get(countryCode).add(regionCode);
-      }
-    } else {
-      // For most countries, there will be only one region code for the country dialing code.
-      List<String> listWithRegionCode = new ArrayList<String>(1);
-      listWithRegionCode.add(regionCode);
-      COUNTRY_CODE_TO_REGION_CODE_MAP.put(countryCode, listWithRegionCode);
-    }
   }
 
   private static String validateRE(String regex) {

File java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java

View file
 import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
 import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber.CountryCodeSource;
 
-import java.io.BufferedReader;
 import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.util.ArrayList;
  * @author Lara Rennie
  */
 public class PhoneNumberUtil {
-  public static final String COUNTRY_CODE_TO_REGION_CODE_MAP_FILE_SUFFIX = "_Mapping";
-
   // The minimum and maximum length of the national significant number.
   private static final int MIN_LENGTH_FOR_NSN = 3;
   private static final int MAX_LENGTH_FOR_NSN = 15;
   // should be first.
   // The initial capacity is set to 300 as there are roughly 200 different
   // country codes, and this offers a load factor of roughly 0.75.
-  private final Map<Integer, List<String> > countryCodeToRegionCodeMap =
+
+  private Map<Integer, List<String> > countryCodeToRegionCodeMap =
       new HashMap<Integer, List<String> >(300);
 
-  // The set of countries the library support.
-  // There are roughly 220 countries of them and we set the initial capacity of the HashSet to 300
-  // to offer a load factor of roughly 0.75.
+  // The set of countries the library supports.
+  // There are roughly 220 of them and we set the initial capacity of the HashSet to 300 to offer a
+  // load factor of roughly 0.75.
   private final Set<String> supportedCountries = new HashSet<String>(300);
 
+
   // The set of countries that share country code 1.
   // There are roughly 26 countries of them and we set the initial capacity of the HashSet to 35
   // to offer a load factor of roughly 0.75.
   private PhoneNumberUtil() {
   }
 
+  private void initializeCountryCodeToRegionCodeMap() {
+    countryCodeToRegionCodeMap.clear();
+    ArrayList<String> listWithRegionCode = new ArrayList<String>(24);
+    listWithRegionCode.add("US");
+    listWithRegionCode.add("AG");
+    listWithRegionCode.add("AI");
+    listWithRegionCode.add("AS");
+    listWithRegionCode.add("BB");
+    listWithRegionCode.add("BM");
+    listWithRegionCode.add("BS");
+    listWithRegionCode.add("CA");
+    listWithRegionCode.add("DM");
+    listWithRegionCode.add("DO");
+    listWithRegionCode.add("GD");
+    listWithRegionCode.add("GU");
+    listWithRegionCode.add("JM");
+    listWithRegionCode.add("KN");
+    listWithRegionCode.add("KY");
+    listWithRegionCode.add("LC");
+    listWithRegionCode.add("MP");
+    listWithRegionCode.add("MS");
+    listWithRegionCode.add("PR");
+    listWithRegionCode.add("TC");
+    listWithRegionCode.add("TT");
+    listWithRegionCode.add("VC");
+    listWithRegionCode.add("VG");
+    listWithRegionCode.add("VI");
+    countryCodeToRegionCodeMap.put(1, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(2);
+    listWithRegionCode.add("RU");
+    listWithRegionCode.add("KZ");
+    countryCodeToRegionCodeMap.put(7, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("EG");
+    countryCodeToRegionCodeMap.put(20, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("ZA");
+    countryCodeToRegionCodeMap.put(27, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("NL");
+    countryCodeToRegionCodeMap.put(31, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("GR");
+    countryCodeToRegionCodeMap.put(30, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("ES");
+    countryCodeToRegionCodeMap.put(34, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("BE");
+    countryCodeToRegionCodeMap.put(32, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("FR");
+    countryCodeToRegionCodeMap.put(33, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("IT");
+    countryCodeToRegionCodeMap.put(39, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("HU");
+    countryCodeToRegionCodeMap.put(36, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("AT");
+    countryCodeToRegionCodeMap.put(43, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("RO");
+    countryCodeToRegionCodeMap.put(40, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("CH");
+    countryCodeToRegionCodeMap.put(41, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("SE");
+    countryCodeToRegionCodeMap.put(46, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("NO");
+    countryCodeToRegionCodeMap.put(47, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(4);
+    listWithRegionCode.add("GB");
+    listWithRegionCode.add("GG");
+    listWithRegionCode.add("IM");
+    listWithRegionCode.add("JE");
+    countryCodeToRegionCodeMap.put(44, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("DK");
+    countryCodeToRegionCodeMap.put(45, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("PE");
+    countryCodeToRegionCodeMap.put(51, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("DE");
+    countryCodeToRegionCodeMap.put(49, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("PL");
+    countryCodeToRegionCodeMap.put(48, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("BR");
+    countryCodeToRegionCodeMap.put(55, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("AR");
+    countryCodeToRegionCodeMap.put(54, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("CU");
+    countryCodeToRegionCodeMap.put(53, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("MX");
+    countryCodeToRegionCodeMap.put(52, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("VE");
+    countryCodeToRegionCodeMap.put(58, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("CO");
+    countryCodeToRegionCodeMap.put(57, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("CL");
+    countryCodeToRegionCodeMap.put(56, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("PH");
+    countryCodeToRegionCodeMap.put(63, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("ID");
+    countryCodeToRegionCodeMap.put(62, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("AU");
+    countryCodeToRegionCodeMap.put(61, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("MY");
+    countryCodeToRegionCodeMap.put(60, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("NZ");
+    countryCodeToRegionCodeMap.put(64, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("SG");
+    countryCodeToRegionCodeMap.put(65, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("TH");
+    countryCodeToRegionCodeMap.put(66, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("VN");
+    countryCodeToRegionCodeMap.put(84, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("CN");
+    countryCodeToRegionCodeMap.put(86, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("JP");
+    countryCodeToRegionCodeMap.put(81, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("KR");
+    countryCodeToRegionCodeMap.put(82, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("AF");
+    countryCodeToRegionCodeMap.put(93, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("PK");
+    countryCodeToRegionCodeMap.put(92, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("MM");
+    countryCodeToRegionCodeMap.put(95, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("LK");
+    countryCodeToRegionCodeMap.put(94, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("IN");
+    countryCodeToRegionCodeMap.put(91, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("TR");
+    countryCodeToRegionCodeMap.put(90, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("IR");
+    countryCodeToRegionCodeMap.put(98, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(3);
+    listWithRegionCode.add("GP");
+    listWithRegionCode.add("BL");
+    listWithRegionCode.add("MF");
+    countryCodeToRegionCodeMap.put(590, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("BO");
+    countryCodeToRegionCodeMap.put(591, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("EC");
+    countryCodeToRegionCodeMap.put(593, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("GY");
+    countryCodeToRegionCodeMap.put(592, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("PY");
+    countryCodeToRegionCodeMap.put(595, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("GF");
+    countryCodeToRegionCodeMap.put(594, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("SR");
+    countryCodeToRegionCodeMap.put(597, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("MQ");
+    countryCodeToRegionCodeMap.put(596, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("AN");
+    countryCodeToRegionCodeMap.put(599, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("UY");
+    countryCodeToRegionCodeMap.put(598, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("NC");
+    countryCodeToRegionCodeMap.put(687, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("KI");
+    countryCodeToRegionCodeMap.put(686, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("WS");
+    countryCodeToRegionCodeMap.put(685, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("NU");
+    countryCodeToRegionCodeMap.put(683, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("CK");
+    countryCodeToRegionCodeMap.put(682, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("WF");
+    countryCodeToRegionCodeMap.put(681, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("PW");
+    countryCodeToRegionCodeMap.put(680, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("FJ");
+    countryCodeToRegionCodeMap.put(679, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("VU");
+    countryCodeToRegionCodeMap.put(678, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("SB");
+    countryCodeToRegionCodeMap.put(677, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("TO");
+    countryCodeToRegionCodeMap.put(676, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("PG");
+    countryCodeToRegionCodeMap.put(675, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("NR");
+    countryCodeToRegionCodeMap.put(674, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("BN");
+    countryCodeToRegionCodeMap.put(673, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("NF");
+    countryCodeToRegionCodeMap.put(672, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("MH");
+    countryCodeToRegionCodeMap.put(692, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("TK");
+    countryCodeToRegionCodeMap.put(690, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("FM");
+    countryCodeToRegionCodeMap.put(691, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("TV");
+    countryCodeToRegionCodeMap.put(688, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("PF");
+    countryCodeToRegionCodeMap.put(689, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("TL");
+    countryCodeToRegionCodeMap.put(670, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("GM");
+    countryCodeToRegionCodeMap.put(220, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("SN");
+    countryCodeToRegionCodeMap.put(221, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("MR");
+    countryCodeToRegionCodeMap.put(222, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("ML");
+    countryCodeToRegionCodeMap.put(223, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("TN");
+    countryCodeToRegionCodeMap.put(216, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("LY");
+    countryCodeToRegionCodeMap.put(218, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("MA");
+    countryCodeToRegionCodeMap.put(212, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("DZ");
+    countryCodeToRegionCodeMap.put(213, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("ST");
+    countryCodeToRegionCodeMap.put(239, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("CV");
+    countryCodeToRegionCodeMap.put(238, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("CM");
+    countryCodeToRegionCodeMap.put(237, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("CF");
+    countryCodeToRegionCodeMap.put(236, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("TD");
+    countryCodeToRegionCodeMap.put(235, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("NG");
+    countryCodeToRegionCodeMap.put(234, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("GH");
+    countryCodeToRegionCodeMap.put(233, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("SL");
+    countryCodeToRegionCodeMap.put(232, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("LR");
+    countryCodeToRegionCodeMap.put(231, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("MU");
+    countryCodeToRegionCodeMap.put(230, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("BJ");
+    countryCodeToRegionCodeMap.put(229, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("TG");
+    countryCodeToRegionCodeMap.put(228, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("NE");
+    countryCodeToRegionCodeMap.put(227, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("BF");
+    countryCodeToRegionCodeMap.put(226, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("CI");
+    countryCodeToRegionCodeMap.put(225, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("GN");
+    countryCodeToRegionCodeMap.put(224, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("KE");
+    countryCodeToRegionCodeMap.put(254, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("TZ");
+    countryCodeToRegionCodeMap.put(255, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("SO");
+    countryCodeToRegionCodeMap.put(252, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("DJ");
+    countryCodeToRegionCodeMap.put(253, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("RW");
+    countryCodeToRegionCodeMap.put(250, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("ET");
+    countryCodeToRegionCodeMap.put(251, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("SC");
+    countryCodeToRegionCodeMap.put(248, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("SD");
+    countryCodeToRegionCodeMap.put(249, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("IO");
+    countryCodeToRegionCodeMap.put(246, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("AO");
+    countryCodeToRegionCodeMap.put(244, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("GW");
+    countryCodeToRegionCodeMap.put(245, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("CG");
+    countryCodeToRegionCodeMap.put(242, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("CD");
+    countryCodeToRegionCodeMap.put(243, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("GQ");
+    countryCodeToRegionCodeMap.put(240, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("GA");
+    countryCodeToRegionCodeMap.put(241, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("MZ");
+    countryCodeToRegionCodeMap.put(258, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("UG");
+    countryCodeToRegionCodeMap.put(256, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("BI");
+    countryCodeToRegionCodeMap.put(257, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(3);
+    listWithRegionCode.add("RE");
+    listWithRegionCode.add("TF");
+    listWithRegionCode.add("YT");
+    countryCodeToRegionCodeMap.put(262, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("ZW");
+    countryCodeToRegionCodeMap.put(263, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("ZM");
+    countryCodeToRegionCodeMap.put(260, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("MG");
+    countryCodeToRegionCodeMap.put(261, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("LS");
+    countryCodeToRegionCodeMap.put(266, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("BW");
+    countryCodeToRegionCodeMap.put(267, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("NA");
+    countryCodeToRegionCodeMap.put(264, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("MW");
+    countryCodeToRegionCodeMap.put(265, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("SZ");
+    countryCodeToRegionCodeMap.put(268, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("KM");
+    countryCodeToRegionCodeMap.put(269, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("SH");
+    countryCodeToRegionCodeMap.put(290, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("ER");
+    countryCodeToRegionCodeMap.put(291, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("AW");
+    countryCodeToRegionCodeMap.put(297, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("FO");
+    countryCodeToRegionCodeMap.put(298, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("GL");
+    countryCodeToRegionCodeMap.put(299, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("BD");
+    countryCodeToRegionCodeMap.put(880, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("TW");
+    countryCodeToRegionCodeMap.put(886, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("PT");
+    countryCodeToRegionCodeMap.put(351, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("GI");
+    countryCodeToRegionCodeMap.put(350, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("MD");
+    countryCodeToRegionCodeMap.put(373, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("KP");
+    countryCodeToRegionCodeMap.put(850, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("EE");
+    countryCodeToRegionCodeMap.put(372, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("BY");
+    countryCodeToRegionCodeMap.put(375, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("AM");
+    countryCodeToRegionCodeMap.put(374, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("KH");
+    countryCodeToRegionCodeMap.put(855, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("MO");
+    countryCodeToRegionCodeMap.put(853, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("LV");
+    countryCodeToRegionCodeMap.put(371, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("LT");
+    countryCodeToRegionCodeMap.put(370, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("HK");
+    countryCodeToRegionCodeMap.put(852, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("RS");
+    countryCodeToRegionCodeMap.put(381, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("UA");
+    countryCodeToRegionCodeMap.put(380, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("ME");
+    countryCodeToRegionCodeMap.put(382, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("LA");
+    countryCodeToRegionCodeMap.put(856, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("MC");
+    countryCodeToRegionCodeMap.put(377, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("AD");
+    countryCodeToRegionCodeMap.put(376, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("VA");
+    countryCodeToRegionCodeMap.put(379, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("SM");
+    countryCodeToRegionCodeMap.put(378, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("MT");
+    countryCodeToRegionCodeMap.put(356, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("CY");
+    countryCodeToRegionCodeMap.put(357, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("FI");
+    countryCodeToRegionCodeMap.put(358, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("BG");
+    countryCodeToRegionCodeMap.put(359, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("LU");
+    countryCodeToRegionCodeMap.put(352, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("IE");
+    countryCodeToRegionCodeMap.put(353, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("IS");
+    countryCodeToRegionCodeMap.put(354, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("AL");
+    countryCodeToRegionCodeMap.put(355, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("BA");
+    countryCodeToRegionCodeMap.put(387, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("SI");
+    countryCodeToRegionCodeMap.put(386, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("HR");
+    countryCodeToRegionCodeMap.put(385, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("MK");
+    countryCodeToRegionCodeMap.put(389, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("SK");
+    countryCodeToRegionCodeMap.put(421, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("CZ");
+    countryCodeToRegionCodeMap.put(420, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("LI");
+    countryCodeToRegionCodeMap.put(423, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("TM");
+    countryCodeToRegionCodeMap.put(993, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("TJ");
+    countryCodeToRegionCodeMap.put(992, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("GE");
+    countryCodeToRegionCodeMap.put(995, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("AZ");
+    countryCodeToRegionCodeMap.put(994, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("KG");
+    countryCodeToRegionCodeMap.put(996, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("UZ");
+    countryCodeToRegionCodeMap.put(998, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("PM");
+    countryCodeToRegionCodeMap.put(508, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("HT");
+    countryCodeToRegionCodeMap.put(509, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("HN");
+    countryCodeToRegionCodeMap.put(504, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("NI");
+    countryCodeToRegionCodeMap.put(505, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("CR");
+    countryCodeToRegionCodeMap.put(506, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("PA");
+    countryCodeToRegionCodeMap.put(507, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("FK");
+    countryCodeToRegionCodeMap.put(500, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("BZ");
+    countryCodeToRegionCodeMap.put(501, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("MN");
+    countryCodeToRegionCodeMap.put(976, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("GT");
+    countryCodeToRegionCodeMap.put(502, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("SV");
+    countryCodeToRegionCodeMap.put(503, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("NP");
+    countryCodeToRegionCodeMap.put(977, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("AE");
+    countryCodeToRegionCodeMap.put(971, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("PS");
+    countryCodeToRegionCodeMap.put(970, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("OM");
+    countryCodeToRegionCodeMap.put(968, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("BT");
+    countryCodeToRegionCodeMap.put(975, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("QA");
+    countryCodeToRegionCodeMap.put(974, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("BH");
+    countryCodeToRegionCodeMap.put(973, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("IL");
+    countryCodeToRegionCodeMap.put(972, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("SY");
+    countryCodeToRegionCodeMap.put(963, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("JO");
+    countryCodeToRegionCodeMap.put(962, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("LB");
+    countryCodeToRegionCodeMap.put(961, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("MV");
+    countryCodeToRegionCodeMap.put(960, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("YE");
+    countryCodeToRegionCodeMap.put(967, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("SA");
+    countryCodeToRegionCodeMap.put(966, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("KW");
+    countryCodeToRegionCodeMap.put(965, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("IQ");
+    countryCodeToRegionCodeMap.put(964, listWithRegionCode);
+  }
+
   private void init(String filePrefix) {
     currentFilePrefix = filePrefix;
-    InputStream mapping =
-        PhoneNumberUtil.class.getResourceAsStream(currentFilePrefix +
-                                                  COUNTRY_CODE_TO_REGION_CODE_MAP_FILE_SUFFIX);
-    // Read in the mapping from country calling codes to region codes.
-    try {
-      BufferedReader in_reader = new BufferedReader(new InputStreamReader(mapping));
-      String line = null;
-      while ((line = in_reader.readLine()) != null) {
-        int countryCode = Integer.parseInt(line);
-        // This won't be null, as the line after country code will be two-letter region codes
-        // separated by a white space. The line will start with a white space.
-        line = in_reader.readLine();
-        int numberOfRegionCode = line.length() / 3;
-        // For most countries, there will be only one region code for the country dialing code.
-        ArrayList<String> listWithRegionCode = new ArrayList<String>(1);
-        for (int i = 0; i < numberOfRegionCode; i++) {
-          String twoLetterRegionCode = line.substring(i * 3 + 1, i * 3 + 3);
-          listWithRegionCode.add(twoLetterRegionCode);
-          supportedCountries.add(twoLetterRegionCode);
-        }
-        countryCodeToRegionCodeMap.put(countryCode, listWithRegionCode);
-      }
-      nanpaCountries.addAll(countryCodeToRegionCodeMap.get(NANPA_COUNTRY_CODE));
-      in_reader.close();
-      // Only preload US metadata at startup. Other metadata will be loaded later when needed.
-      loadMetadataForRegionFromFile(currentFilePrefix, "US");
-    } catch (IOException e) {
-      LOGGER.log(Level.WARNING, e.toString());
+    for (Integer countryCallingCode : countryCodeToRegionCodeMap.keySet()) {
+      supportedCountries.addAll(countryCodeToRegionCodeMap.get(countryCallingCode));
     }
+    nanpaCountries.addAll(countryCodeToRegionCodeMap.get(NANPA_COUNTRY_CODE));
   }
 
   private void loadMetadataForRegionFromFile(String filePrefix, String regionCode) {
     InputStream source =
         PhoneNumberUtil.class.getResourceAsStream(filePrefix + "_" + regionCode);
-    ObjectInputStream in = null;
+    ObjectInputStream in;
     try {
       in = new ObjectInputStream(source);
       PhoneMetadataCollection metadataCollection = new PhoneMetadataCollection();
     return normalizedNumber.toString();
   }
 
-  static synchronized PhoneNumberUtil getInstance(String baseFileLocation) {
+  static synchronized PhoneNumberUtil getInstance(
+      String baseFileLocation,
+      Map<Integer, List<String> > countryCodeToRegionCodeMap) {
     if (instance == null) {
       instance = new PhoneNumberUtil();
+      instance.countryCodeToRegionCodeMap.clear();
+      instance.countryCodeToRegionCodeMap = countryCodeToRegionCodeMap;
       instance.init(baseFileLocation);
     }
     return instance;
   public static synchronized PhoneNumberUtil getInstance() {
     if (instance == null) {
       instance = new PhoneNumberUtil();
+      instance.initializeCountryCodeToRegionCodeMap();
       instance.init(META_DATA_FILE_PREFIX);
     }
     return instance;

File java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_Mapping

-1
- US AG AI AS BB BM BS CA DM DO GD GU JM KN KY LC MP MS PR TC TT VC VG VI
-7
- RU KZ
-20
- EG
-27
- ZA
-31
- NL
-30
- GR
-34
- ES
-32
- BE
-33
- FR
-39
- IT
-36
- HU
-43
- AT
-40
- RO
-41
- CH
-46
- SE
-47
- NO
-44
- GB GG IM JE
-45
- DK
-51
- PE
-49
- DE
-48
- PL
-55
- BR
-54
- AR
-53
- CU
-52
- MX
-58
- VE
-57
- CO
-56
- CL
-63
- PH
-62
- ID
-61
- AU
-60
- MY
-64
- NZ
-65
- SG
-66
- TH
-84
- VN
-86
- CN
-81
- JP
-82
- KR
-93
- AF
-92
- PK
-95
- MM
-94
- LK
-91
- IN
-90
- TR
-98
- IR
-590
- GP BL MF
-591
- BO
-593
- EC
-592
- GY
-595
- PY
-594
- GF
-597
- SR
-596
- MQ
-599
- AN
-598
- UY
-687
- NC
-686
- KI
-685
- WS
-683
- NU
-682
- CK
-681
- WF
-680
- PW
-679
- FJ
-678
- VU
-677
- SB
-676
- TO
-675
- PG
-674
- NR
-673
- BN
-672
- NF
-692
- MH
-690
- TK
-691
- FM
-688
- TV
-689
- PF
-670
- TL
-220
- GM
-221
- SN
-222
- MR
-223
- ML
-216
- TN
-218
- LY
-212
- MA
-213
- DZ
-239
- ST
-238
- CV
-237
- CM
-236
- CF
-235
- TD
-234
- NG
-233
- GH
-232
- SL
-231
- LR
-230
- MU
-229
- BJ
-228
- TG
-227
- NE
-226
- BF
-225
- CI
-224
- GN
-254
- KE
-255
- TZ
-252
- SO
-253
- DJ
-250
- RW
-251
- ET
-248
- SC
-249
- SD
-246
- IO
-244
- AO
-245
- GW
-242
- CG
-243
- CD
-240
- GQ
-241
- GA
-258
- MZ
-256
- UG
-257
- BI
-262
- RE TF YT
-263
- ZW
-260
- ZM
-261
- MG
-266
- LS
-267
- BW
-264
- NA
-265
- MW
-268
- SZ
-269
- KM
-290
- SH
-291
- ER
-297
- AW
-298
- FO
-299
- GL
-880
- BD
-886
- TW
-351
- PT
-350
- GI
-373
- MD
-850
- KP
-372
- EE
-375
- BY
-374
- AM
-855
- KH
-853
- MO
-371
- LV
-370
- LT
-852
- HK
-381
- RS
-380
- UA
-382
- ME
-856
- LA
-377
- MC
-376
- AD
-379
- VA
-378
- SM
-356
- MT
-357
- CY
-358
- FI
-359
- BG
-352
- LU
-353
- IE
-354
- IS
-355
- AL
-387
- BA
-386
- SI
-385
- HR
-389
- MK
-421
- SK
-420
- CZ
-423
- LI
-993
- TM
-992
- TJ
-995
- GE
-994
- AZ
-996
- KG
-998
- UZ
-508
- PM
-509
- HT
-504
- HN
-505
- NI
-506
- CR
-507
- PA
-500
- FK
-501
- BZ
-976
- MN
-502
- GT
-503
- SV
-977
- NP
-971
- AE
-970
- PS
-968
- OM
-975
- BT
-974
- QA
-973
- BH
-972
- IL
-963
- SY
-962
- JO
-961
- LB
-960
- MV
-967
- YE
-966
- SA
-965
- KW
-964
- IQ

File java/test/com/google/i18n/phonenumbers/AsYouTypeFormatterTest.java

View file
  */
 public class AsYouTypeFormatterTest extends TestCase {
   private PhoneNumberUtil phoneUtil;
-  private static final String TEST_META_DATA_FILE_PREFIX =
-      "/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting";
 
   public AsYouTypeFormatterTest() {
-    PhoneNumberUtil.resetInstance();
-    phoneUtil = PhoneNumberUtil.getInstance(TEST_META_DATA_FILE_PREFIX);
+    phoneUtil = (new PhoneNumberUtilTest()).initilizePhoneUtilForTesting();
   }
 
   public void testAYTFUS() {

File java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java

View file
 import junit.framework.TestCase;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.regex.Pattern;
 
 /**
   private PhoneNumberUtil phoneUtil;
   private static final String TEST_META_DATA_FILE_PREFIX =
       "/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting";
+  private static final Map<Integer, List<String> > COUNTRY_CODE_TO_REGION_CODE_MAP_FOR_TESTING =
+      new HashMap<Integer, List<String> >();
 
   public PhoneNumberUtilTest() {
+    phoneUtil = initilizePhoneUtilForTesting();
+  }
+
+  PhoneNumberUtil initilizePhoneUtilForTesting() {
     PhoneNumberUtil.resetInstance();
-    phoneUtil = PhoneNumberUtil.getInstance(TEST_META_DATA_FILE_PREFIX);
+    return PhoneNumberUtil.getInstance(TEST_META_DATA_FILE_PREFIX,
+        COUNTRY_CODE_TO_REGION_CODE_MAP_FOR_TESTING);
+  }
+
+  static {
+    COUNTRY_CODE_TO_REGION_CODE_MAP_FOR_TESTING.clear();
+    ArrayList<String> listWithRegionCode = new ArrayList<String>(2);
+    listWithRegionCode.add("US");
+    listWithRegionCode.add("BS");
+    COUNTRY_CODE_TO_REGION_CODE_MAP_FOR_TESTING.put(1, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("IT");
+    COUNTRY_CODE_TO_REGION_CODE_MAP_FOR_TESTING.put(39, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("GB");
+    COUNTRY_CODE_TO_REGION_CODE_MAP_FOR_TESTING.put(44, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("DE");
+    COUNTRY_CODE_TO_REGION_CODE_MAP_FOR_TESTING.put(49, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("PL");
+    COUNTRY_CODE_TO_REGION_CODE_MAP_FOR_TESTING.put(48, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("AR");
+    COUNTRY_CODE_TO_REGION_CODE_MAP_FOR_TESTING.put(54, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("MX");
+    COUNTRY_CODE_TO_REGION_CODE_MAP_FOR_TESTING.put(52, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("AU");
+    COUNTRY_CODE_TO_REGION_CODE_MAP_FOR_TESTING.put(61, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("NZ");
+    COUNTRY_CODE_TO_REGION_CODE_MAP_FOR_TESTING.put(64, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("SG");
+    COUNTRY_CODE_TO_REGION_CODE_MAP_FOR_TESTING.put(65, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("JP");
+    COUNTRY_CODE_TO_REGION_CODE_MAP_FOR_TESTING.put(81, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("KR");
+    COUNTRY_CODE_TO_REGION_CODE_MAP_FOR_TESTING.put(82, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("AO");
+    COUNTRY_CODE_TO_REGION_CODE_MAP_FOR_TESTING.put(244, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(2);
+    listWithRegionCode.add("RE");
+    listWithRegionCode.add("YT");
+    COUNTRY_CODE_TO_REGION_CODE_MAP_FOR_TESTING.put(262, listWithRegionCode);
+
+    listWithRegionCode = new ArrayList<String>(1);
+    listWithRegionCode.add("AD");
+    COUNTRY_CODE_TO_REGION_CODE_MAP_FOR_TESTING.put(376, listWithRegionCode);
   }
 
   @Override

File java/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_Mapping

-1
- US BS
-39
- IT
-44
- GB
-49
- DE
-48
- PL
-54
- AR
-52
- MX
-61
- AU
-64
- NZ
-65
- SG
-81
- JP
-82
- KR
-244
- AO
-262
- RE YT
-376
- AD