Browse Source

JAVA,GEODATA: libphonenumber 3.9.

pull/567/head
Philippe Liard 14 years ago
committed by Mihaela Rosca
parent
commit
ed81076fe0
85 changed files with 4150 additions and 474 deletions
  1. +17
    -0
      java/release_notes.txt
  2. +64
    -16
      java/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java
  3. +34
    -3
      java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java
  4. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AM
  5. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BE
  6. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BH
  7. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BJ
  8. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BR
  9. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BT
  10. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BZ
  11. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CI
  12. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CL
  13. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CN
  14. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DK
  15. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DM
  16. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DZ
  17. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EC
  18. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EG
  19. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FJ
  20. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GR
  21. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HR
  22. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HT
  23. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IN
  24. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IQ
  25. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IS
  26. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_JM
  27. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KE
  28. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KG
  29. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KH
  30. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KR
  31. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LA
  32. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LB
  33. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LR
  34. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MA
  35. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MD
  36. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ML
  37. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MO
  38. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MX
  39. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MY
  40. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NE
  41. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NG
  42. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PG
  43. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PH
  44. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PK
  45. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PY
  46. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_QA
  47. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SA
  48. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SD
  49. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SG
  50. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SN
  51. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TD
  52. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TG
  53. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TH
  54. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TN
  55. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TT
  56. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_UG
  57. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_YE
  58. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ZA
  59. BIN
      java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ZM
  60. +8
    -5
      java/src/com/google/i18n/phonenumbers/geocoding/AreaCodeMap.java
  61. +20
    -30
      java/src/com/google/i18n/phonenumbers/geocoding/AreaCodeMapStorageStrategy.java
  62. +0
    -5
      java/src/com/google/i18n/phonenumbers/geocoding/DefaultMapStorage.java
  63. +124
    -111
      java/src/com/google/i18n/phonenumbers/geocoding/FlyweightMapStorage.java
  64. BIN
      java/src/com/google/i18n/phonenumbers/geocoding/data/381_sr
  65. BIN
      java/src/com/google/i18n/phonenumbers/geocoding/data/49_de
  66. BIN
      java/src/com/google/i18n/phonenumbers/geocoding/data/81_en
  67. BIN
      java/src/com/google/i18n/phonenumbers/geocoding/data/config
  68. +135
    -2
      java/test/com/google/i18n/phonenumbers/AsYouTypeFormatterTest.java
  69. +7
    -0
      java/test/com/google/i18n/phonenumbers/ExampleNumbersTest.java
  70. +4
    -1
      java/test/com/google/i18n/phonenumbers/PhoneNumberMatcherTest.java
  71. +25
    -0
      java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java
  72. BIN
      java/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_KR
  73. BIN
      java/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_SG
  74. +7
    -7
      java/test/com/google/i18n/phonenumbers/geocoding/AreaCodeMapTest.java
  75. +46
    -19
      java/test/com/google/i18n/phonenumbers/geocoding/FlyweightMapStorageTest.java
  76. +337
    -247
      resources/PhoneNumberMetaData.xml
  77. +13
    -12
      resources/PhoneNumberMetaDataForTesting.xml
  78. +1692
    -1
      resources/geocoding/de/49.txt
  79. +1546
    -0
      resources/geocoding/en/81.txt
  80. +51
    -0
      resources/geocoding/sr/381.txt
  81. +8
    -3
      tools/java/common/src/com/google/i18n/phonenumbers/tools/BuildMetadataFromXml.java
  82. BIN
      tools/java/cpp-build/target/cpp-build-1.0-SNAPSHOT-jar-with-dependencies.jar
  83. +2
    -5
      tools/java/java-build/src/com/google/i18n/phonenumbers/tools/GenerateAreaCodeData.java
  84. BIN
      tools/java/java-build/target/java-build-1.0-SNAPSHOT-jar-with-dependencies.jar
  85. +10
    -7
      tools/java/java-build/test/com/google/i18n/phonenumbers/tools/GenerateAreaCodeDataTest.java

+ 17
- 0
java/release_notes.txt View File

@ -1,3 +1,20 @@
September 13th, 2011: libphonenumber-3.9
* Code changes
- Enable AsYouTypeFormatter to handle long IDD and NDD.
- Allow the presence of an IDD following a +.
- Fix formatting of phone numbers which contain only 0s in the national number.
- Refactored some code in geocoding including AreaCodeMap and the storage
strategies.
* Metadata changes
- Updates: AM, BE, BH, BJ, BR, BT, BZ, CI, CL, CN, DE, DK, DM, DZ, EC, EG, FJ,
GR, HR, HT, IN, IQ, IS, JM, KE, KG, KH, KR, LA, LB, LR, MA, MD, ML, MO, MX,
MY, NE, NG, PG, PH, PK, PY, QA, SA, SD, SG, SN, TD, TG, TH, TN, TT, UG, YE,
ZA, ZM
- New geocoding data for: AC, CG, CU, CV, EG, ET, FI, FI, FI, GL, JP, KM, MA,
MA, MU, MU, MU, MZ, RS, SH, SH, SL, SO, ST, TG, TG, TG, UG, ZM
- Updated geocoding data for: AR, DE
August 11th, 2011: libphonenumber-3.8
* Code changes
- Fix to demo to not throw null-ptr exceptions for invalid NANPA numbers


+ 64
- 16
java/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java View File

