Browse Source

- Fix formatNumberForMobileDialing that is modifying its input PhoneNumber.

- Fix incorect use of string equality.
- Fix testGetEnglishDataPath that is failing under windows.
- Remove unused method and variables.
pull/567/head
Nikolaos Trogkanis 14 years ago
committed by Mihaela Rosca
parent
commit
d46ff896ce
5 changed files with 18 additions and 31 deletions
  1. +12
    -12
      java/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java
  2. +2
    -2
      java/src/com/google/i18n/phonenumbers/ShortNumberUtil.java
  3. +0
    -9
      java/test/com/google/i18n/phonenumbers/PhoneNumberMatcherTest.java
  4. +3
    -6
      tools/java/java-build/src/com/google/i18n/phonenumbers/geocoding/GenerateAreaCodeData.java
  5. +1
    -2
      tools/java/java-build/test/com/google/i18n/phonenumbers/geocoding/GenerateAreaCodeDataTest.java

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

@ -1179,27 +1179,27 @@ public class PhoneNumberUtil {
String formattedNumber; String formattedNumber;
// Clear the extension, as that part cannot normally be dialed together with the main number. // Clear the extension, as that part cannot normally be dialed together with the main number.
number.clearExtension();
PhoneNumberType numberType = getNumberType(number);
if ((regionCode == "CO") && (regionCallingFrom == "CO") &&
PhoneNumber numberNoExt = new PhoneNumber().mergeFrom(number).clearExtension();
PhoneNumberType numberType = getNumberType(numberNoExt);
if ((regionCode.equals("CO")) && (regionCallingFrom.equals("CO")) &&
(numberType == PhoneNumberType.FIXED_LINE)) { (numberType == PhoneNumberType.FIXED_LINE)) {
formattedNumber = formattedNumber =
formatNationalNumberWithCarrierCode(number, COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX);
} else if ((regionCode == "BR") && (regionCallingFrom == "BR") &&
formatNationalNumberWithCarrierCode(numberNoExt, COLOMBIA_MOBILE_TO_FIXED_LINE_PREFIX);
} else if ((regionCode.equals("BR")) && (regionCallingFrom.equals("BR")) &&
((numberType == PhoneNumberType.FIXED_LINE) || (numberType == PhoneNumberType.MOBILE) || ((numberType == PhoneNumberType.FIXED_LINE) || (numberType == PhoneNumberType.MOBILE) ||
(numberType == PhoneNumberType.FIXED_LINE_OR_MOBILE))) { (numberType == PhoneNumberType.FIXED_LINE_OR_MOBILE))) {
formattedNumber = number.hasPreferredDomesticCarrierCode()
? formatNationalNumberWithPreferredCarrierCode(number, "")
formattedNumber = numberNoExt.hasPreferredDomesticCarrierCode()
? formatNationalNumberWithPreferredCarrierCode(numberNoExt, "")
// Brazilian fixed line and mobile numbers need to be dialed with a carrier code when // Brazilian fixed line and mobile numbers need to be dialed with a carrier code when
// called within Brazil. Without that, most of the carriers won't connect the call. // called within Brazil. Without that, most of the carriers won't connect the call.
// Because of that, we return an empty string here. // Because of that, we return an empty string here.
: ""; : "";
} else if (canBeInternationallyDialled(number)) {
return withFormatting ? format(number, PhoneNumberFormat.INTERNATIONAL)
: format(number, PhoneNumberFormat.E164);
} else if (canBeInternationallyDialled(numberNoExt)) {
return withFormatting ? format(numberNoExt, PhoneNumberFormat.INTERNATIONAL)
: format(numberNoExt, PhoneNumberFormat.E164);
} else { } else {
formattedNumber = (regionCallingFrom == regionCode)
? format(number, PhoneNumberFormat.NATIONAL) : "";
formattedNumber = (regionCallingFrom.equals(regionCode))
? format(numberNoExt, PhoneNumberFormat.NATIONAL) : "";
} }
return withFormatting ? formattedNumber : normalizeDigitsOnly(formattedNumber); return withFormatting ? formattedNumber : normalizeDigitsOnly(formattedNumber);
} }


+ 2
- 2
java/src/com/google/i18n/phonenumbers/ShortNumberUtil.java View File

