phonelib 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/{README.rdoc → README.md} +116 -75
  3. data/data/extended_data.dat +0 -0
  4. data/data/libphonenumber/FALSEHOODS.md +16 -0
  5. data/data/libphonenumber/FAQ.md +8 -0
  6. data/data/libphonenumber/README.md +1 -1
  7. data/data/libphonenumber/cpp/src/phonenumbers/alternate_format.cc +108 -100
  8. data/data/libphonenumber/cpp/src/phonenumbers/lite_metadata.cc +10070 -10016
  9. data/data/libphonenumber/cpp/src/phonenumbers/metadata.cc +10938 -10884
  10. data/data/libphonenumber/cpp/src/phonenumbers/short_metadata.cc +2481 -2455
  11. data/data/libphonenumber/java/carrier/pom.xml +26 -4
  12. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/255_en +0 -0
  13. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/374_en +0 -0
  14. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/374_ru +0 -0
  15. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/421_en +0 -0
  16. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/66_en +0 -0
  17. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/91_en +0 -0
  18. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/93_fa +0 -0
  19. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/973_en +0 -0
  20. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/98_fa +0 -0
  21. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/992_en +0 -0
  22. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/994_en +0 -0
  23. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/config +0 -0
  24. data/data/libphonenumber/java/demo/pom.xml +6 -6
  25. data/data/libphonenumber/java/geocoder/pom.xml +26 -4
  26. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/1747_en +0 -0
  27. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/1934_en +0 -0
  28. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/371_en +0 -0
  29. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/44_en +0 -0
  30. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/504_en +0 -0
  31. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/82_bg +0 -0
  32. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/82_ca +0 -0
  33. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/82_el +0 -0
  34. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/82_es +0 -0
  35. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/82_fi +0 -0
  36. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/82_hi +0 -0
  37. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/82_hu +0 -0
  38. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/82_iw +0 -0
  39. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/82_ja +0 -0
  40. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/82_tr +0 -0
  41. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/91_en +0 -0
  42. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/93_en +0 -0
  43. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/93_fa +0 -0
  44. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/98_en +0 -0
  45. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/98_fa +0 -0
  46. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/992_en +0 -0
  47. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/994_en +0 -0
  48. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/config +0 -0
  49. data/data/libphonenumber/java/internal/prefixmapper/pom.xml +25 -3
  50. data/data/libphonenumber/java/libphonenumber/pom.xml +23 -2
  51. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/MetadataLoader.java +2 -1
  52. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/MultiFileMetadataSourceImpl.java +63 -70
  53. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberAlternateFormatsProto_595 +0 -0
  54. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AZ +0 -0
  55. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BD +0 -0
  56. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BG +0 -0
  57. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BH +0 -0
  58. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CI +0 -0
  59. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CN +0 -0
  60. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HK +0 -0
  61. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HN +0 -0
  62. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IN +0 -0
  63. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KN +0 -0
  64. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KW +0 -0
  65. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LV +0 -0
  66. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PY +0 -0
  67. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SK +0 -0
  68. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SN +0 -0
  69. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TC +0 -0
  70. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TH +0 -0
  71. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TJ +0 -0
  72. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TZ +0 -0
  73. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_US +0 -0
  74. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_AE +0 -0
  75. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_AR +0 -0
  76. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_BR +0 -0
  77. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_GB +0 -0
  78. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_IN +0 -0
  79. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_NO +0 -0
  80. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_SK +0 -0
  81. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_ZA +0 -0
  82. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/SingleFilePhoneNumberMetadataProto +0 -0
  83. data/data/libphonenumber/java/libphonenumber/test/com/google/i18n/phonenumbers/MultiFileMetadataSourceImplTest.java +25 -5
  84. data/data/libphonenumber/java/pom.xml +2 -2
  85. data/data/libphonenumber/java/release_notes.txt +45 -0
  86. data/data/libphonenumber/javascript/i18n/phonenumbers/demo-compiled.js +72 -70
  87. data/data/libphonenumber/javascript/i18n/phonenumbers/metadata.js +38 -32
  88. data/data/libphonenumber/javascript/i18n/phonenumbers/metadatalite.js +38 -32
  89. data/data/libphonenumber/resources/PhoneNumberAlternateFormats.xml +16 -0
  90. data/data/libphonenumber/resources/PhoneNumberMetadata.xml +232 -96
  91. data/data/libphonenumber/resources/ShortNumberMetadata.xml +188 -44
  92. data/data/libphonenumber/resources/carrier/en/255.txt +2 -0
  93. data/data/libphonenumber/resources/carrier/en/374.txt +3 -3
  94. data/data/libphonenumber/resources/carrier/en/421.txt +1 -0
  95. data/data/libphonenumber/resources/carrier/en/66.txt +1 -0
  96. data/data/libphonenumber/resources/carrier/en/91.txt +419 -253
  97. data/data/libphonenumber/resources/carrier/en/973.txt +1 -0
  98. data/data/libphonenumber/resources/carrier/en/992.txt +1 -0
  99. data/data/libphonenumber/resources/carrier/en/994.txt +3 -0
  100. data/data/libphonenumber/resources/carrier/fa/93.txt +24 -0
  101. data/data/libphonenumber/resources/carrier/fa/98.txt +30 -0
  102. data/data/libphonenumber/resources/carrier/ru/374.txt +28 -0
  103. data/data/libphonenumber/resources/geocoding/bg/82.txt +34 -0
  104. data/data/libphonenumber/resources/geocoding/ca/82.txt +34 -0
  105. data/data/libphonenumber/resources/geocoding/el/82.txt +28 -0
  106. data/data/libphonenumber/resources/geocoding/en/1.txt +2 -0
  107. data/data/libphonenumber/resources/geocoding/en/371.txt +3 -0
  108. data/data/libphonenumber/resources/geocoding/en/44.txt +19 -1
  109. data/data/libphonenumber/resources/geocoding/en/504.txt +19 -0
  110. data/data/libphonenumber/resources/geocoding/en/91.txt +1 -5
  111. data/data/libphonenumber/resources/geocoding/en/93.txt +52 -0
  112. data/data/libphonenumber/resources/geocoding/en/98.txt +0 -2
  113. data/data/libphonenumber/resources/geocoding/en/992.txt +77 -0
  114. data/data/libphonenumber/resources/geocoding/en/994.txt +98 -0
  115. data/data/libphonenumber/resources/geocoding/es/82.txt +33 -0
  116. data/data/libphonenumber/resources/geocoding/fa/93.txt +53 -0
  117. data/data/libphonenumber/resources/geocoding/fa/98.txt +0 -2
  118. data/data/libphonenumber/resources/geocoding/fi/82.txt +34 -0
  119. data/data/libphonenumber/resources/geocoding/hi/82.txt +36 -0
  120. data/data/libphonenumber/resources/geocoding/hu/82.txt +35 -0
  121. data/data/libphonenumber/resources/geocoding/iw/82.txt +37 -0
  122. data/data/libphonenumber/resources/geocoding/ja/82.txt +35 -0
  123. data/data/libphonenumber/resources/geocoding/tr/82.txt +35 -0
  124. data/data/libphonenumber/tools/java/common/pom.xml +2 -0
  125. data/data/libphonenumber/tools/java/cpp-build/pom.xml +4 -0
  126. data/data/libphonenumber/tools/java/data/pom.xml +1 -11
  127. data/data/libphonenumber/tools/java/java-build/pom.xml +2 -0
  128. data/data/phone_data.dat +0 -0
  129. data/lib/phonelib.rb +7 -6
  130. data/lib/phonelib/core.rb +116 -68
  131. data/lib/phonelib/data_importer.rb +23 -19
  132. data/lib/phonelib/data_importer_helper.rb +16 -16
  133. data/lib/phonelib/phone.rb +47 -137
  134. data/lib/phonelib/phone_analyzer.rb +27 -25
  135. data/lib/phonelib/phone_analyzer_helper.rb +16 -9
  136. data/lib/phonelib/phone_extended_data.rb +27 -17
  137. data/lib/phonelib/phone_formatter.rb +131 -0
  138. data/lib/phonelib/version.rb +2 -3
  139. data/lib/tasks/phonelib_tasks.rake +0 -2
  140. data/lib/validators/phone_validator.rb +24 -14
  141. metadata +42 -3
