Skip to content

Commit 35b831c

Browse files
Rename NonGeographicalRegion to NonGeographicalEntity.
This is to be consistent with the naming of non-geographical entities, since region and non-geographical can be contradictory.
1 parent 55716be commit 35b831c

8 files changed

Lines changed: 88 additions & 39 deletions

File tree

java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ private boolean attemptToExtractCountryCallingCode() {
612612
nationalNumber.append(numberWithoutCountryCallingCode);
613613
String newRegionCode = phoneUtil.getRegionCodeForCountryCode(countryCode);
614614
if (PhoneNumberUtil.REGION_CODE_FOR_NON_GEO_ENTITY.equals(newRegionCode)) {
615-
currentMetadata = phoneUtil.getMetadataForNonGeographicalRegion(countryCode);
615+
currentMetadata = phoneUtil.getMetadataForNonGeographicalEntity(countryCode);
616616
} else if (!newRegionCode.equals(defaultCountry)) {
617617
currentMetadata = getMetadataForRegion(newRegionCode);
618618
}

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ abstract boolean verify(
699699

700700
// The set of country calling codes that map to the non-geo entity region ("001"). This set
701701
// currently contains < 12 elements so the default capacity of 16 (load factor=0.75) is fine.
702-
private final Set<Integer> countryCodesForNonGeographicalRegion = new HashSet<>();
702+
private final Set<Integer> countryCodesForNonGeographicalEntity = new HashSet<>();
703703

704704
/**
705705
* This class implements a singleton, the constructor is only visible to facilitate testing.
@@ -715,7 +715,7 @@ abstract boolean verify(
715715
// that's the only region code it maps to.
716716
if (regionCodes.size() == 1 && REGION_CODE_FOR_NON_GEO_ENTITY.equals(regionCodes.get(0))) {
717717
// This is the subset of all country codes that map to the non-geo entity region code.
718-
countryCodesForNonGeographicalRegion.add(entry.getKey());
718+
countryCodesForNonGeographicalEntity.add(entry.getKey());
719719
} else {
720720
// The supported regions set does not include the "001" non-geo entity region code.
721721
supportedRegions.addAll(regionCodes);
@@ -1072,7 +1072,7 @@ public Set<String> getSupportedRegions() {
10721072
* library supports
10731073
*/
10741074
public Set<Integer> getSupportedGlobalNetworkCallingCodes() {
1075-
return Collections.unmodifiableSet(countryCodesForNonGeographicalRegion);
1075+
return Collections.unmodifiableSet(countryCodesForNonGeographicalEntity);
10761076
}
10771077

10781078
/**
@@ -1159,7 +1159,7 @@ public Set<PhoneNumberType> getSupportedTypesForRegion(String regionCode) {
11591159
* entity.
11601160
*/
11611161
public Set<PhoneNumberType> getSupportedTypesForNonGeoEntity(int countryCallingCode) {
1162-
PhoneMetadata metadata = getMetadataForNonGeographicalRegion(countryCallingCode);
1162+
PhoneMetadata metadata = getMetadataForNonGeographicalEntity(countryCallingCode);
11631163
if (metadata == null) {
11641164
logger.log(Level.WARNING, "Unknown country calling code for a non-geographical entity "
11651165
+ "provided: " + countryCallingCode);
@@ -1436,7 +1436,7 @@ public String formatNationalNumberWithCarrierCode(PhoneNumber number, CharSequen
14361436
private PhoneMetadata getMetadataForRegionOrCallingCode(
14371437
int countryCallingCode, String regionCode) {
14381438
return REGION_CODE_FOR_NON_GEO_ENTITY.equals(regionCode)
1439-
? getMetadataForNonGeographicalRegion(countryCallingCode)
1439+
? getMetadataForNonGeographicalEntity(countryCallingCode)
14401440
: getMetadataForRegion(regionCode);
14411441
}
14421442

@@ -2149,7 +2149,7 @@ public PhoneNumber getExampleNumberForType(PhoneNumberType type) {
21492149
// If there wasn't an example number for a region, try the non-geographical entities.
21502150
for (int countryCallingCode : getSupportedGlobalNetworkCallingCodes()) {
21512151
PhoneNumberDesc desc = getNumberDescByType(
2152-
getMetadataForNonGeographicalRegion(countryCallingCode), type);
2152+
getMetadataForNonGeographicalEntity(countryCallingCode), type);
21532153
try {
21542154
if (desc.hasExampleNumber()) {
21552155
return parse("+" + countryCallingCode + desc.getExampleNumber(), UNKNOWN_REGION);
@@ -2171,7 +2171,7 @@ public PhoneNumber getExampleNumberForType(PhoneNumberType type) {
21712171
* to a non-geographical entity.
21722172
*/
21732173
public PhoneNumber getExampleNumberForNonGeoEntity(int countryCallingCode) {
2174-
PhoneMetadata metadata = getMetadataForNonGeographicalRegion(countryCallingCode);
2174+
PhoneMetadata metadata = getMetadataForNonGeographicalEntity(countryCallingCode);
21752175
if (metadata != null) {
21762176
// For geographical entities, fixed-line data is always present. However, for non-geographical
21772177
// entities, this is not the case, so we have to go through different types to find the
@@ -2322,18 +2322,26 @@ PhoneMetadata getMetadataForRegion(String regionCode) {
23222322
return phoneMetadata;
23232323
}
23242324

2325+
/**
2326+
* @deprecated use the following name {@link #getMetadataForNonGeographicalEntity}
2327+
*/
2328+
@Deprecated
2329+
PhoneMetadata getMetadataForNonGeographicalRegion(int countryCallingCode) {
2330+
return getMetadataForNonGeographicalEntity(countryCallingCode);
2331+
}
2332+
23252333
/**
23262334
* Returns the metadata for the given country calling code or {@code null} if the country calling
23272335
* code is invalid or unknown.
23282336
*
23292337
* @throws MissingMetadataException if the country calling code is valid, but metadata cannot be
23302338
* found.
23312339
*/
2332-
PhoneMetadata getMetadataForNonGeographicalRegion(int countryCallingCode) {
2333-
if (!countryCodesForNonGeographicalRegion.contains(countryCallingCode)) {
2340+
PhoneMetadata getMetadataForNonGeographicalEntity(int countryCallingCode) {
2341+
if (!countryCodesForNonGeographicalEntity.contains(countryCallingCode)) {
23342342
return null;
23352343
}
2336-
PhoneMetadata phoneMetadata = metadataSource.getMetadataForNonGeographicalRegion(
2344+
PhoneMetadata phoneMetadata = metadataSource.getMetadataForNonGeographicalEntity(
23372345
countryCallingCode);
23382346
ensureMetadataIsNonNull(phoneMetadata,
23392347
"Missing metadata for country code " + countryCallingCode);

java/libphonenumber/src/com/google/i18n/phonenumbers/metadata/source/FormattingMetadataSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public interface FormattingMetadataSource {
2525
* Returns formatting phone metadata for provided country calling code.
2626
*
2727
* <p>This method is similar to the one in {@link
28-
* NonGeographicalEntityMetadataSource#getMetadataForNonGeographicalRegion(int)}, except that it
28+
* NonGeographicalEntityMetadataSourceV2#getMetadataForNonGeographicalEntity(int)}, except that it
2929
* will not fail for geographical regions, it can be used for both geo- and non-geo entities.
3030
*
3131
* <p>In case the provided {@code countryCallingCode} maps to several different regions, only one

java/libphonenumber/src/com/google/i18n/phonenumbers/metadata/source/MetadataSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
package com.google.i18n.phonenumbers.metadata.source;
1818

1919
/** A source of phone metadata split by different regions. */
20-
public interface MetadataSource extends RegionMetadataSource, NonGeographicalEntityMetadataSource {
20+
public interface MetadataSource extends RegionMetadataSource, NonGeographicalEntityMetadataSource, NonGeographicalEntityMetadataSourceV2 {
2121
}

java/libphonenumber/src/com/google/i18n/phonenumbers/metadata/source/MetadataSourceImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,17 @@ public MetadataSourceImpl(
4949
metadataLoader, metadataParser, new CompositeMetadataContainer()));
5050
}
5151

52+
/**
53+
* @deprecated Use {@link #getMetadataForNonGeographicalEntity(int)}
54+
*/
55+
@Deprecated
5256
@Override
5357
public PhoneMetadata getMetadataForNonGeographicalRegion(int countryCallingCode) {
58+
return getMetadataForNonGeographicalEntity(countryCallingCode);
59+
}
60+
61+
@Override
62+
public PhoneMetadata getMetadataForNonGeographicalEntity(int countryCallingCode) {
5463
if (GeoEntityUtility.isGeoEntity(countryCallingCode)) {
5564
throw new IllegalArgumentException(
5665
countryCallingCode + " calling code belongs to a geo entity");

java/libphonenumber/src/com/google/i18n/phonenumbers/metadata/source/NonGeographicalEntityMetadataSource.java

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,14 @@
1919
import com.google.i18n.phonenumbers.Phonemetadata.PhoneMetadata;
2020

2121
/**
22-
* A source of phone metadata for non-geographical entities.
23-
*
24-
* <p>Non-geographical entities are phone number ranges that have a country calling code, but either
25-
* do not belong to an actual country (some international services), or belong to a region which has
26-
* a different country calling code from the country it is part of. Examples of such ranges are
27-
* those starting with:
28-
*
29-
* <ul>
30-
* <li>800 - country code assigned to the Universal International Freephone Service
31-
* <li>808 - country code assigned to the International Shared Cost Service
32-
* <li>870 - country code assigned to the Pitcairn Islands
33-
* <li>...
34-
* </ul>
22+
* @deprecated Use {@link NonGeographicalEntityMetadataSourceV2}
3523
*/
24+
@Deprecated
3625
public interface NonGeographicalEntityMetadataSource {
3726

3827
/**
39-
* Gets phone metadata for a non-geographical entity.
40-
*
41-
* @param countryCallingCode the country calling code.
42-
* @return the phone metadata for that entity, or null if there is none.
43-
* @throws IllegalArgumentException if provided {@code countryCallingCode} does not belong to a
44-
* non-geographical entity
28+
* @deprecated use {@link NonGeographicalEntityMetadataSourceV2#getMetadataForNonGeographicalEntity(int)}
4529
*/
30+
@Deprecated
4631
PhoneMetadata getMetadataForNonGeographicalRegion(int countryCallingCode);
47-
}
32+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (C) 2022 The Libphonenumber Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.i18n.phonenumbers.metadata.source;
18+
19+
import com.google.i18n.phonenumbers.Phonemetadata.PhoneMetadata;
20+
21+
/**
22+
* A source of phone metadata for non-geographical entities.
23+
*
24+
* <p>Non-geographical entities are phone number ranges that have a country calling code, but either
25+
* do not belong to an actual country (some international services), or belong to a region which has
26+
* a different country calling code from the country it is part of. Examples of such ranges are
27+
* those starting with:
28+
*
29+
* <ul>
30+
* <li>800 - country code assigned to the Universal International Freephone Service
31+
* <li>808 - country code assigned to the International Shared Cost Service
32+
* <li>870 - country code assigned to the Pitcairn Islands
33+
* <li>...
34+
* </ul>
35+
*/
36+
public interface NonGeographicalEntityMetadataSourceV2 {
37+
38+
/**
39+
* Gets phone metadata for a non-geographical entity.
40+
*
41+
* @param countryCallingCode the country calling code.
42+
* @return the phone metadata for that entity, or null if there is none.
43+
* @throws IllegalArgumentException if provided {@code countryCallingCode} does not belong to a
44+
* non-geographical entity
45+
*/
46+
PhoneMetadata getMetadataForNonGeographicalEntity(int countryCallingCode);
47+
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public void testGetSupportedCallingCodes() {
161161

162162
public void testGetInstanceLoadBadMetadata() {
163163
assertNull(phoneUtil.getMetadataForRegion("No Such Region"));
164-
assertNull(phoneUtil.getMetadataForNonGeographicalRegion(-1));
164+
assertNull(phoneUtil.getMetadataForNonGeographicalEntity(-1));
165165
}
166166

167167
public void testGetSupportedTypesForRegion() {
@@ -262,7 +262,7 @@ public void testGetInstanceLoadARMetadata() {
262262
}
263263

264264
public void testGetInstanceLoadInternationalTollFreeMetadata() {
265-
PhoneMetadata metadata = phoneUtil.getMetadataForNonGeographicalRegion(800);
265+
PhoneMetadata metadata = phoneUtil.getMetadataForNonGeographicalEntity(800);
266266
assertEquals("001", metadata.getId());
267267
assertEquals(800, metadata.getCountryCode());
268268
assertEquals("$1 $2", metadata.getNumberFormat(0).getFormat());
@@ -3247,8 +3247,8 @@ public void testGetMetadataForRegionForUnknownRegion_shouldBeNull() {
32473247
assertNull(phoneUtil.getMetadataForRegion(RegionCode.ZZ));
32483248
}
32493249

3250-
public void testGetMetadataForNonGeographicalRegionForGeoRegion_shouldBeNull() {
3251-
assertNull(phoneUtil.getMetadataForNonGeographicalRegion(/* countryCallingCode = */ 1));
3250+
public void testGetMetadataForNonGeographicalEntityForGeoRegion_shouldBeNull() {
3251+
assertNull(phoneUtil.getMetadataForNonGeographicalEntity(/* countryCallingCode = */ 1));
32523252
}
32533253

32543254
public void testGetMetadataForRegionForMissingMetadata() {
@@ -3262,13 +3262,13 @@ public void run() {
32623262
});
32633263
}
32643264

3265-
public void testGetMetadataForNonGeographicalRegionForMissingMetadata() {
3265+
public void testGetMetadataForNonGeographicalEntityForMissingMetadata() {
32663266
assertThrows(
32673267
MissingMetadataException.class,
32683268
new ThrowingRunnable() {
32693269
@Override
32703270
public void run() {
3271-
phoneNumberUtilWithMissingMetadata.getMetadataForNonGeographicalRegion(800);
3271+
phoneNumberUtilWithMissingMetadata.getMetadataForNonGeographicalEntity(800);
32723272
}
32733273
});
32743274
}

0 commit comments

Comments
 (0)