@ -28,7 +28,7 @@ import java.util.regex.Pattern;
*/ */
public class ShortNumberUtil { public class ShortNumberUtil {
private static PhoneNumberUtil phoneUtil;
private final PhoneNumberUtil phoneUtil;
public ShortNumberUtil() { public ShortNumberUtil() {
phoneUtil = PhoneNumberUtil.getInstance(); phoneUtil = PhoneNumberUtil.getInstance();
@ -62,7 +62,7 @@ public class ShortNumberUtil {
PhoneNumberDesc emergencyNumberDesc = phoneUtil.getMetadataForRegion(regionCode).getEmergency(); PhoneNumberDesc emergencyNumberDesc = phoneUtil.getMetadataForRegion(regionCode).getEmergency();
Pattern emergencyNumberPattern = Pattern emergencyNumberPattern =
Pattern.compile(emergencyNumberDesc.getNationalNumberPattern()); Pattern.compile(emergencyNumberDesc.getNationalNumberPattern());
if (regionCode == "BR") {
if (regionCode.equals("BR")) {
// This is to prevent Brazilian local numbers which start with 911 being incorrectly // This is to prevent Brazilian local numbers which start with 911 being incorrectly
// classified as emergency numbers. In Brazil, it is impossible to append additional digits to // classified as emergency numbers. In Brazil, it is impossible to append additional digits to
// an emergency number to dial the number. // an emergency number to dial the number.


+ 0
- 9
java/test/com/google/i18n/phonenumbers/PhoneNumberMatcherTest.java View File

@ -433,8 +433,6 @@ public class PhoneNumberMatcherTest extends TestCase {
}; };
public void testMatchesWithStrictGroupingLeniency() throws Exception { public void testMatchesWithStrictGroupingLeniency() throws Exception {
int noMatchFoundCount = 0;
int wrongMatchFoundCount = 0;
List<NumberTest> testCases = new ArrayList<NumberTest>(); List<NumberTest> testCases = new ArrayList<NumberTest>();
testCases.addAll(Arrays.asList(STRICT_GROUPING_CASES)); testCases.addAll(Arrays.asList(STRICT_GROUPING_CASES));
testCases.addAll(Arrays.asList(EXACT_GROUPING_CASES)); testCases.addAll(Arrays.asList(EXACT_GROUPING_CASES));
@ -895,13 +893,6 @@ public class PhoneNumberMatcherTest extends TestCase {
return phoneUtil.findNumbers(text, defaultCountry, leniency, Long.MAX_VALUE).iterator(); return phoneUtil.findNumbers(text, defaultCountry, leniency, Long.MAX_VALUE).iterator();
} }
/**
* Returns true if there were no matches found.
*/
private boolean hasNoMatches(Iterator<PhoneNumberMatch> iterator) {
return !iterator.hasNext();
}
private boolean hasNoMatches(Iterable<PhoneNumberMatch> iterable) { private boolean hasNoMatches(Iterable<PhoneNumberMatch> iterable) {
return !iterable.iterator().hasNext(); return !iterable.iterator().hasNext();
} }


+ 3
- 6
tools/java/java-build/src/com/google/i18n/phonenumbers/geocoding/GenerateAreaCodeData.java View File

@ -336,14 +336,12 @@ public class GenerateAreaCodeData {
for (Map.Entry<Integer, String> mapping : mappings.entrySet()) { for (Map.Entry<Integer, String> mapping : mappings.entrySet()) {
String prefix = String.valueOf(mapping.getKey()); String prefix = String.valueOf(mapping.getKey());
File targetFile = null; File targetFile = null;
int correspondingAreaCode = -1;
for (File outputBinaryFile : outputBinaryFiles) { for (File outputBinaryFile : outputBinaryFiles) {
String outputBinaryFilePrefix = String outputBinaryFilePrefix =
getPhonePrefixLanguagePairFromFilename(outputBinaryFile.getName()).prefix; getPhonePrefixLanguagePairFromFilename(outputBinaryFile.getName()).prefix;
if (prefix.startsWith(outputBinaryFilePrefix)) { if (prefix.startsWith(outputBinaryFilePrefix)) {
targetFile = outputBinaryFile; targetFile = outputBinaryFile;
correspondingAreaCode = Integer.parseInt(outputBinaryFilePrefix);
break; break;
} }
} }
@ -361,9 +359,8 @@ public class GenerateAreaCodeData {
* Gets the English data text file path corresponding to the provided one. * Gets the English data text file path corresponding to the provided one.
*/ */
// @VisibleForTesting // @VisibleForTesting
static String getEnglishDataPath(File inputTextFile) {
return LANGUAGE_IN_FILE_PATH_PATTERN.matcher(inputTextFile.getAbsolutePath()).replaceFirst(
"$1en$2");
static String getEnglishDataPath(String inputTextFileName) {
return LANGUAGE_IN_FILE_PATH_PATTERN.matcher(inputTextFileName).replaceFirst("$1en$2");
} }
/** /**
@ -416,7 +413,7 @@ public class GenerateAreaCodeData {
*/ */
private void makeDataFallbackToEnglish(File inputTextFile, SortedMap<Integer, String> mappings) private void makeDataFallbackToEnglish(File inputTextFile, SortedMap<Integer, String> mappings)
throws IOException { throws IOException {
File englishTextFile = new File(getEnglishDataPath(inputTextFile));
File englishTextFile = new File(getEnglishDataPath(inputTextFile.getAbsolutePath()));
if (inputTextFile.getAbsolutePath().equals(englishTextFile.getAbsolutePath()) || if (inputTextFile.getAbsolutePath().equals(englishTextFile.getAbsolutePath()) ||
!englishTextFile.exists()) { !englishTextFile.exists()) {
return; return;


+ 1
- 2
tools/java/java-build/test/com/google/i18n/phonenumbers/geocoding/GenerateAreaCodeDataTest.java View File

@ -200,8 +200,7 @@ public class GenerateAreaCodeDataTest extends TestCase {
} }
public void testGetEnglishDataPath() { public void testGetEnglishDataPath() {
assertEquals("/path/en/33.txt",
GenerateAreaCodeData.getEnglishDataPath(new File("/path/fr/33.txt")));
assertEquals("/path/en/33.txt", GenerateAreaCodeData.getEnglishDataPath("/path/fr/33.txt"));
} }
public void testHasOverlap() { public void testHasOverlap() {


Loading…
Cancel
Save