@@ -43,8 +43,8 @@ public class CountryBordersReader {
43
43
44
44
private final HashMap <String , CountryInfo > ids = new HashMap <>();
45
45
private final HashMap <String , ArrayList <String >> openBorders = new HashMap <>();
46
- private final HashMap <String , Integer > isoCodes = new HashMap <>();
47
-
46
+ private final Map <String , Short > isoCodes = new HashMap <>();
47
+ private Map < Short , String > names = new HashMap <>();
48
48
private final HashMap <Long , CountryBordersHierarchy > hierarchies = new HashMap <>();
49
49
50
50
// Package scoped for testing purposes
@@ -108,8 +108,8 @@ public void addHierarchy(Long id, CountryBordersHierarchy hierarchy) {
108
108
public void addId (String id , String localName , String englishName , String cca2 , String cca3 ) {
109
109
if (!ids .containsKey (localName )) {
110
110
ids .put (localName , new CountryInfo (id , localName , englishName ));
111
- isoCodes .put (cca2 .trim ().toUpperCase (), Integer . parseInt (id ));
112
- isoCodes .put (cca3 .trim ().toUpperCase (), Integer . parseInt (id ));
111
+ isoCodes .put (cca2 .trim ().toUpperCase (), Short . parseShort (id ));
112
+ isoCodes .put (cca3 .trim ().toUpperCase (), Short . parseShort (id ));
113
113
}
114
114
}
115
115
@@ -346,6 +346,10 @@ public String getEngName(String name) {
346
346
return "" ;
347
347
}
348
348
349
+ public String getName (short id ) {
350
+ return names .get (id );
351
+ }
352
+
349
353
/**
350
354
* Get whether a border between two specified countries is open or closed
351
355
*
@@ -370,8 +374,8 @@ public boolean isOpen(String c1, String c2) {
370
374
* @param code The code to look up
371
375
* @return The ID of the country or 0 if not found
372
376
*/
373
- public static int getCountryIdByISOCode (String code ) {
374
- return currentInstance != null ? currentInstance .isoCodes .getOrDefault (code .toUpperCase (), 0 ) : 0 ;
377
+ public static short getCountryIdByISOCode (String code ) {
378
+ return currentInstance != null ? currentInstance .isoCodes .getOrDefault (code .toUpperCase (), ( short ) 0 ) : 0 ;
375
379
}
376
380
377
381
/**
@@ -388,23 +392,24 @@ private void readIds() {
388
392
int isoCCA2 = 0 ;
389
393
int isoCCA3 = 0 ;
390
394
for (List <String > col : data ) {
391
- if (col .size () >= 3 ) {
392
- ids .put (col .get (1 ), new CountryInfo (col .get (0 ), col .get (1 ), col .get (2 )));
393
- countries ++;
394
- }
395
- int intID = 0 ;
395
+ short shortID = 0 ;
396
396
try {
397
- intID = Integer . parseInt (col .get (0 ));
397
+ shortID = Short . parseShort (col .get (0 ));
398
398
} catch (NumberFormatException e ) {
399
399
LOGGER .error ("Invalid country ID " + col .get (0 ));
400
400
continue ;
401
401
}
402
+ if (col .size () >= 3 ) {
403
+ ids .put (col .get (1 ), new CountryInfo (col .get (0 ), col .get (1 ), col .get (2 )));
404
+ names .put (shortID , col .get (2 ));
405
+ countries ++;
406
+ }
402
407
if (col .size () >= 4 && !col .get (3 ).trim ().isEmpty ()) {
403
- isoCodes .put (col .get (3 ).trim ().toUpperCase (), intID );
408
+ isoCodes .put (col .get (3 ).trim ().toUpperCase (), shortID );
404
409
isoCCA2 ++;
405
410
}
406
411
if (col .size () == 5 && !col .get (4 ).trim ().isEmpty ()) {
407
- isoCodes .put (col .get (4 ).trim ().toUpperCase (), intID );
412
+ isoCodes .put (col .get (4 ).trim ().toUpperCase (), shortID );
408
413
isoCCA3 ++;
409
414
}
410
415
}
0 commit comments