@ -45,7 +45,11 @@ public class AsYouTypeFormatter {
private String currentFormattingPattern = "";
private StringBuilder accruedInput = new StringBuilder();
private StringBuilder accruedInputWithoutFormatting = new StringBuilder();
// This indicates whether AsYouTypeFormatter is currently doing the formatting.
private boolean ableToFormat = true;
// Set to true when users enter their own formatting. AsYouTypeFormatter will do no formatting at
// all when this is set to true.
private boolean inputHasFormatting = false;
private boolean isInternationalFormatting = false;
private boolean isExpectingCountryCallingCode = false;
private final PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
@ -91,7 +95,13 @@ public class AsYouTypeFormatter {
// The position of a digit upon which inputDigitAndRememberPosition is most recently invoked, as
// found in accruedInputWithoutFormatting.
private int positionToRemember = 0;
// This contains anything that has been entered so far preceding the national significant number,
// and it is formatted (e.g. with space inserted). For example, this can contain IDD, country
// code, and/or NDD, etc.
private StringBuilder prefixBeforeNationalNumber = new StringBuilder();
// This contains the national prefix that has been extracted. It contains only digits without
// formatting.
private String nationalPrefixExtracted = "";
private StringBuilder nationalNumber = new StringBuilder();
private List<NumberFormat> possibleFormats = new ArrayList<NumberFormat>();
@ -137,6 +147,9 @@ public class AsYouTypeFormatter {
}
if (createFormattingTemplate(numberFormat)) {
currentFormattingPattern = pattern;
// With a new formatting template, the matched position using the old template needs to be
// reset.
lastMatchPosition = 0;
return true;
} else { // Remove the current number format from possibleFormats.
it.remove();
@ -236,8 +249,10 @@ public class AsYouTypeFormatter {
lastMatchPosition = 0;
currentFormattingPattern = "";
prefixBeforeNationalNumber.setLength(0);
nationalPrefixExtracted = "";
nationalNumber.setLength(0);
ableToFormat = true;
inputHasFormatting = false;
positionToRemember = 0;
originalPosition = 0;
isInternationalFormatting = false;
@ -283,13 +298,29 @@ public class AsYouTypeFormatter {
// sign (accepted at the start of the number only).
if (!isDigitOrLeadingPlusSign(nextChar)) {
ableToFormat = false;
inputHasFormatting = true;
} else {
nextChar = normalizeAndAccrueDigitsAndPlusSign(nextChar, rememberPosition);
}
if (!ableToFormat) {
// When we are unable to format because of reasons other than that formatting chars have been
// entered, it can be due to really long IDDs or NDDs. If that is the case, we might be able
// to do formatting again after extracting them.
if (inputHasFormatting) {
return accruedInput.toString();
} else if (attemptToExtractIdd()) {
if (attemptToExtractCountryCallingCode()) {
return attemptToChoosePatternWithPrefixExtracted();
}
} else if (ableToExtractLongerNdd()) {
// Add an additional space to separate long NDD and national significant number for
// readability.
prefixBeforeNationalNumber.append(" ");
return attemptToChoosePatternWithPrefixExtracted();
}
return accruedInput.toString();
}
nextChar = normalizeAndAccrueDigitsAndPlusSign(nextChar, rememberPosition);
// We start to attempt to format only when at least MIN_LEADING_DIGITS_LENGTH digits (the plus
// sign is counted as a digit as well for this purpose) have been entered.
switch (accruedInputWithoutFormatting.length()) {
@ -300,26 +331,17 @@ public class AsYouTypeFormatter {
case 3:
if (attemptToExtractIdd()) {
isExpectingCountryCallingCode = true;
} else { // No IDD or plus sign is found, must be entering in national format.
removeNationalPrefixFromNationalNumber();
} else { // No IDD or plus sign is found, might be entering in national format.
nationalPrefixExtracted = removeNationalPrefixFromNationalNumber();
return attemptToChooseFormattingPattern();
}
case 4:
case 5:
default:
if (isExpectingCountryCallingCode) {
if (attemptToExtractCountryCallingCode()) {
isExpectingCountryCallingCode = false;
}
return prefixBeforeNationalNumber + nationalNumber.toString();
}
// We make a last attempt to extract a country calling code at the 6th digit because the
// maximum length of IDD and country calling code are both 3.
case 6:
if (isExpectingCountryCallingCode && !attemptToExtractCountryCallingCode()) {
ableToFormat = false;
return accruedInput.toString();
}
default:
if (possibleFormats.size() > 0) { // The formatting pattern is already chosen.
String tempNationalNumber = inputDigitHelper(nextChar);
// See if the accrued digits can be formatted properly already. If not, use the results
@ -341,6 +363,28 @@ public class AsYouTypeFormatter {
}
}
private String attemptToChoosePatternWithPrefixExtracted() {
ableToFormat = true;
isExpectingCountryCallingCode = false;
possibleFormats.clear();
return attemptToChooseFormattingPattern();
}
// Some national prefixes are a substring of others. If extracting the shorter NDD doesn't result
// in a number we can format, we try to see if we can extract a longer version here.
private boolean ableToExtractLongerNdd() {
if (nationalPrefixExtracted.length() > 0) {
// Put the extracted NDD back to the national number before attempting to extract a new NDD.
nationalNumber.insert(0, nationalPrefixExtracted);
// Remove the previously extracted NDD from prefixBeforeNationalNumber. We cannot simply set
// it to empty string because people sometimes enter national prefix after country code, e.g
// +44 (0)20-1234-5678.
int indexOfPreviousNdd = prefixBeforeNationalNumber.lastIndexOf(nationalPrefixExtracted);
prefixBeforeNationalNumber.setLength(indexOfPreviousNdd);
}
return !nationalPrefixExtracted.equals(removeNationalPrefixFromNationalNumber());
}
private boolean isDigitOrLeadingPlusSign(char nextChar) {
return Character.isDigit(nextChar) ||
(accruedInput.length() == 1 &&
@ -408,13 +452,14 @@ public class AsYouTypeFormatter {
}
}
private void removeNationalPrefixFromNationalNumber() {
// Returns the national prefix extracted, or an empty string if it is not present.
private String removeNationalPrefixFromNationalNumber() {
int startOfNationalNumber = 0;
if (currentMetaData.getCountryCode() == 1 && nationalNumber.charAt(0) == '1') {
startOfNationalNumber = 1;
prefixBeforeNationalNumber.append("1 ");
isInternationalFormatting = true;
} else if (currentMetaData.hasNationalPrefix()) {
} else if (currentMetaData.hasNationalPrefixForParsing()) {
Pattern nationalPrefixForParsing =
regexCache.getPatternForRegex(currentMetaData.getNationalPrefixForParsing());
Matcher m = nationalPrefixForParsing.matcher(nationalNumber);
@ -427,7 +472,9 @@ public class AsYouTypeFormatter {
prefixBeforeNationalNumber.append(nationalNumber.substring(0, startOfNationalNumber));
}
}
String nationalPrefix = nationalNumber.substring(0, startOfNationalNumber);
nationalNumber.delete(0, startOfNationalNumber);
return nationalPrefix;
}
/**
@ -447,6 +494,7 @@ public class AsYouTypeFormatter {
int startOfCountryCallingCode = iddMatcher.end();
nationalNumber.setLength(0);
nationalNumber.append(accruedInputWithoutFormatting.substring(startOfCountryCallingCode));
prefixBeforeNationalNumber.setLength(0);
prefixBeforeNationalNumber.append(
accruedInputWithoutFormatting.substring(0, startOfCountryCallingCode));
if (accruedInputWithoutFormatting.charAt(0) != PhoneNumberUtil.PLUS_SIGN) {


+ 34
- 3
java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java View File

@ -978,6 +978,12 @@ public class PhoneNumberUtil {
* @return the formatted phone number
*/
public String format(PhoneNumber number, PhoneNumberFormat numberFormat) {
if (number.getNationalNumber() == 0 && number.hasRawInput()) {
String rawInput = number.getRawInput();
if (rawInput.length() > 0) {
return rawInput;
}
}
StringBuilder formattedNumber = new StringBuilder(20);
format(number, numberFormat, formattedNumber);
return formattedNumber.toString();
@ -1486,7 +1492,7 @@ public class PhoneNumberUtil {
public PhoneNumber getExampleNumberForType(String regionCode, PhoneNumberType type) {
// Check the region code is valid.
if (!isValidRegionCode(regionCode)) {
LOGGER.log(Level.WARNING, "Invalid or unknown region code provided.");
LOGGER.log(Level.SEVERE, "Invalid or unknown region code provided: " + regionCode);
return null;
}
PhoneNumberDesc desc = getNumberDescByType(getMetadataForRegion(regionCode), type);
@ -1968,6 +1974,10 @@ public class PhoneNumberUtil {
// 0 if fullNumber doesn't start with a valid country calling code, and leaves nationalNumber
// unmodified.
int extractCountryCode(StringBuilder fullNumber, StringBuilder nationalNumber) {
if ((fullNumber.length() == 0) || (fullNumber.charAt(0) == '0')) {
// Country codes do not begin with a '0'.
return 0;
}
int potentialCountryCode;
int numberLength = fullNumber.length();
for (int i = 1; i <= MAX_LENGTH_COUNTRY_CODE && i <= numberLength; i++) {
@ -2398,8 +2408,29 @@ public class PhoneNumberUtil {
// Check to see if the number is given in international format so we know whether this number is
// from the default region or not.
StringBuilder normalizedNationalNumber = new StringBuilder();
int countryCode = maybeExtractCountryCode(nationalNumber.toString(), regionMetadata,
normalizedNationalNumber, keepRawInput, phoneNumber);
int countryCode = 0;
try {
// TODO: This method should really just take in the string buffer that has already
// been created, and just remove the prefix, rather than taking in a string and then
// outputting a string buffer.
countryCode = maybeExtractCountryCode(nationalNumber.toString(), regionMetadata,
normalizedNationalNumber, keepRawInput, phoneNumber);
} catch (NumberParseException e) {
Matcher matcher = PLUS_CHARS_PATTERN.matcher(nationalNumber.toString());
if (e.getErrorType() == NumberParseException.ErrorType.INVALID_COUNTRY_CODE &&
matcher.lookingAt()) {
// Strip the plus-char, and try again.
countryCode = maybeExtractCountryCode(nationalNumber.substring(matcher.end()),
regionMetadata, normalizedNationalNumber,
keepRawInput, phoneNumber);
if (countryCode == 0) {
throw new NumberParseException(NumberParseException.ErrorType.INVALID_COUNTRY_CODE,
"Could not interpret numbers after plus-sign.");
}
} else {
throw new NumberParseException(e.getErrorType(), e.getMessage());
}
}
if (countryCode != 0) {
String phoneNumberRegion = getRegionCodeForCountryCode(countryCode);
if (!phoneNumberRegion.equals(defaultRegion)) {


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AM View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BE View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BH View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BJ View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BR View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BT View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BZ View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CI View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CL View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CN View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DK View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DM View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DZ View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EC View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EG View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FJ View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GR View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HR View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HT View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IN View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IQ View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IS View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_JM View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KE View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KG View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KH View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KR View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LA View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LB View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LR View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MA View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MD View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ML View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MO View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MX View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MY View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NE View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NG View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PG View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PH View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PK View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PY View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_QA View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SA View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SD View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SG View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SN View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TD View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TG View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TH View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TN View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TT View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_UG View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_YE View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ZA View File


BIN
java/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ZM View File


+ 8
- 5
java/src/com/google/i18n/phonenumbers/geocoding/AreaCodeMap.java View File

@ -129,12 +129,15 @@ public class AreaCodeMap implements Externalizable {
* Supports Java Serialization.
*/
public void writeExternal(ObjectOutput objectOutput) throws IOException {
objectOutput.writeBoolean(areaCodeMapStorage.isFlyweight());
objectOutput.writeBoolean(areaCodeMapStorage instanceof FlyweightMapStorage);
areaCodeMapStorage.writeExternal(objectOutput);
}
/**
* Returns the description of the geographical area the {@code number} corresponds to.
* Returns the description of the geographical area the {@code number} corresponds to. This method
* distinguishes the case of an invalid prefix and a prefix for which the name is not available in
* the current language. If the description is not available in the current language an empty
* string is returned. If no description was found for the provided number, null is returned.
*
* @param number the phone number to look up
* @return the description of the geographical area
@ -142,7 +145,7 @@ public class AreaCodeMap implements Externalizable {
String lookup(PhoneNumber number) {
int numOfEntries = areaCodeMapStorage.getNumOfEntries();
if (numOfEntries == 0) {
return "";
return null;
}
long phonePrefix =
Long.parseLong(number.getCountryCode() + phoneUtil.getNationalSignificantNumber(number));
@ -156,7 +159,7 @@ public class AreaCodeMap implements Externalizable {
}
currentIndex = binarySearch(0, currentIndex, phonePrefix);
if (currentIndex < 0) {
return "";
return null;
}
int currentPrefix = areaCodeMapStorage.getPrefix(currentIndex);
if (phonePrefix == currentPrefix) {
@ -164,7 +167,7 @@ public class AreaCodeMap implements Externalizable {
}
currentSetOfLengths = currentSetOfLengths.headSet(possibleLength);
}
return "";
return null;
}
/**


+ 20
- 30
java/src/com/google/i18n/phonenumbers/geocoding/AreaCodeMapStorageStrategy.java View File

@ -29,35 +29,10 @@ import java.util.TreeSet;
*
* @author Philippe Liard
*/
// @VisibleForTesting
abstract class AreaCodeMapStorageStrategy {
protected int numOfEntries = 0;
protected final TreeSet<Integer> possibleLengths = new TreeSet<Integer>();
public AreaCodeMapStorageStrategy() {}
/**
* Returns whether the underlying implementation of this abstract class is flyweight.
* It is expected to be flyweight if it implements the {@code FlyweightMapStorage} class.
*
* @return whether the underlying implementation of this abstract class is flyweight
*/
public abstract boolean isFlyweight();
/**
* @return the number of entries contained in the area code map
*/
public int getNumOfEntries() {
return numOfEntries;
}
/**
* @return the set containing the possible lengths of prefixes
*/
public TreeSet<Integer> getPossibleLengths() {
return possibleLengths;
}
/**
* Gets the phone number prefix located at the provided {@code index}.
*
@ -68,7 +43,8 @@ abstract class AreaCodeMapStorageStrategy {
/**
* Gets the description corresponding to the phone number prefix located at the provided {@code
* index}.
* index}. If the description is not available in the current language an empty string is
* returned.
*
* @param index the index of the phone number prefix that needs to be returned
* @return the description corresponding to the phone number prefix at the provided index
@ -102,16 +78,30 @@ abstract class AreaCodeMapStorageStrategy {
*/
public abstract void writeExternal(ObjectOutput objectOutput) throws IOException;
/**
* @return the number of entries contained in the area code map
*/
public int getNumOfEntries() {
return numOfEntries;
}
/**
* @return the set containing the possible lengths of prefixes
*/
public TreeSet<Integer> getPossibleLengths() {
return possibleLengths;
}
@Override
public String toString() {
StringBuilder output = new StringBuilder();
int numOfEntries = getNumOfEntries();
for (int i = 0; i < numOfEntries; i++) {
output.append(getPrefix(i));
output.append("|");
output.append(getDescription(i));
output.append("\n");
output.append(getPrefix(i))
.append("|")
.append(getDescription(i))
.append("\n");
}
return output.toString();
}


+ 0
- 5
java/src/com/google/i18n/phonenumbers/geocoding/DefaultMapStorage.java View File

@ -35,11 +35,6 @@ class DefaultMapStorage extends AreaCodeMapStorageStrategy {
private int[] phoneNumberPrefixes;
private String[] descriptions;
@Override
public boolean isFlyweight() {
return false;
}
@Override
public int getPrefix(int index) {
return phoneNumberPrefixes[index];


+ 124
- 111
java/src/com/google/i18n/phonenumbers/geocoding/FlyweightMapStorage.java View File

@ -21,7 +21,6 @@ import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.SortedSet;
@ -34,10 +33,10 @@ import java.util.TreeSet;
*
* @author Philippe Liard
*/
class FlyweightMapStorage extends AreaCodeMapStorageStrategy {
final class FlyweightMapStorage extends AreaCodeMapStorageStrategy {
// Size of short and integer types in bytes.
private static final int SHORT_SIZE = Short.SIZE / 8;
private static final int INT_SIZE = Integer.SIZE / 8;
private static final int SHORT_NUM_BYTES = Short.SIZE / 8;
private static final int INT_NUM_BYTES = Integer.SIZE / 8;
// The number of bytes used to store a phone number prefix.
private int prefixSizeInBytes;
@ -51,120 +50,60 @@ class FlyweightMapStorage extends AreaCodeMapStorageStrategy {
// Sorted string array of unique description strings.
private String[] descriptionPool;
public FlyweightMapStorage() {}
@Override
public boolean isFlyweight() {
return true;
}
/**
* Gets the minimum number of bytes that can be used to store the provided {@code value}.
*/
private static int getOptimalNumberOfBytesForValue(int value) {
return value <= Short.MAX_VALUE ? SHORT_SIZE : INT_SIZE;
}
/**
* Stores the provided {@code value} to the provided byte {@code buffer} at the specified {@code
* index} using the provided {@code wordSize} in bytes. Note that only integer and short sizes are
* supported.
*
* @param buffer the byte buffer to which the value is stored
* @param wordSize the number of bytes used to store the provided value
* @param index the index to which the value is stored
* @param value the value that is stored assuming it does not require more than the specified
* number of bytes.
*/
private static void storeWordInBuffer(ByteBuffer buffer, int wordSize, int index, int value) {
index *= wordSize;
if (wordSize == SHORT_SIZE) {
buffer.putShort(index, (short) value);
} else {
buffer.putInt(index, value);
}
}
/**
* Reads the {@code value} at the specified {@code index} from the provided byte {@code buffer}.
* Note that only integer and short sizes are supported.
*
* @param buffer the byte buffer from which the value is read
* @param wordSize the number of bytes used to store the value
* @param index the index where the value is read from
*
* @return the value read from the buffer
*/
private static int readWordFromBuffer(ByteBuffer buffer, int wordSize, int index) {
index *= wordSize;
return wordSize == SHORT_SIZE ? buffer.getShort(index) : buffer.getInt(index);
}
@Override
public int getPrefix(int index) {
return readWordFromBuffer(phoneNumberPrefixes, prefixSizeInBytes, index);
}
/**
* This implementation returns the same string (same identity) when called for multiple indexes
* corresponding to prefixes that have the same description.
*/
@Override
public String getDescription(int index) {
return descriptionPool[readWordFromBuffer(descriptionIndexes, descIndexSizeInBytes, index)];
int indexInDescriptionPool =
readWordFromBuffer(descriptionIndexes, descIndexSizeInBytes, index);
return descriptionPool[indexInDescriptionPool];
}
@Override
public void readFromSortedMap(SortedMap<Integer, String> sortedAreaCodeMap) {
public void readFromSortedMap(SortedMap<Integer, String> areaCodeMap) {
SortedSet<String> descriptionsSet = new TreeSet<String>();
numOfEntries = sortedAreaCodeMap.size();
prefixSizeInBytes = getOptimalNumberOfBytesForValue(sortedAreaCodeMap.lastKey());
numOfEntries = areaCodeMap.size();
prefixSizeInBytes = getOptimalNumberOfBytesForValue(areaCodeMap.lastKey());
phoneNumberPrefixes = ByteBuffer.allocate(numOfEntries * prefixSizeInBytes);
// Fill the phone number prefixes byte buffer, the set of possible lengths of prefixes and the
// description set.
int index = 0;
for (Entry<Integer, String> entry : sortedAreaCodeMap.entrySet()) {
for (Entry<Integer, String> entry : areaCodeMap.entrySet()) {
int prefix = entry.getKey();
storeWordInBuffer(phoneNumberPrefixes, prefixSizeInBytes, index++, prefix);
storeWordInBuffer(phoneNumberPrefixes, prefixSizeInBytes, index, prefix);
possibleLengths.add((int) Math.log10(prefix) + 1);
descriptionsSet.add(entry.getValue());
++index;
}
createDescriptionPool(descriptionsSet, areaCodeMap);
}
// Create the description pool.
/**
* Creates the description pool from the provided set of string descriptions and area code map.
*/
private void createDescriptionPool(SortedSet<String> descriptionsSet,
SortedMap<Integer, String> areaCodeMap) {
descIndexSizeInBytes = getOptimalNumberOfBytesForValue(descriptionsSet.size() - 1);
descriptionIndexes = ByteBuffer.allocate(numOfEntries * descIndexSizeInBytes);
descriptionPool = new String[descriptionsSet.size()];
descriptionsSet.toArray(descriptionPool);
// Map the phone number prefixes to the descriptions.
index = 0;
int index = 0;
for (int i = 0; i < numOfEntries; i++) {
int prefix = readWordFromBuffer(phoneNumberPrefixes, prefixSizeInBytes, i);
String description = sortedAreaCodeMap.get(prefix);
int positionInDescriptionPool =
Arrays.binarySearch(descriptionPool, description, new Comparator<String>() {
public int compare(String o1, String o2) { return o1.compareTo(o2); }
});
storeWordInBuffer(descriptionIndexes, descIndexSizeInBytes, index++,
positionInDescriptionPool);
}
}
/**
* Stores a value which is read from the provided {@code objectInput} to the provided byte {@code
* buffer} at the specified {@code index}.
*
* @param objectInput the object input stream from which the value is read
* @param wordSize the number of bytes used to store the value read from the stream
* @param outputBuffer the byte buffer to which the value is stored
* @param index the index where the value is stored in the buffer
* @throws IOException if an error occurred reading from the object input stream
*/
private static void readExternalWord(ObjectInput objectInput, int wordSize,
ByteBuffer outputBuffer, int index) throws IOException {
index *= wordSize;
if (wordSize == SHORT_SIZE) {
outputBuffer.putShort(index, objectInput.readShort());
} else {
outputBuffer.putInt(index, objectInput.readInt());
String description = areaCodeMap.get(prefix);
int positionInDescriptionPool = Arrays.binarySearch(descriptionPool, description);
storeWordInBuffer(descriptionIndexes, descIndexSizeInBytes, index, positionInDescriptionPool);
++index;
}
}
@ -173,12 +112,14 @@ class FlyweightMapStorage extends AreaCodeMapStorageStrategy {
// Read binary words sizes.
prefixSizeInBytes = objectInput.readInt();
descIndexSizeInBytes = objectInput.readInt();
// Read possible lengths.
int sizeOfLengths = objectInput.readInt();
possibleLengths.clear();
for (int i = 0; i < sizeOfLengths; i++) {
possibleLengths.add(objectInput.readInt());
}
// Read description pool size.
int descriptionPoolSize = objectInput.readInt();
// Read description pool.
@ -189,10 +130,17 @@ class FlyweightMapStorage extends AreaCodeMapStorageStrategy {
String description = objectInput.readUTF();
descriptionPool[i] = description;
}
// Read entries.
readEntries(objectInput);
}
/**
* Reads the area code entries from the provided input stream and stores them to the internal byte
* buffers.
*/
private void readEntries(ObjectInput objectInput) throws IOException {
numOfEntries = objectInput.readInt();
if (phoneNumberPrefixes == null || phoneNumberPrefixes.capacity() < numOfEntries) {
phoneNumberPrefixes = ByteBuffer.allocate(numOfEntries * prefixSizeInBytes);
phoneNumberPrefixes = ByteBuffer.allocate(numOfEntries * prefixSizeInBytes);
}
if (descriptionIndexes == null || descriptionIndexes.capacity() < numOfEntries) {
descriptionIndexes = ByteBuffer.allocate(numOfEntries * descIndexSizeInBytes);
@ -203,43 +151,26 @@ class FlyweightMapStorage extends AreaCodeMapStorageStrategy {
}
}
/**
* Writes the value read from the provided byte {@code buffer} at the specified {@code index} to
* the provided {@code objectOutput}.
*
* @param objectOutput the object output stream to which the value is written
* @param wordSize the number of bytes used to store the value
* @param inputBuffer the byte buffer from which the value is read
* @param index the index of the value in the the byte buffer
* @throws IOException if an error occurred writing to the provided object output stream
*/
private static void writeExternalWord(ObjectOutput objectOutput, int wordSize,
ByteBuffer inputBuffer, int index) throws IOException {
index *= wordSize;
if (wordSize == SHORT_SIZE) {
objectOutput.writeShort(inputBuffer.getShort(index));
} else {
objectOutput.writeInt(inputBuffer.getInt(index));
}
}
@Override
public void writeExternal(ObjectOutput objectOutput) throws IOException {
// Write binary words sizes.
objectOutput.writeInt(prefixSizeInBytes);
objectOutput.writeInt(descIndexSizeInBytes);
// Write possible lengths.
int sizeOfLengths = possibleLengths.size();
objectOutput.writeInt(sizeOfLengths);
for (Integer length : possibleLengths) {
objectOutput.writeInt(length);
}
// Write description pool size.
objectOutput.writeInt(descriptionPool.length);
// Write description pool.
for (String description : descriptionPool) {
objectOutput.writeUTF(description);
}
// Write entries.
objectOutput.writeInt(numOfEntries);
for (int i = 0; i < numOfEntries; i++) {
@ -247,4 +178,86 @@ class FlyweightMapStorage extends AreaCodeMapStorageStrategy {
writeExternalWord(objectOutput, descIndexSizeInBytes, descriptionIndexes, i);
}
}
/**
* Gets the minimum number of bytes that can be used to store the provided {@code value}.
*/
private static int getOptimalNumberOfBytesForValue(int value) {
return value <= Short.MAX_VALUE ? SHORT_NUM_BYTES : INT_NUM_BYTES;
}
/**
* Stores a value which is read from the provided {@code objectInput} to the provided byte {@code
* buffer} at the specified {@code index}.
*
* @param objectInput the object input stream from which the value is read
* @param wordSize the number of bytes used to store the value read from the stream
* @param outputBuffer the byte buffer to which the value is stored
* @param index the index where the value is stored in the buffer
* @throws IOException if an error occurred reading from the object input stream
*/
private static void readExternalWord(ObjectInput objectInput, int wordSize,
ByteBuffer outputBuffer, int index) throws IOException {
int wordIndex = index * wordSize;
if (wordSize == SHORT_NUM_BYTES) {
outputBuffer.putShort(wordIndex, objectInput.readShort());
} else {
outputBuffer.putInt(wordIndex, objectInput.readInt());
}
}
/**
* Writes the value read from the provided byte {@code buffer} at the specified {@code index} to
* the provided {@code objectOutput}.
*
* @param objectOutput the object output stream to which the value is written
* @param wordSize the number of bytes used to store the value
* @param inputBuffer the byte buffer from which the value is read
* @param index the index of the value in the the byte buffer
* @throws IOException if an error occurred writing to the provided object output stream
*/
private static void writeExternalWord(ObjectOutput objectOutput, int wordSize,
ByteBuffer inputBuffer, int index) throws IOException {
int wordIndex = index * wordSize;
if (wordSize == SHORT_NUM_BYTES) {
objectOutput.writeShort(inputBuffer.getShort(wordIndex));
} else {
objectOutput.writeInt(inputBuffer.getInt(wordIndex));
}
}
/**
* Reads the {@code value} at the specified {@code index} from the provided byte {@code buffer}.
* Note that only integer and short sizes are supported.
*
* @param buffer the byte buffer from which the value is read
* @param wordSize the number of bytes used to store the value
* @param index the index where the value is read from
*
* @return the value read from the buffer
*/
private static int readWordFromBuffer(ByteBuffer buffer, int wordSize, int index) {
int wordIndex = index * wordSize;
return wordSize == SHORT_NUM_BYTES ? buffer.getShort(wordIndex) : buffer.getInt(wordIndex);
}
/**
* Stores the provided {@code value} to the provided byte {@code buffer} at the specified {@code
* index} using the provided {@code wordSize} in bytes. Note that only integer and short sizes are
* supported.
*
* @param buffer the byte buffer to which the value is stored
* @param wordSize the number of bytes used to store the provided value
* @param index the index to which the value is stored
* @param value the value that is stored assuming it does not require more than the specified
* number of bytes.
*/
private static void storeWordInBuffer(ByteBuffer buffer, int wordSize, int index, int value) {
int wordIndex = index * wordSize;
if (wordSize == SHORT_NUM_BYTES) {
buffer.putShort(wordIndex, (short) value);
} else {
buffer.putInt(wordIndex, value);
}
}
}

BIN
java/src/com/google/i18n/phonenumbers/geocoding/data/381_sr View File


BIN
java/src/com/google/i18n/phonenumbers/geocoding/data/49_de View File


BIN
java/src/com/google/i18n/phonenumbers/geocoding/data/81_en View File


BIN
java/src/com/google/i18n/phonenumbers/geocoding/data/config View File


+ 135
- 2
java/test/com/google/i18n/phonenumbers/AsYouTypeFormatterTest.java View File

@ -68,9 +68,9 @@ public class AsYouTypeFormatterTest extends TestCase {
assertEquals("+48 88 123", formatter.inputDigit('3'));
assertEquals("+48 88 123 1", formatter.inputDigit('1'));
// A plus sign can only appear at the beginning of the number; otherwise, no formatting is
// applied.
// applied.
assertEquals("+48881231+", formatter.inputDigit('+'));
assertEquals("+48881231+2", formatter.inputDigit('2'));
assertEquals("+48881231+2", formatter.inputDigit('2'));
}
public void testTooLongNumberMatchingMultipleLeadingDigits() {
@ -731,4 +731,137 @@ public class AsYouTypeFormatterTest extends TestCase {
assertEquals("+81 3332 2 567", formatter.inputDigit('7'));
assertEquals("+81 3332 2 5678", formatter.inputDigit('8'));
}
public void testAYTFLongIDD_AU() {
AsYouTypeFormatter formatter = phoneUtil.getAsYouTypeFormatter("AU");
// 0011 1 650 253 2250
assertEquals("0", formatter.inputDigit('0'));
assertEquals("00", formatter.inputDigit('0'));
assertEquals("001", formatter.inputDigit('1'));
assertEquals("0011", formatter.inputDigit('1'));
assertEquals("0011 1 ", formatter.inputDigit('1'));
assertEquals("0011 1 6", formatter.inputDigit('6'));
assertEquals("0011 1 65", formatter.inputDigit('5'));
assertEquals("0011 1 650", formatter.inputDigit('0'));
assertEquals("0011 1 650 2", formatter.inputDigit('2'));
assertEquals("0011 1 650 25", formatter.inputDigit('5'));
assertEquals("0011 1 650 253", formatter.inputDigit('3'));
assertEquals("0011 1 650 253 2", formatter.inputDigit('2'));
assertEquals("0011 1 650 253 22", formatter.inputDigit('2'));
assertEquals("0011 1 650 253 222", formatter.inputDigit('2'));
assertEquals("0011 1 650 253 2222", formatter.inputDigit('2'));
// 0011 81 3332 2 5678
formatter.clear();
assertEquals("0", formatter.inputDigit('0'));
assertEquals("00", formatter.inputDigit('0'));
assertEquals("001", formatter.inputDigit('1'));
assertEquals("0011", formatter.inputDigit('1'));
assertEquals("00118", formatter.inputDigit('8'));
assertEquals("0011 81 ", formatter.inputDigit('1'));
assertEquals("0011 81 3", formatter.inputDigit('3'));
assertEquals("0011 81 33", formatter.inputDigit('3'));
assertEquals("0011 81 33 3", formatter.inputDigit('3'));
assertEquals("0011 81 3332", formatter.inputDigit('2'));
assertEquals("0011 81 3332 2", formatter.inputDigit('2'));
assertEquals("0011 81 3332 2 5", formatter.inputDigit('5'));
assertEquals("0011 81 3332 2 56", formatter.inputDigit('6'));
assertEquals("0011 81 3332 2 567", formatter.inputDigit('7'));
assertEquals("0011 81 3332 2 5678", formatter.inputDigit('8'));
// 0011 244 250 253 222
formatter.clear();
assertEquals("0", formatter.inputDigit('0'));
assertEquals("00", formatter.inputDigit('0'));
assertEquals("001", formatter.inputDigit('1'));
assertEquals("0011", formatter.inputDigit('1'));
assertEquals("00112", formatter.inputDigit('2'));
assertEquals("001124", formatter.inputDigit('4'));
assertEquals("0011 244 ", formatter.inputDigit('4'));
assertEquals("0011 244 2", formatter.inputDigit('2'));
assertEquals("0011 244 25", formatter.inputDigit('5'));
assertEquals("0011 244 250", formatter.inputDigit('0'));
assertEquals("0011 244 250 2", formatter.inputDigit('2'));
assertEquals("0011 244 250 25", formatter.inputDigit('5'));
assertEquals("0011 244 250 253", formatter.inputDigit('3'));
assertEquals("0011 244 250 253 2", formatter.inputDigit('2'));
assertEquals("0011 244 250 253 22", formatter.inputDigit('2'));
assertEquals("0011 244 250 253 222", formatter.inputDigit('2'));
}
public void testAYTFLongIDD_KR() {
AsYouTypeFormatter formatter = phoneUtil.getAsYouTypeFormatter("KR");
// 00300 1 650 253 2222
assertEquals("0", formatter.inputDigit('0'));
assertEquals("00", formatter.inputDigit('0'));
assertEquals("003", formatter.inputDigit('3'));
assertEquals("0030", formatter.inputDigit('0'));
assertEquals("00300", formatter.inputDigit('0'));
assertEquals("00300 1 ", formatter.inputDigit('1'));
assertEquals("00300 1 6", formatter.inputDigit('6'));
assertEquals("00300 1 65", formatter.inputDigit('5'));
assertEquals("00300 1 650", formatter.inputDigit('0'));
assertEquals("00300 1 650 2", formatter.inputDigit('2'));
assertEquals("00300 1 650 25", formatter.inputDigit('5'));
assertEquals("00300 1 650 253", formatter.inputDigit('3'));
assertEquals("00300 1 650 253 2", formatter.inputDigit('2'));
assertEquals("00300 1 650 253 22", formatter.inputDigit('2'));
assertEquals("00300 1 650 253 222", formatter.inputDigit('2'));
assertEquals("00300 1 650 253 2222", formatter.inputDigit('2'));
}
public void testAYTFLongNDD_KR() {
AsYouTypeFormatter formatter = phoneUtil.getAsYouTypeFormatter("KR");
// 08811-9876-7890
assertEquals("0", formatter.inputDigit('0'));
assertEquals("08", formatter.inputDigit('8'));
assertEquals("088", formatter.inputDigit('8'));
assertEquals("0881", formatter.inputDigit('1'));
assertEquals("08811", formatter.inputDigit('1'));
assertEquals("08811-9", formatter.inputDigit('9'));
assertEquals("08811-98", formatter.inputDigit('8'));
assertEquals("08811-987", formatter.inputDigit('7'));
assertEquals("08811-9876", formatter.inputDigit('6'));
assertEquals("08811-9876-7", formatter.inputDigit('7'));
assertEquals("08811-9876-78", formatter.inputDigit('8'));
assertEquals("08811-9876-789", formatter.inputDigit('9'));
assertEquals("08811-9876-7890", formatter.inputDigit('0'));
// 08500 11-9876-7890
formatter.clear();
assertEquals("0", formatter.inputDigit('0'));
assertEquals("08", formatter.inputDigit('8'));
assertEquals("085", formatter.inputDigit('5'));
assertEquals("0850", formatter.inputDigit('0'));
assertEquals("08500 ", formatter.inputDigit('0'));
assertEquals("08500 1", formatter.inputDigit('1'));
assertEquals("08500 11", formatter.inputDigit('1'));
assertEquals("08500 11-9", formatter.inputDigit('9'));
assertEquals("08500 11-98", formatter.inputDigit('8'));
assertEquals("08500 11-987", formatter.inputDigit('7'));
assertEquals("08500 11-9876", formatter.inputDigit('6'));
assertEquals("08500 11-9876-7", formatter.inputDigit('7'));
assertEquals("08500 11-9876-78", formatter.inputDigit('8'));
assertEquals("08500 11-9876-789", formatter.inputDigit('9'));
assertEquals("08500 11-9876-7890", formatter.inputDigit('0'));
}
public void testAYTFLongNDD_SG() {
AsYouTypeFormatter formatter = phoneUtil.getAsYouTypeFormatter("SG");
// 777777 9876 7890
assertEquals("7", formatter.inputDigit('7'));
assertEquals("77", formatter.inputDigit('7'));
assertEquals("777", formatter.inputDigit('7'));
assertEquals("7777", formatter.inputDigit('7'));
assertEquals("77777", formatter.inputDigit('7'));
assertEquals("777777 ", formatter.inputDigit('7'));
assertEquals("777777 9", formatter.inputDigit('9'));
assertEquals("777777 98", formatter.inputDigit('8'));
assertEquals("777777 987", formatter.inputDigit('7'));
assertEquals("777777 9876", formatter.inputDigit('6'));
assertEquals("777777 9876 7", formatter.inputDigit('7'));
assertEquals("777777 9876 78", formatter.inputDigit('8'));
assertEquals("777777 9876 789", formatter.inputDigit('9'));
assertEquals("777777 9876 7890", formatter.inputDigit('0'));
}
}

+ 7
- 0
java/test/com/google/i18n/phonenumbers/ExampleNumbersTest.java View File

@ -166,4 +166,11 @@ public class ExampleNumbersTest extends TestCase {
}
assertEquals(0, wrongTypeCases.size());
}
public void testEveryRegionHasAnExampleNumber() throws Exception {
for (String regionCode : phoneNumberUtil.getSupportedRegions()) {
PhoneNumber exampleNumber = phoneNumberUtil.getExampleNumber(regionCode);
assertNotNull("None found for region " + regionCode, exampleNumber);
}
}
}

+ 4
- 1
java/test/com/google/i18n/phonenumbers/PhoneNumberMatcherTest.java View File

@ -392,6 +392,8 @@ public class PhoneNumberMatcherTest extends TestCase {
new NumberTest("1979-2011 100%", RegionCode.US),
new NumberTest("800 234 1 111x1111", RegionCode.US),
new NumberTest("+494949-4-94", RegionCode.DE), // National number in wrong format
new NumberTest("\uFF14\uFF11\uFF15\uFF16\uFF16\uFF16\uFF16-\uFF17\uFF17\uFF17\uFF17",
RegionCode.US)
};
/**
@ -440,8 +442,8 @@ public class PhoneNumberMatcherTest extends TestCase {
}
public void testNonMatchesWithStrictGroupLeniency() throws Exception {
int matchFoundCount = 0;
List<NumberTest> testCases = new ArrayList<NumberTest>();
testCases.addAll(Arrays.asList(IMPOSSIBLE_CASES));
testCases.addAll(Arrays.asList(POSSIBLE_ONLY_CASES));
testCases.addAll(Arrays.asList(VALID_CASES));
doTestNumberNonMatchesForLeniency(testCases, Leniency.STRICT_GROUPING);
@ -455,6 +457,7 @@ public class PhoneNumberMatcherTest extends TestCase {
public void testNonMatchesExactGroupLeniency() throws Exception {
List<NumberTest> testCases = new ArrayList<NumberTest>();
testCases.addAll(Arrays.asList(IMPOSSIBLE_CASES));
testCases.addAll(Arrays.asList(POSSIBLE_ONLY_CASES));
testCases.addAll(Arrays.asList(VALID_CASES));
testCases.addAll(Arrays.asList(STRICT_GROUPING_CASES));


+ 25
- 0
java/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java View File

@ -98,6 +98,11 @@ public class PhoneNumberUtilTest extends TestCase {
new PhoneNumber().setCountryCode(1).setNationalNumber(650253000L);
private static final PhoneNumber US_TOLLFREE =
new PhoneNumber().setCountryCode(1).setNationalNumber(8002530000L);
private static final PhoneNumber US_SPOOF =
new PhoneNumber().setCountryCode(1).setNationalNumber(0L);
private static final PhoneNumber US_SPOOF_WITH_RAW_INPUT =
new PhoneNumber().setCountryCode(1).setNationalNumber(0L)
.setRawInput("000-000-0000");
public PhoneNumberUtilTest() {
phoneUtil = initializePhoneUtilForTesting();
@ -322,6 +327,11 @@ public class PhoneNumberUtilTest extends TestCase {
assertEquals("900 253 0000", phoneUtil.format(US_PREMIUM, PhoneNumberFormat.NATIONAL));
assertEquals("+1 900 253 0000", phoneUtil.format(US_PREMIUM, PhoneNumberFormat.INTERNATIONAL));
assertEquals("+1-900-253-0000", phoneUtil.format(US_PREMIUM, PhoneNumberFormat.RFC3966));
// Numbers with all zeros in the national number part will be formatted by using the raw_input
// if that is available no matter which format is specified.
assertEquals("000-000-0000",
phoneUtil.format(US_SPOOF_WITH_RAW_INPUT, PhoneNumberFormat.NATIONAL));
assertEquals("0", phoneUtil.format(US_SPOOF, PhoneNumberFormat.NATIONAL));
}
public void testFormatBSNumber() {
@ -1294,6 +1304,11 @@ public class PhoneNumberUtilTest extends TestCase {
// recognise the country calling code and parse accordingly.
assertEquals(NZ_NUMBER, phoneUtil.parse("01164 3 331 6005", RegionCode.US));
assertEquals(NZ_NUMBER, phoneUtil.parse("+64 3 331 6005", RegionCode.US));
// We should ignore the leading plus here, since it is not followed by a valid country code but
// instead is followed by the IDD for the US.
assertEquals(NZ_NUMBER, phoneUtil.parse("+01164 3 331 6005", RegionCode.US));
assertEquals(NZ_NUMBER, phoneUtil.parse("+0064 3 331 6005", RegionCode.NZ));
assertEquals(NZ_NUMBER, phoneUtil.parse("+ 00 64 3 331 6005", RegionCode.NZ));
PhoneNumber nzNumber = new PhoneNumber();
nzNumber.setCountryCode(64).setNationalNumber(64123456L);
@ -1476,6 +1491,16 @@ public class PhoneNumberUtilTest extends TestCase {
NumberParseException.ErrorType.INVALID_COUNTRY_CODE,
e.getErrorType());
}
try {
String plusAndIddAndInvalidCountryCode = "+ 00 210 3 331 6005";
phoneUtil.parse(plusAndIddAndInvalidCountryCode, RegionCode.NZ);
fail("This should not parse without throwing an exception.");
} catch (NumberParseException e) {
// Expected this exception. 00 is a correct IDD, but 210 is not a valid country code.
assertEquals("Wrong error type stored in exception.",
NumberParseException.ErrorType.INVALID_COUNTRY_CODE,
e.getErrorType());
}
try {
String someNumber = "123 456 7890";
phoneUtil.parse(someNumber, RegionCode.ZZ);


BIN
java/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_KR View File


BIN
java/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_SG View File


+ 7
- 7
java/test/com/google/i18n/phonenumbers/geocoding/AreaCodeMapTest.java View File

@ -84,13 +84,13 @@ public class AreaCodeMapTest extends TestCase {
public void testGetSmallerMapStorageChoosesDefaultImpl() {
AreaCodeMapStorageStrategy mapStorage =
new AreaCodeMap().getSmallerMapStorage(createDefaultStorageMapCandidate());
assertFalse(mapStorage.isFlyweight());
assertFalse(mapStorage instanceof FlyweightMapStorage);
}
public void testGetSmallerMapStorageChoosesFlyweightImpl() {
AreaCodeMapStorageStrategy mapStorage =
new AreaCodeMap().getSmallerMapStorage(createFlyweightStorageMapCandidate());
assertTrue(mapStorage.isFlyweight());
assertTrue(mapStorage instanceof FlyweightMapStorage);
}
public void testLookupInvalidNumber_US() {
@ -126,12 +126,12 @@ public class AreaCodeMapTest extends TestCase {
public void testLookupNumberNotFound_TX() {
number.setCountryCode(1).setNationalNumber(9724811234L);
assertEquals("", areaCodeMapForUS.lookup(number));
assertNull(areaCodeMapForUS.lookup(number));
}
public void testLookupNumber_CH() {
number.setCountryCode(41).setNationalNumber(446681300L);
assertEquals("", areaCodeMapForUS.lookup(number));
assertNull(areaCodeMapForUS.lookup(number));
}
public void testLookupNumber_IT() {
@ -146,7 +146,7 @@ public class AreaCodeMapTest extends TestCase {
// A mobile number
number.setNationalNumber(321123456L).setItalianLeadingZero(false);
assertEquals("", areaCodeMapForIT.lookup(number));
assertNull(areaCodeMapForIT.lookup(number));
// An invalid number (too short)
number.setNationalNumber(321123L).setItalianLeadingZero(true);
@ -173,7 +173,7 @@ public class AreaCodeMapTest extends TestCase {
public void testReadWriteExternalWithDefaultStrategy() throws IOException {
AreaCodeMap localAreaCodeMap = new AreaCodeMap();
localAreaCodeMap.readAreaCodeMap(createDefaultStorageMapCandidate());
assertFalse(localAreaCodeMap.getAreaCodeMapStorage().isFlyweight());
assertFalse(localAreaCodeMap.getAreaCodeMapStorage() instanceof FlyweightMapStorage);
AreaCodeMap newAreaCodeMap;
newAreaCodeMap = createNewAreaCodeMap(localAreaCodeMap);
@ -183,7 +183,7 @@ public class AreaCodeMapTest extends TestCase {
public void testReadWriteExternalWithFlyweightStrategy() throws IOException {
AreaCodeMap localAreaCodeMap = new AreaCodeMap();
localAreaCodeMap.readAreaCodeMap(createFlyweightStorageMapCandidate());
assertTrue(localAreaCodeMap.getAreaCodeMapStorage().isFlyweight());
assertTrue(localAreaCodeMap.getAreaCodeMapStorage() instanceof FlyweightMapStorage);
AreaCodeMap newAreaCodeMap;
newAreaCodeMap = createNewAreaCodeMap(localAreaCodeMap);


+ 46
- 19
java/test/com/google/i18n/phonenumbers/geocoding/FlyweightMapStorageTest.java View File

@ -23,6 +23,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Collections;
import java.util.SortedMap;
import java.util.TreeMap;
@ -32,37 +33,48 @@ import java.util.TreeMap;
* @author Philippe Liard
*/
public class FlyweightMapStorageTest extends TestCase {
private final SortedMap<Integer, String> areaCodeMap = new TreeMap<Integer, String>();
public FlyweightMapStorageTest() {
areaCodeMap.put(331402, "Paris");
areaCodeMap.put(331434, "Paris");
areaCodeMap.put(334910, "Marseille");
areaCodeMap.put(334911, "Marseille");
private static final SortedMap<Integer, String> areaCodeMap;
static {
SortedMap<Integer, String> tmpMap = new TreeMap<Integer, String>();
tmpMap.put(331402, "Paris");
tmpMap.put(331434, "Paris");
tmpMap.put(334910, "Marseille");
tmpMap.put(334911, "Marseille");
tmpMap.put(334912, "");
tmpMap.put(334913, "");
areaCodeMap = Collections.unmodifiableSortedMap(tmpMap);
}
public void testReadFromSortedMap() {
FlyweightMapStorage mapStorage = new FlyweightMapStorage();
private FlyweightMapStorage mapStorage;
@Override
protected void setUp() throws Exception {
mapStorage = new FlyweightMapStorage();
mapStorage.readFromSortedMap(areaCodeMap);
}
public void testReadFromSortedMap() {
assertEquals(331402, mapStorage.getPrefix(0));
assertEquals(331434, mapStorage.getPrefix(1));
assertEquals(334910, mapStorage.getPrefix(2));
assertEquals(334911, mapStorage.getPrefix(3));
String desc = mapStorage.getDescription(0);
assertEquals("Paris", desc);
assertTrue(desc == mapStorage.getDescription(1)); // Same identity.
assertEquals("Paris", mapStorage.getDescription(0));
assertSame(mapStorage.getDescription(0), mapStorage.getDescription(1));
desc = mapStorage.getDescription(2);
assertEquals("Marseille", desc);
assertTrue(desc == mapStorage.getDescription(3)); // Same identity.
assertEquals("Marseille", mapStorage.getDescription(2));
assertSame(mapStorage.getDescription(2), mapStorage.getDescription(3));
}
public void testWriteAndReadExternal() throws IOException {
FlyweightMapStorage mapStorage = new FlyweightMapStorage();
mapStorage.readFromSortedMap(areaCodeMap);
public void testReadFromSortedMapSupportsEmptyDescription() {
assertEquals(334912, mapStorage.getPrefix(4));
assertEquals(334913, mapStorage.getPrefix(5));
assertEquals("", mapStorage.getDescription(4));
assertSame(mapStorage.getDescription(4), mapStorage.getDescription(5));
}
public void testWriteAndReadExternal() throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
mapStorage.writeExternal(objectOutputStream);
@ -74,7 +86,22 @@ public class FlyweightMapStorageTest extends TestCase {
newMapStorage.readExternal(objectInputStream);
String expected = mapStorage.toString();
assertFalse(expected.length() == 0);
assertEquals(expected, newMapStorage.toString());
}
public void testReadExternalThrowsIOExceptionWithMalformedData() throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeUTF("hello");
objectOutputStream.flush();
ObjectInputStream objectInputStream =
new ObjectInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
FlyweightMapStorage newMapStorage = new FlyweightMapStorage();
try {
newMapStorage.readExternal(objectInputStream);
fail();
} catch (IOException e) {
// Exception expected.
}
}
}

+ 337
- 247
resources/PhoneNumberMetaData.xml
File diff suppressed because it is too large
View File


+ 13
- 12
resources/PhoneNumberMetaDataForTesting.xml View File

@ -16,8 +16,7 @@
MetaData on Phone Number Plan and formatting rules. This file is used
solely for the purpose of unittesting, so data in this file is not
necessarily consistent with that of
../resources/PhoneNumberMetaData.xml
necessarily consistent with that of PhoneNumberMetaData.xml.
-->
<phoneNumberMetadata>
@ -381,8 +380,8 @@
<format>$1-$2-$3</format>
</numberFormat>
<numberFormat pattern="(\d{2})(\d{3})(\d{4})">
<leadingDigits>1(?:[169][2-8]|[78]|5[1-4])|[68]0|[3-9][1-9][2-9]</leadingDigits>
<leadingDigits>1(?:[169][2-8]|[78]|5(?:[1-3]|4[56]))|[68]0|[3-9][1-9][2-9]</leadingDigits>
<leadingDigits>1(?:[169][2-8]|[78]|5[1-4])|[68]0|[3-6][1-9][2-9]</leadingDigits>
<leadingDigits>1(?:[169][2-8]|[78]|5(?:[1-3]|4[56]))|[68]0|[3-6][1-9][2-9]</leadingDigits>
<format>$1-$2-$3</format>
</numberFormat>
<numberFormat pattern="(\d{3})(\d)(\d{4})">
@ -424,20 +423,20 @@
<format>$1-$2</format>
</numberFormat>
<numberFormat pattern="(\d{2})(\d{3})">
<leadingDigits>[3-9][1-9]1</leadingDigits>
<leadingDigits>[3-9][1-9]1(?:[0-46-9])</leadingDigits>
<leadingDigits>[3-9][1-9]1(?:[0-247-9]|3[124]|6[1269])</leadingDigits>
<leadingDigits>[3-6][1-9]1</leadingDigits>
<leadingDigits>[3-6][1-9]1(?:[0-46-9])</leadingDigits>
<leadingDigits>[3-6][1-9]1(?:[0-247-9]|3[124]|6[1269])</leadingDigits>
<format>$1-$2</format>
</numberFormat>
<numberFormat pattern="(\d{2})(\d{4})">
<leadingDigits>[3-9][1-9]1</leadingDigits>
<leadingDigits>[3-9][1-9]1[36]</leadingDigits>
<leadingDigits>[3-9][1-9]1(?:3[035-9]|6[03-578])</leadingDigits>
<leadingDigits>[3-6][1-9]1</leadingDigits>
<leadingDigits>[3-6][1-9]1[36]</leadingDigits>
<leadingDigits>[3-6][1-9]1(?:3[035-9]|6[03-578])</leadingDigits>
<format>$1-$2</format>
</numberFormat>
</availableFormats>
<generalDesc>
<nationalNumberPattern>[1-79]\d{3,9}|8\d{8}</nationalNumberPattern>
<nationalNumberPattern>[1-7]\d{3,9}|8\d{8}</nationalNumberPattern>
<possibleNumberPattern>\d{4,10}</possibleNumberPattern>
</generalDesc>
<fixedLine>
@ -627,7 +626,9 @@
<!-- Singapore -->
<!-- http://www.ida.gov.sg/policies%20and%20regulation/20060508120124.aspx -->
<territory id="SG" countryCode="65" internationalPrefix="0[0-3][0-9]">
<!-- For testing the AYTF with long NDDs, "777777" is added as a possible national prefix. -->
<territory id="SG" countryCode="65" internationalPrefix="0[0-3][0-9]"
nationalPrefixForParsing="777777">
<availableFormats>
<numberFormat pattern="(\d{4})(\d{4})">
<leadingDigits>[369]|8[1-9]</leadingDigits>


+ 1692
- 1
resources/geocoding/de/49.txt
File diff suppressed because it is too large
View File


+ 1546
- 0
resources/geocoding/en/81.txt
File diff suppressed because it is too large
View File


+ 51
- 0
resources/geocoding/sr/381.txt View File

@ -0,0 +1,51 @@
# Copyright (C) 2011 The Libphonenumber Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Generated from:
# http://www.itu.int/oth/T02020000B9/en [2011-07-04]
38110|Pirot
38111|Beograd
38112|Požarevac
38113|Pančevo
38114|Valjevo
38115|Šabac
38116|Leskovac
38117|Vranje
38118|Niš
38119|Zaječar
38120|Novi Pazar
38121|Novi Sad
38122|Sremska Mitrovica
38123|Zrenjanin
381230|Kikinda
38124|Subotica
38125|Sombor
38126|Smederevo
38127|Prokuplje
38128|Kosovska Mitrovica
381280|Gnjilane
38129|Prizren
381290|Uroševac
38130|Bor
38131|Užice
38132|Čačak
38133|Prijepolje
38134|Kragujevac (TC)
38135|Jagodina
38136|Kraljevo
38137|Kruševac
38138|Priština
38139|Peć
381390|Dakovica

+ 8
- 3
tools/java/common/src/com/google/i18n/phonenumbers/tools/BuildMetadataFromXml.java View File

@ -98,9 +98,14 @@ public class BuildMetadataFromXml {
int numOfTerritories = territory.getLength();
for (int i = 0; i < numOfTerritories; i++) {
Element territoryElement = (Element) territory.item(i);
String regionCode = territoryElement.getAttribute("id");
PhoneMetadata metadata = loadCountryMetadata(regionCode, territoryElement);
metadataCollection.addMetadata(metadata);
String id = territoryElement.getAttribute("id");
try {
PhoneMetadata metadata = loadCountryMetadata(id, territoryElement);
metadataCollection.addMetadata(metadata);
} catch (IllegalArgumentException e) {
LOGGER.log(Level.WARNING, "Found data for region '" + id + "' but no valid region code " +
"can be found to match this. Data will be ignored.");
}
}
return metadataCollection.build();
}


BIN
tools/java/cpp-build/target/cpp-build-1.0-SNAPSHOT-jar-with-dependencies.jar View File


+ 2
- 5
tools/java/java-build/src/com/google/i18n/phonenumbers/tools/GenerateAreaCodeData.java View File

@ -135,9 +135,6 @@ public class GenerateAreaCodeData extends Command {
lineNumber));
}
String prefix = line.substring(0, indexOfPipe);
if (indexOfPipe == line.length() - 1) {
throw new RuntimeException(String.format("line %d: missing location", lineNumber));
}
String location = line.substring(indexOfPipe + 1);
handler.process(Integer.parseInt(prefix), location);
}
@ -277,7 +274,7 @@ public class GenerateAreaCodeData extends Command {
* generated from the provided file name previously used to output the area code/location mappings
* for the given country.
*/
// @VisibleForTesting
// @VisibleForTesting
static void addConfigurationMapping(SortedMap<Integer, Set<String>> availableDataFiles,
File outputAreaCodeMappingsFile) {
String outputAreaCodeMappingsFileName = outputAreaCodeMappingsFile.getName();
@ -296,7 +293,7 @@ public class GenerateAreaCodeData extends Command {
/**
* Outputs the binary configuration file mapping country codes to language strings.
*/
// @VisibleForTesting
// @VisibleForTesting
static void outputBinaryConfiguration(SortedMap<Integer, Set<String>> availableDataFiles,
OutputStream outputStream) throws IOException {
MappingFileProvider mappingFileProvider = new MappingFileProvider();


BIN
tools/java/java-build/target/java-build-1.0-SNAPSHOT-jar-with-dependencies.jar View File


+ 10
- 7
tools/java/java-build/test/com/google/i18n/phonenumbers/tools/GenerateAreaCodeDataTest.java View File

@ -138,13 +138,8 @@ public class GenerateAreaCodeDataTest extends TestCase {
}
}
public void testParseTextFileThrowsExceptionWithMissingLocation() throws IOException {
try {
parseTextFileHelper("331|");
fail();
} catch (RuntimeException e) {
// Expected.
}
public void testParseTextFileAcceptsMissingLocation() throws IOException {
parseTextFileHelper("331|");
}
public void testSplitMap() {
@ -187,6 +182,14 @@ public class GenerateAreaCodeDataTest extends TestCase {
assertEquals(input, dataAfterDeserialization);
}
public void testConvertDataSupportsEmptyDescription() throws IOException {
String input = "331|Paris\n334|Marseilles\n3341|\n";
String dataAfterDeserialization = convertDataHelper(input);
assertEquals(3, dataAfterDeserialization.split("\n").length);
assertEquals(input, dataAfterDeserialization);
}
public void testConvertDataThrowsExceptionWithDuplicatedAreaCodes() throws IOException {
String input = "331|Paris\n331|Marseilles\n";


Loading…
Cancel
Save