@@ -3,14 +3,14 @@
3
3
  <modelVersion>4.0.0</modelVersion>
4
4
  <groupId>com.googlecode.libphonenumber</groupId>
5
5
  <artifactId>carrier</artifactId>
6
- <version>1.35-SNAPSHOT</version>
6
+ <version>1.40-SNAPSHOT</version>
7
7
  <packaging>jar</packaging>
8
8
  <url>https://github.com/googlei18n/libphonenumber/</url>
9
9
 
10
10
  <parent>
11
11
  <groupId>com.googlecode.libphonenumber</groupId>
12
12
  <artifactId>libphonenumber-parent</artifactId>
13
- <version>7.4.3-SNAPSHOT</version>
13
+ <version>7.5.2-SNAPSHOT</version>
14
14
  </parent>
15
15
 
16
16
  <build>
@@ -28,18 +28,40 @@
28
28
  <targetPath>com/google/i18n/phonenumbers/carrier/testing_data</targetPath>
29
29
  </testResource>
30
30
  </testResources>
31
+ <plugins>
32
+ <plugin>
33
+ <groupId>org.codehaus.mojo</groupId>
34
+ <artifactId>animal-sniffer-maven-plugin</artifactId>
35
+ <version>1.15</version>
36
+ <executions>
37
+ <execution>
38
+ <phase>test</phase>
39
+ <goals>
40
+ <goal>check</goal>
41
+ </goals>
42
+ </execution>
43
+ </executions>
44
+ <configuration>
45
+ <signature>
46
+ <groupId>org.codehaus.mojo.signature</groupId>
47
+ <artifactId>java15</artifactId>
48
+ <version>1.0</version>
49
+ </signature>
50
+ </configuration>
51
+ </plugin>
52
+ </plugins>
31
53
  </build>
