1818
1919import javax .annotation .Nonnull ;
2020import javax .annotation .Nullable ;
21- import java .util .ArrayList ;
22- import java .util .HashMap ;
23- import java .util .List ;
24- import java .util .Map ;
21+ import java .util .*;
2522
2623import static com .mapcode .CheckArgs .checkNonnull ;
2724import static com .mapcode .CheckArgs .checkRange ;
@@ -42,7 +39,7 @@ public enum Territory {
4239 BRA (409 , "Brazil" , null , new String []{"BR" }),
4340 RUS (496 , "Russia" , null , new String []{"RU" }),
4441 CHN (528 , "China" , null , new String []{"CN" }),
45- ATA (540 , "Antarctica" ),
42+ ATA (531 , "Antarctica" ),
4643
4744 VAT (0 , "Vatican City" , null , null , new String []{"Holy See)" }),
4845 MCO (1 , "Monaco" ),
@@ -52,10 +49,10 @@ public enum Territory {
5249 BLM (5 , "Saint-Barthelemy" ),
5350 NRU (6 , "Nauru" ),
5451 TUV (7 , "Tuvalu" ),
55- MAC (8 , "Macau" , null , new String []{"CN-92" , "CHN-92" , "CN-MC" , "CHN-MC" }),
52+ MAC (8 , "Macau" , null , new String []{"CN-92" , "CHN-92" , "CN-MC" , "CHN-MC" }, new String []{ "Aomen" } ),
5653 SXM (9 , "Sint Maarten" ),
5754 MAF (10 , "Saint-Martin" ),
58- NFK (11 , "Norfolk and Philip Island" , null , new String []{"AU-NI" , "AUS-NI" , "AU- NF" , "AUS-NF" },
55+ NFK (11 , "Norfolk and Philip Island" , null , new String []{"AU-NF" , "AUS-NF" },
5956 new String []{"Philip Island" }),
6057 PCN (12 , "Pitcairn Islands" ),
6158 BVT (13 , "Bouvet Island" ),
@@ -86,7 +83,7 @@ public enum Territory {
8683 GRD (37 , "Grenada" ),
8784 VIR (38 , "US Virgin Islands" , null , new String []{"US-VI" , "USA-VI" }, new String []{"Virgin Islands, US" }),
8885 MYT (39 , "Mayotte" ),
89- SJM (40 , "Svalbard and Jan Mayen" , null , null , new String []{"Jan Mayen" }),
86+ SJM (40 , "Svalbard and Jan Mayen" , null , null , new String []{"Jan Mayen" , "Spitsbergen" }),
9087 VCT (41 , "Saint Vincent and the Grenadines" , null , null , new String []{"Grenadines" }),
9188 HMD (42 , "Heard Island and McDonald Islands" , null , new String []{"AU-HM" , "AUS-HM" },
9289 new String []{"McDonald Islands" }),
@@ -108,7 +105,7 @@ public enum Territory {
108105 KIR (58 , "Kiribati" ),
109106 TCA (59 , "Turks and Caicos Islands" , null , null , new String []{"Caicos Islands" }),
110107 STP (60 , "Sao Tome and Principe" , null , null , new String []{"Principe" }),
111- HKG (61 , "Hong Kong" , null , new String []{"CN-91" , "CHN-91" , "CN-HK" , "CHN-HK" }),
108+ HKG (61 , "Hong Kong" , null , new String []{"CN-91" , "CHN-91" , "CN-HK" , "CHN-HK" }, new String []{ "Xianggang" } ),
112109 MTQ (62 , "Martinique" ),
113110 FRO (63 , "Faroe Islands" ),
114111 GLP (64 , "Guadeloupe" ),
@@ -264,7 +261,7 @@ public enum Territory {
264261 NAM (213 , "Namibia" ),
265262 VEN (214 , "Venezuela" ),
266263 NGA (215 , "Nigeria" ),
267- TZA (216 , "Tanzania" , null , new String []{ "EAZ" } ),
264+ TZA (216 , "Tanzania" ),
268265 EGY (217 , "Egypt" ),
269266 MRT (218 , "Mauritania" ),
270267 BOL (219 , "Bolivia" ),
@@ -330,7 +327,7 @@ public enum Territory {
330327 IN_MN (279 , "Manipur" , ParentTerritory .IND ),
331328 IN_TR (280 , "Tripura" , ParentTerritory .IND ),
332329 IN_MZ (281 , "Mizoram" , ParentTerritory .IND ),
333- IN_SK (282 , "Sikkim" , ParentTerritory .IND , new String []{ "IN-SKM" } ),
330+ IN_SK (282 , "Sikkim" , ParentTerritory .IND ),
334331 IN_PB (283 , "Punjab" , ParentTerritory .IND ),
335332 IN_HR (284 , "Haryana" , ParentTerritory .IND ),
336333 IN_AR (285 , "Arunachal Pradesh" , ParentTerritory .IND ),
@@ -339,7 +336,7 @@ public enum Territory {
339336 IN_UT (288 , "Uttarakhand" , ParentTerritory .IND , new String []{"IN-UK" }),
340337 IN_GA (289 , "Goa" , ParentTerritory .IND ),
341338 IN_KL (290 , "Kerala" , ParentTerritory .IND ),
342- IN_TN (291 , "Tamil Nuda " , ParentTerritory .IND ),
339+ IN_TN (291 , "Tamil Nadu " , ParentTerritory .IND ),
343340 IN_HP (292 , "Himachal Pradesh" , ParentTerritory .IND ),
344341 IN_JK (293 , "Jammu and Kashmir" , ParentTerritory .IND ),
345342 IN_CT (294 , "Chhattisgarh" , ParentTerritory .IND , new String []{"IN-CG" }),
@@ -357,13 +354,13 @@ public enum Territory {
357354 IN_PY (306 , "Puducherry" , ParentTerritory .IND ),
358355 AU_NSW (307 , "New South Wales" , ParentTerritory .AUS ),
359356 AU_ACT (308 , "Australian Capital Territory" , ParentTerritory .AUS ),
360- AU_JBT (309 , "Jervis Bay Territory" , ParentTerritory .AUS , new String []{ "AU-JB" } ),
357+ AU_JBT (309 , "Jervis Bay Territory" , ParentTerritory .AUS ),
361358 AU_NT (310 , "Northern Territory" , ParentTerritory .AUS ),
362359 AU_SA (311 , "South Australia" , ParentTerritory .AUS ),
363- AU_TAS (312 , "Tasmania" , ParentTerritory .AUS , new String []{ "AU-TS" } ),
360+ AU_TAS (312 , "Tasmania" , ParentTerritory .AUS ),
364361 AU_VIC (313 , "Victoria" , ParentTerritory .AUS ),
365362 AU_WA (314 , "Western Australia" , ParentTerritory .AUS ),
366- AU_QLD (315 , "Queensland" , ParentTerritory .AUS , new String []{ "AU-QL" } ),
363+ AU_QLD (315 , "Queensland" , ParentTerritory .AUS ),
367364 BR_DF (316 , "Distrito Federal" , ParentTerritory .BRA ),
368365 BR_SE (317 , "Sergipe" , ParentTerritory .BRA ),
369366 BR_AL (318 , "Alagoas" , ParentTerritory .BRA ),
@@ -571,16 +568,7 @@ public enum Territory {
571568 CN_XJ (527 , "Xinjiang Uyghur" , ParentTerritory .CHN , new String []{"CN-65" }),
572569 UMI (529 , "United States Minor Outlying Islands" , null , new String []{"US-UM" , "USA-UM" , "JTN" }),
573570 CPT (530 , "Clipperton Island" ),
574- AT0 (531 , "Macquarie Island" , ParentTerritory .ATA ),
575- AT1 (532 , "Ross Dependency" , ParentTerritory .ATA ),
576- AT2 (533 , "Adelie Land" , ParentTerritory .ATA ),
577- AT3 (534 , "Australian Antarctic Territory" , ParentTerritory .ATA ),
578- AT4 (535 , "Queen Maud Land" , ParentTerritory .ATA ),
579- AT5 (536 , "British Antarctic Territory" , ParentTerritory .ATA ),
580- AT6 (537 , "Chile Antartica" , ParentTerritory .ATA ),
581- AT7 (538 , "Argentine Antarctica" , ParentTerritory .ATA ),
582- AT8 (539 , "Peter 1 Island" , ParentTerritory .ATA ),
583- AAA (541 , "International" , null , null , new String []{"Worldwide" , "Earth" });
571+ AAA (532 , "International" , null , null , new String []{"Worldwide" , "Earth" });
584572
585573 private final int territoryCode ;
586574 @ Nonnull
@@ -802,15 +790,22 @@ private Territory(
802790 * Static initialization of the static data structures.
803791 */
804792 static {
793+ final String errorPrefix = "Initializing error: " ;
805794 codeList = new ArrayList <>();
806795 nameMap = new HashMap <>();
807796 parentList = new ArrayList <>();
808797 final ArrayList <Integer > territoryCodeList = new ArrayList <>();
798+ final Set <String > aliasesSet = new HashSet <>();
809799
810800 for (final Territory territory : Territory .values ()) {
811801 final int territoryCode = territory .getTerritoryCode ();
812- assert (0 <= territoryCode ) && (territoryCode < Territory .values ().length ) : territoryCode ;
813- assert !territoryCodeList .contains (territoryCode ) : territoryCode ;
802+ if ((territoryCode < 0 ) || (territoryCode >= Territory .values ().length )) {
803+ throw new ExceptionInInitializerError (errorPrefix + "territory code out of range: " + territoryCode );
804+
805+ }
806+ if (territoryCodeList .contains (territoryCode )) {
807+ throw new ExceptionInInitializerError (errorPrefix + "non-unique territory code: " + territoryCode );
808+ }
814809 territoryCodeList .add (territory .getTerritoryCode ());
815810
816811 final int initialCodeListSize = codeList .size ();
@@ -823,6 +818,10 @@ private Territory(
823818 }
824819 addNameWithParentVariants (territory .toString (), territory );
825820 for (final String alias : territory .aliases ) {
821+ if (aliasesSet .contains (alias )) {
822+ throw new ExceptionInInitializerError (errorPrefix + "non-unique alias: " + alias );
823+ }
824+ aliasesSet .add (alias );
826825 addNameWithParentVariants (alias , territory );
827826 }
828827 }
@@ -932,7 +931,7 @@ private static void addName(@Nonnull final String name, @Nonnull final Territory
932931 for (int i = 0 ; i < territories .size (); i ++) {
933932
934933 final Territory existingTerritoryParent = territories .get (i ).getParentTerritory ();
935- if (existingTerritoryParent == null && territories .get (i ).toString ().contentEquals (name )) {
934+ if (( existingTerritoryParent == null ) && territories .get (i ).toString ().contentEquals (name )) {
936935 // A primary identifier always takes priority.
937936 return ;
938937 }
0 commit comments