@@ -239,12 +239,8 @@ protected Map<String, Object> transform(final CityResponse response) {
239239 }
240240 }
241241 case REGION_ISO_CODE -> {
242- // ISO 3166-2 code for country subdivisions.
243- // See iso.org/iso-3166-country-codes.html
244- String countryIso = country .getIsoCode ();
245- String subdivisionIso = subdivision .getIsoCode ();
246- if (countryIso != null && subdivisionIso != null ) {
247- String regionIsoCode = countryIso + "-" + subdivisionIso ;
242+ String regionIsoCode = regionIsoCode (country , subdivision );
243+ if (regionIsoCode != null ) {
248244 data .put ("region_iso_code" , regionIsoCode );
249245 }
250246 }
@@ -510,12 +506,8 @@ protected Map<String, Object> transform(final EnterpriseResponse response) {
510506 }
511507 }
512508 case REGION_ISO_CODE -> {
513- // ISO 3166-2 code for country subdivisions.
514- // See iso.org/iso-3166-country-codes.html
515- String countryIso = country .getIsoCode ();
516- String subdivisionIso = subdivision .getIsoCode ();
517- if (countryIso != null && subdivisionIso != null ) {
518- String regionIsoCode = countryIso + "-" + subdivisionIso ;
509+ String regionIsoCode = regionIsoCode (country , subdivision );
510+ if (regionIsoCode != null ) {
519511 data .put ("region_iso_code" , regionIsoCode );
520512 }
521513 }
@@ -783,4 +775,16 @@ private static Boolean isInEuropeanUnion(com.maxmind.geoip2.record.Country count
783775 // for this if there's actually a real country here, as opposed to an empty null-object country, so we check for an iso code first
784776 return (country .getIsoCode () == null ) ? null : country .isInEuropeanUnion ();
785777 }
778+
779+ @ Nullable
780+ private static String regionIsoCode (final com .maxmind .geoip2 .record .Country country , final Subdivision subdivision ) {
781+ // ISO 3166-2 code for country subdivisions, see https://www.iso.org/iso-3166-country-codes.html
782+ final String countryIso = country .getIsoCode ();
783+ final String subdivisionIso = subdivision .getIsoCode ();
784+ if (countryIso != null && subdivisionIso != null ) {
785+ return countryIso + "-" + subdivisionIso ;
786+ } else {
787+ return null ;
788+ }
789+ }
786790}
0 commit comments