32
54
 
33
55
  <dependencies>
34
56
  <dependency>
35
57
  <groupId>com.googlecode.libphonenumber</groupId>
36
58
  <artifactId>libphonenumber</artifactId>
37
- <version>7.4.3-SNAPSHOT</version>
59
+ <version>7.5.2-SNAPSHOT</version>
38
60
  </dependency>
39
61
  <dependency>
40
62
  <groupId>com.googlecode.libphonenumber</groupId>
41
63
  <artifactId>prefixmapper</artifactId>
42
- <version>2.45-SNAPSHOT</version>
64
+ <version>2.50-SNAPSHOT</version>
43
65
  </dependency>
44
66
  </dependencies>
45
67
 
@@ -4,11 +4,11 @@
4
4
  <parent>
5
5
  <artifactId>libphonenumber-parent</artifactId>
6
6
  <groupId>com.googlecode.libphonenumber</groupId>
7
- <version>7.4.3-SNAPSHOT</version>
7
+ <version>7.5.2-SNAPSHOT</version>
8
8
  </parent>
9
9
  <groupId>com.googlecode.libphonenumber</groupId>
10
10
  <artifactId>demo</artifactId>
11
- <version>7.4.3-SNAPSHOT</version>
11
+ <version>7.5.2-SNAPSHOT</version>
12
12
 
13
13
  <properties>
14
14
  <gae.version>1.9.32</gae.version>
@@ -31,7 +31,7 @@
31
31
  <version>2.5</version>
32
32
  </dependency>
33
33
  <dependency>
34
- <groupId>org.apache.commons</groupId>
34
+ <groupId>commons-io</groupId>
35
35
  <artifactId>commons-io</artifactId>
36
36
  <version>1.3.2</version>
37
37
  </dependency>
@@ -48,17 +48,17 @@
48
48
  <dependency>
49
49
  <groupId>com.googlecode.libphonenumber</groupId>
50
50
  <artifactId>libphonenumber</artifactId>
51
- <version>7.4.3-SNAPSHOT</version>
51
+ <version>7.5.2-SNAPSHOT</version>
52
52
  </dependency>
53
53
  <dependency>
54
54
  <groupId>com.googlecode.libphonenumber</groupId>
55
55
  <artifactId>geocoder</artifactId>
56
- <version>2.45-SNAPSHOT</version>
56
+ <version>2.50-SNAPSHOT</version>
57
57
  </dependency>
58
58
  <dependency>
59
59
  <groupId>com.googlecode.libphonenumber</groupId>
60
60
  <artifactId>carrier</artifactId>
61
- <version>1.35-SNAPSHOT</version>
61
+ <version>1.40-SNAPSHOT</version>
62
62
  </dependency>
63
63
  </dependencies>
64
64
 
@@ -3,14 +3,14 @@
3
3
  <modelVersion>4.0.0</modelVersion>
4
4
  <groupId>com.googlecode.libphonenumber</groupId>
5
5
  <artifactId>geocoder</artifactId>
6
- <version>2.45-SNAPSHOT</version>
6
+ <version>2.50-SNAPSHOT</version>
7
7
  <packaging>jar</packaging>
8
8
  <url>https://github.com/googlei18n/libphonenumber/</url>
9
9
 
10
10
  <parent>
11
11
  <groupId>com.googlecode.libphonenumber</groupId>
12
12
  <artifactId>libphonenumber-parent</artifactId>
13
- <version>7.4.3-SNAPSHOT</version>
13
+ <version>7.5.2-SNAPSHOT</version>
14
14
  </parent>
15
15
 
16
16
  <build>
@@ -36,18 +36,40 @@
36
36
  <targetPath>com/google/i18n/phonenumbers/timezones/testing_data</targetPath>
37
37
  </testResource>
38
38
  </testResources>
39
+ <plugins>
40
+ <plugin>
41
+ <groupId>org.codehaus.mojo</groupId>
42
+ <artifactId>animal-sniffer-maven-plugin</artifactId>
43
+ <version>1.15</version>
44
+ <executions>
45
+ <execution>
46
+ <phase>test</phase>
47
+ <goals>
48
+ <goal>check</goal>
49
+ </goals>
50
+ </execution>
51
+ </executions>
52
+ <configuration>
53
+ <signature>
54
+ <groupId>org.codehaus.mojo.signature</groupId>
55
+ <artifactId>java15</artifactId>
56
+ <version>1.0</version>
57
+ </signature>
58
+ </configuration>
59
+ </plugin>
60
+ </plugins>
39
61
  </build>
40
62
 
41
63
  <dependencies>
42
64
  <dependency>
43
65
  <groupId>com.googlecode.libphonenumber</groupId>
44
66
  <artifactId>libphonenumber</artifactId>
45
- <version>7.4.3-SNAPSHOT</version>
67
+ <version>7.5.2-SNAPSHOT</version>
46
68
  </dependency>
47
69
  <dependency>
48
70
  <groupId>com.googlecode.libphonenumber</groupId>
49
71
  <artifactId>prefixmapper</artifactId>
50
- <version>2.45-SNAPSHOT</version>
72
+ <version>2.50-SNAPSHOT</version>
51
73
  </dependency>
52
74
  </dependencies>
53
75
 
@@ -3,14 +3,14 @@
3
3
  <modelVersion>4.0.0</modelVersion>
4
4
  <groupId>com.googlecode.libphonenumber</groupId>
5
5
  <artifactId>prefixmapper</artifactId>
6
- <version>2.45-SNAPSHOT</version>
6
+ <version>2.50-SNAPSHOT</version>
7
7
  <packaging>jar</packaging>
8
8
  <url>https://github.com/googlei18n/libphonenumber/</url>
9
9
 
10
10
  <parent>
11
11
  <groupId>com.googlecode.libphonenumber</groupId>
12
12
  <artifactId>libphonenumber-parent</artifactId>
13
- <version>7.4.3-SNAPSHOT</version>
13
+ <version>7.5.2-SNAPSHOT</version>
14
14
  <relativePath>../../pom.xml</relativePath>
15
15
  </parent>
16
16
 
@@ -23,13 +23,35 @@
23
23
  <targetPath>com/google/i18n/phonenumbers/geocoding/testing_data</targetPath>
24
24
  </testResource>
25
25
  </testResources>
26
+ <plugins>
27
+ <plugin>
28
+ <groupId>org.codehaus.mojo</groupId>
29
+ <artifactId>animal-sniffer-maven-plugin</artifactId>
30
+ <version>1.15</version>
31
+ <executions>
32
+ <execution>
33
+ <phase>test</phase>
34
+ <goals>
35
+ <goal>check</goal>
36
+ </goals>
37
+ </execution>
38
+ </executions>
39
+ <configuration>
40
+ <signature>
41
+ <groupId>org.codehaus.mojo.signature</groupId>
42
+ <artifactId>java15</artifactId>
43
+ <version>1.0</version>
44
+ </signature>
45
+ </configuration>
46
+ </plugin>
47
+ </plugins>
26
48
  </build>
27
49
 
28
50
  <dependencies>
29
51
  <dependency>
30
52
  <groupId>com.googlecode.libphonenumber</groupId>
31
53
  <artifactId>libphonenumber</artifactId>
32
- <version>7.4.3-SNAPSHOT</version>
54
+ <version>7.5.2-SNAPSHOT</version>
33
55
  </dependency>
34
56
  </dependencies>
35
57
 
@@ -3,14 +3,14 @@
3
3
  <modelVersion>4.0.0</modelVersion>
4
4
  <groupId>com.googlecode.libphonenumber</groupId>
5
5
  <artifactId>libphonenumber</artifactId>
6
- <version>7.4.3-SNAPSHOT</version>
6
+ <version>7.5.2-SNAPSHOT</version>
7
7
  <packaging>jar</packaging>
8
8
  <url>https://github.com/googlei18n/libphonenumber/</url>
9
9
 
10
10
  <parent>
11
11
  <groupId>com.googlecode.libphonenumber</groupId>
12
12
  <artifactId>libphonenumber-parent</artifactId>
13
- <version>7.4.3-SNAPSHOT</version>
13
+ <version>7.5.2-SNAPSHOT</version>
14
14
  </parent>
15
15
 
16
16
  <build>
@@ -31,6 +31,7 @@
31
31
  <plugins>
32
32
  <plugin>
33
33
  <artifactId>maven-jar-plugin</artifactId>
34
+ <version>2.2</version>
34
35
  <configuration>
35
36
  <excludes>
36
37
  <exclude>com/google/i18n/phonenumbers/SingleFileMetadataSourceImpl.class</exclude>
@@ -60,6 +61,26 @@
60
61
  </execution>
61
62
  </executions>
62
63
  </plugin>
64
+ <plugin>
65
+ <groupId>org.codehaus.mojo</groupId>
66
+ <artifactId>animal-sniffer-maven-plugin</artifactId>
67
+ <version>1.15</version>
68
+ <executions>
69
+ <execution>
70
+ <phase>test</phase>
71
+ <goals>
72
+ <goal>check</goal>
73
+ </goals>
74
+ </execution>
75
+ </executions>
76
+ <configuration>
77
+ <signature>
78
+ <groupId>org.codehaus.mojo.signature</groupId>
79
+ <artifactId>java15</artifactId>
80
+ <version>1.0</version>
81
+ </signature>
82
+ </configuration>
83
+ </plugin>
63
84
  </plugins>
64
85
  </build>
65
86
 
@@ -23,7 +23,8 @@ import java.io.InputStream;
23
23
  */
24
24
  public interface MetadataLoader {
25
25
  /**
26
- * Returns an input stream corresponding to the metadata to load.
26
+ * Returns an input stream corresponding to the metadata to load. This method may be called
27
+ * concurrently so implementations must be thread-safe.
27
28
  *
28
29
  * @param metadataFileName File name (including path) of metadata to load. File path is an
29
30
  * absolute class path like /com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto.
@@ -22,10 +22,8 @@ import com.google.i18n.phonenumbers.nano.Phonemetadata.PhoneMetadataCollection;
22
22
  import java.io.IOException;
23
23
  import java.io.InputStream;
24
24
  import java.io.ObjectInputStream;
25
- import java.util.Collections;
26
- import java.util.HashMap;
25
+ import java.util.concurrent.ConcurrentHashMap;
27
26
  import java.util.List;
28
- import java.util.Map;
29
27
  import java.util.logging.Level;
30
28
  import java.util.logging.Logger;
31
29
 
@@ -41,18 +39,14 @@ final class MultiFileMetadataSourceImpl implements MetadataSource {
41
39
  "/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto";
42
40
 
43
41
  // A mapping from a region code to the PhoneMetadata for that region.
44
- // Note: Synchronization, though only needed for the Android version of the library, is used in
45
- // all versions for consistency.
46
- private final Map<String, PhoneMetadata> regionToMetadataMap =
47
- Collections.synchronizedMap(new HashMap<String, PhoneMetadata>());
42
+ private final ConcurrentHashMap<String, PhoneMetadata> geographicalRegions =
43
+ new ConcurrentHashMap<String, PhoneMetadata>();
48
44
 
49
45
  // A mapping from a country calling code for a non-geographical entity to the PhoneMetadata for
50
46
  // that country calling code. Examples of the country calling codes include 800 (International
51
47
  // Toll Free Service) and 808 (International Shared Cost Service).
52
- // Note: Synchronization, though only needed for the Android version of the library, is used in
53
- // all versions for consistency.
54
- private final Map<Integer, PhoneMetadata> countryCodeToNonGeographicalMetadataMap =
55
- Collections.synchronizedMap(new HashMap<Integer, PhoneMetadata>());
48
+ private final ConcurrentHashMap<Integer, PhoneMetadata> nonGeographicalRegions =
49
+ new ConcurrentHashMap<Integer, PhoneMetadata>();
56
50
 
57
51
  // The prefix of the metadata files from which region data is loaded.
58
52
  private final String filePrefix;
@@ -60,97 +54,97 @@ final class MultiFileMetadataSourceImpl implements MetadataSource {
60
54
  // The metadata loader used to inject alternative metadata sources.
61
55
  private final MetadataLoader metadataLoader;
62
56
 
63
- // It is assumed that metadataLoader is not null.
64
- public MultiFileMetadataSourceImpl(String filePrefix, MetadataLoader metadataLoader) {
57
+ // It is assumed that metadataLoader is not null. If needed, checks should happen before passing
58
+ // here.
59
+ // @VisibleForTesting
60
+ MultiFileMetadataSourceImpl(String filePrefix, MetadataLoader metadataLoader) {
65
61
  this.filePrefix = filePrefix;
66
62
  this.metadataLoader = metadataLoader;
67
63
  }
68
64
 
69
- // It is assumed that metadataLoader is not null.
65
+ // It is assumed that metadataLoader is not null. If needed, checks should happen before passing
66
+ // here.
70
67
  public MultiFileMetadataSourceImpl(MetadataLoader metadataLoader) {
71
68
  this(META_DATA_FILE_PREFIX, metadataLoader);
72
69
  }
73
70
 
74
71
  @Override
75
72
  public PhoneMetadata getMetadataForRegion(String regionCode) {
76
- synchronized (regionToMetadataMap) {
77
- if (!regionToMetadataMap.containsKey(regionCode)) {
78
- // The regionCode here will be valid and won't be '001', so we don't need to worry about
79
- // what to pass in for the country calling code.
80
- loadMetadataFromFile(regionCode, 0);
81
- }
82
- }
83
- return regionToMetadataMap.get(regionCode);
73
+ PhoneMetadata metadata = geographicalRegions.get(regionCode);
74
+ return (metadata != null) ? metadata : loadMetadataFromFile(
75
+ regionCode, geographicalRegions, filePrefix, metadataLoader);
84
76
  }
85
77
 
86
78
  @Override
87
79
  public PhoneMetadata getMetadataForNonGeographicalRegion(int countryCallingCode) {
88
- synchronized (countryCodeToNonGeographicalMetadataMap) {
89
- if (!countryCodeToNonGeographicalMetadataMap.containsKey(countryCallingCode)) {
90
- List<String> regionCodes =
91
- CountryCodeToRegionCodeMap.getCountryCodeToRegionCodeMap().get(countryCallingCode);
92
- // We can assume that if the country calling code maps to the non-geo entity region code
93
- // then that's the only region code it maps to.
94
- if (regionCodes.size() == 1 &&
95
- PhoneNumberUtil.REGION_CODE_FOR_NON_GEO_ENTITY.equals(regionCodes.get(0))) {
96
- loadMetadataFromFile(PhoneNumberUtil.REGION_CODE_FOR_NON_GEO_ENTITY, countryCallingCode);
97
- }
98
- }
80
+ PhoneMetadata metadata = nonGeographicalRegions.get(countryCallingCode);
81
+ if (metadata != null) {
82
+ return metadata;
99
83
  }
100
- return countryCodeToNonGeographicalMetadataMap.get(countryCallingCode);
84
+ if (isNonGeographical(countryCallingCode)) {
85
+ return loadMetadataFromFile(
86
+ countryCallingCode, nonGeographicalRegions, filePrefix, metadataLoader);
87
+ }
88
+ // The given country calling code was for a geographical region.
89
+ return null;
90
+ }
91
+
92
+ // A country calling code is non-geographical if it only maps to the non-geographical region code,
93
+ // i.e. "001".
94
+ private boolean isNonGeographical(int countryCallingCode) {
95
+ List<String> regionCodes =
96
+ CountryCodeToRegionCodeMap.getCountryCodeToRegionCodeMap().get(countryCallingCode);
97
+ return (regionCodes.size() == 1
98
+ && PhoneNumberUtil.REGION_CODE_FOR_NON_GEO_ENTITY.equals(regionCodes.get(0)));
101
99
  }
102
100
 
101
+ /**
102
+ * @param key The geographical region code or the non-geographical region's country
103
+ * calling code.
104
+ * @param map The map to contain the mapping from {@code key} to the corresponding
105
+ * metadata.
106
+ * @param filePrefix The prefix of the metadata files from which region data is loaded.
107
+ * @param metadataLoader The metadata loader used to inject alternative metadata sources.
108
+ */
103
109
  // @VisibleForTesting
104
- void loadMetadataFromFile(String regionCode, int countryCallingCode) {
105
- boolean isNonGeoRegion = PhoneNumberUtil.REGION_CODE_FOR_NON_GEO_ENTITY.equals(regionCode);
106
- String fileName = filePrefix + "_" +
107
- (isNonGeoRegion ? String.valueOf(countryCallingCode) : regionCode);
110
+ static <T> PhoneMetadata loadMetadataFromFile(
111
+ T key, ConcurrentHashMap<T, PhoneMetadata> map, String filePrefix,
112
+ MetadataLoader metadataLoader) {
113
+ // We assume key.toString() is well-defined.
114
+ String fileName = filePrefix + "_" + key;
108
115
  InputStream source = metadataLoader.loadMetadata(fileName);
109
116
  if (source == null) {
110
- logger.log(Level.SEVERE, "missing metadata: " + fileName);
111
117
  throw new IllegalStateException("missing metadata: " + fileName);
112
118
  }
113
- try {
114
- PhoneMetadataCollection metadataCollection =
115
- loadMetadataAndCloseInput(new ObjectInputStream(source));
116
- PhoneMetadata[] metadataList = metadataCollection.metadata;
117
- if (metadataList.length == 0) {
118
- logger.log(Level.SEVERE, "empty metadata: " + fileName);
119
- throw new IllegalStateException("empty metadata: " + fileName);
120
- }
121
- if (metadataList.length > 1) {
122
- logger.log(Level.WARNING, "invalid metadata (too many entries): " + fileName);
123
- }
124
- PhoneMetadata metadata = metadataList[0];
125
- if (isNonGeoRegion) {
126
- countryCodeToNonGeographicalMetadataMap.put(countryCallingCode, metadata);
127
- } else {
128
- regionToMetadataMap.put(regionCode, metadata);
129
- }
130
- } catch (IOException e) {
131
- logger.log(Level.SEVERE, "cannot load/parse metadata: " + fileName, e);
132
- throw new RuntimeException("cannot load/parse metadata: " + fileName, e);
119
+ PhoneMetadataCollection metadataCollection = loadMetadataAndCloseInput(source);
120
+ PhoneMetadata[] metadataList = metadataCollection.metadata;
121
+ if (metadataList.length == 0) {
122
+ throw new IllegalStateException("empty metadata: " + fileName);
123
+ }
124
+ if (metadataList.length > 1) {
125
+ logger.log(Level.WARNING, "invalid metadata (too many entries): " + fileName);
133
126
  }
127
+ PhoneMetadata metadata = metadataList[0];
128
+ PhoneMetadata oldValue = map.putIfAbsent(key, metadata);
129
+ return (oldValue != null) ? oldValue : metadata;
134
130
  }
135
131
 
136
132
  /**
137
- * Loads the metadata protocol buffer from the given stream and closes the stream afterwards. Any
138
- * exceptions that occur while reading or closing the stream are ignored.
139
- *
140
- * @param source the non-null stream from which metadata is to be read.
141
- * @return the loaded metadata protocol buffer.
133
+ * Loads and returns the metadata protocol buffer from the given stream and closes the stream.
142
134
  */
143
- private static PhoneMetadataCollection loadMetadataAndCloseInput(ObjectInputStream source) {
135
+ private static PhoneMetadataCollection loadMetadataAndCloseInput(InputStream source) {
144
136
  // The size of the byte buffer used for deserializing the phone number metadata files for each
145
137
  // region.
146
138
  final int MULTI_FILE_BUFFER_SIZE = 16 * 1024;
147
139
 
148
- PhoneMetadataCollection metadataCollection = new PhoneMetadataCollection();
149
140
  try {
150
- metadataCollection.mergeFrom(
151
- MetadataManager.convertStreamToByteBuffer(source, MULTI_FILE_BUFFER_SIZE));
141
+ // Read in metadata for each region.
142
+ PhoneMetadataCollection metadataCollection = new PhoneMetadataCollection();
143
+ metadataCollection.mergeFrom(MetadataManager.convertStreamToByteBuffer(
144
+ new ObjectInputStream(source), MULTI_FILE_BUFFER_SIZE));
145
+ return metadataCollection;
152
146
  } catch (IOException e) {
153
- logger.log(Level.WARNING, "error reading input (ignored)", e);
147
+ throw new RuntimeException("cannot load/parse metadata", e);
154
148
  } finally {
155
149
  try {
156
150
  source.close();
@@ -158,6 +152,5 @@ final class MultiFileMetadataSourceImpl implements MetadataSource {
158
152
  logger.log(Level.WARNING, "error closing input stream (ignored)", e);
159
153
  }
160
154
  }
161
- return metadataCollection;
162
155
  }
163
156
  }