diff --git a/src/main/java/uk/gov/pay/connector/northamericaregion/CanadaPostalcodeToProvinceOrTerritoryMapper.java b/src/main/java/uk/gov/pay/connector/northamericaregion/CanadaPostalcodeToProvinceOrTerritoryMapper.java index 390320a538..cddac68055 100644 --- a/src/main/java/uk/gov/pay/connector/northamericaregion/CanadaPostalcodeToProvinceOrTerritoryMapper.java +++ b/src/main/java/uk/gov/pay/connector/northamericaregion/CanadaPostalcodeToProvinceOrTerritoryMapper.java @@ -5,27 +5,27 @@ import java.util.regex.Pattern; import static java.util.Map.entry; +import static uk.gov.pay.connector.northamericaregion.CanadaProvinceOrTerritory.ALBERTA; +import static uk.gov.pay.connector.northamericaregion.CanadaProvinceOrTerritory.BRITISH_COLUMBIA; +import static uk.gov.pay.connector.northamericaregion.CanadaProvinceOrTerritory.MANITOBA; import static uk.gov.pay.connector.northamericaregion.CanadaProvinceOrTerritory.NEWFOUNDLAND_AND_LABRADOR; +import static uk.gov.pay.connector.northamericaregion.CanadaProvinceOrTerritory.NEW_BRUNSWICK; +import static uk.gov.pay.connector.northamericaregion.CanadaProvinceOrTerritory.NORTHWEST_TERRITORIES; import static uk.gov.pay.connector.northamericaregion.CanadaProvinceOrTerritory.NOVA_SCOTIA; +import static uk.gov.pay.connector.northamericaregion.CanadaProvinceOrTerritory.NUNAVUT; +import static uk.gov.pay.connector.northamericaregion.CanadaProvinceOrTerritory.ONTARIO; import static uk.gov.pay.connector.northamericaregion.CanadaProvinceOrTerritory.PRINCE_EDWARD_ISLAND; -import static uk.gov.pay.connector.northamericaregion.CanadaProvinceOrTerritory.NEW_BRUNSWICK; import static uk.gov.pay.connector.northamericaregion.CanadaProvinceOrTerritory.QUEBEC; -import static uk.gov.pay.connector.northamericaregion.CanadaProvinceOrTerritory.ONTARIO; import static uk.gov.pay.connector.northamericaregion.CanadaProvinceOrTerritory.SASKATCHEWAN; -import static uk.gov.pay.connector.northamericaregion.CanadaProvinceOrTerritory.MANITOBA; -import static uk.gov.pay.connector.northamericaregion.CanadaProvinceOrTerritory.ALBERTA; -import static uk.gov.pay.connector.northamericaregion.CanadaProvinceOrTerritory.BRITISH_COLUMBIA; import static uk.gov.pay.connector.northamericaregion.CanadaProvinceOrTerritory.YUKON; -import static uk.gov.pay.connector.northamericaregion.CanadaProvinceOrTerritory.NUNAVUT; -import static uk.gov.pay.connector.northamericaregion.CanadaProvinceOrTerritory.NORTHWEST_TERRITORIES; public class CanadaPostalcodeToProvinceOrTerritoryMapper { - private final Pattern WELL_FORMED_POSTAL_CODE = Pattern.compile("([A-Z])[0-9][A-Z][0-9][A-Z][0-9]"); - private final Pattern WELL_FORMED_X_POSTAL_CODE = Pattern.compile("(X[0-9][A-Z])[0-9][A-Z][0-9]"); - private final String SANTA_CLAUS_POSTAL_CODE = "H0H0H0"; + private static final Pattern WELL_FORMED_POSTAL_CODE = Pattern.compile("([A-Z])[0-9][A-Z][0-9][A-Z][0-9]"); + private static final Pattern WELL_FORMED_X_POSTAL_CODE = Pattern.compile("(X[0-9][A-Z])[0-9][A-Z][0-9]"); + private static final String SANTA_CLAUS_POSTAL_CODE = "H0H0H0"; - public final Map NON_X_POSTAL_CODE_TERRITORY_PROVINCE_MAP = Map.ofEntries( + private static final Map NON_X_POSTAL_CODE_TERRITORY_PROVINCE_MAP = Map.ofEntries( entry("A", NEWFOUNDLAND_AND_LABRADOR), entry("B", NOVA_SCOTIA), entry("C", PRINCE_EDWARD_ISLAND), @@ -45,7 +45,7 @@ public class CanadaPostalcodeToProvinceOrTerritoryMapper { entry("Y", YUKON) ); - public final Map X_POSTAL_CODE_TERRITORY_MAP = Map.ofEntries( + private static final Map X_POSTAL_CODE_TERRITORY_MAP = Map.ofEntries( entry("X0A", NUNAVUT), entry("X0B", NUNAVUT), entry("X0C", NUNAVUT), diff --git a/src/main/java/uk/gov/pay/connector/northamericaregion/UsZipCodeToStateMap.java b/src/main/java/uk/gov/pay/connector/northamericaregion/UsZipCodeToStateMap.java index 5693651f82..04051bb560 100644 --- a/src/main/java/uk/gov/pay/connector/northamericaregion/UsZipCodeToStateMap.java +++ b/src/main/java/uk/gov/pay/connector/northamericaregion/UsZipCodeToStateMap.java @@ -5,11 +5,11 @@ import static uk.gov.pay.connector.northamericaregion.UsState.ALABAMA; import static uk.gov.pay.connector.northamericaregion.UsState.ALASKA; -import static uk.gov.pay.connector.northamericaregion.UsState.ARMED_FORCES_AMERICAS; import static uk.gov.pay.connector.northamericaregion.UsState.ARIZONA; import static uk.gov.pay.connector.northamericaregion.UsState.ARKANSAS; -import static uk.gov.pay.connector.northamericaregion.UsState.ARMED_FORCES_PACIFIC; +import static uk.gov.pay.connector.northamericaregion.UsState.ARMED_FORCES_AMERICAS; import static uk.gov.pay.connector.northamericaregion.UsState.ARMED_FORCES_EUROPE; +import static uk.gov.pay.connector.northamericaregion.UsState.ARMED_FORCES_PACIFIC; import static uk.gov.pay.connector.northamericaregion.UsState.CALIFORNIA; import static uk.gov.pay.connector.northamericaregion.UsState.COLORADO; import static uk.gov.pay.connector.northamericaregion.UsState.CONNECTICUT; @@ -64,10 +64,10 @@ public class UsZipCodeToStateMap { /** - We have to use this initializiation method because using 'Map.ofEntries(...)' with hundreds of arguments is excessively slow to compile. See https://youtrack.jetbrains.com/issue/IDEA-245963 - */ - - public final static Map ZIP_CODE_TO_US_STATE_ABBREVIATIONS = Map.copyOf(new HashMap<>() {{ + * We have to use this initializiation method because using 'Map.ofEntries(...)' with hundreds of arguments is excessively slow to compile. + * See https://youtrack.jetbrains.com/issue/IDEA-245963 + **/ + public static final Map ZIP_CODE_TO_US_STATE_ABBREVIATIONS = Map.copyOf(new HashMap<>() {{ put("005", NEW_YORK); put("006", PUERTO_RICO); put("007", PUERTO_RICO); diff --git a/src/main/java/uk/gov/pay/connector/northamericaregion/UsZipCodeToStateMapper.java b/src/main/java/uk/gov/pay/connector/northamericaregion/UsZipCodeToStateMapper.java index e67b987efc..981d8b4e07 100644 --- a/src/main/java/uk/gov/pay/connector/northamericaregion/UsZipCodeToStateMapper.java +++ b/src/main/java/uk/gov/pay/connector/northamericaregion/UsZipCodeToStateMapper.java @@ -10,9 +10,10 @@ public class UsZipCodeToStateMapper { - private final Pattern WELL_FORMED_ZIP_CODE_AND_OPTIONAL_PLUS_FOUR = Pattern.compile("([0-9]{3})[0-9]{2}(?:-[0-9]{4})?"); - private final Pattern WELL_FORMED_STATE_WITH_ZIP_CODE_AND_OPTIONAL_PLUS_FOUR = Pattern.compile("([A-Z]{2})[0-9]{5}(?:-[0-9]{4})?"); - private final Map US_STATE_ABBREVIATIONS_MAPPING = Arrays.stream(UsState.values()).collect( + private static final Pattern WELL_FORMED_ZIP_CODE_AND_OPTIONAL_PLUS_FOUR = Pattern.compile("([0-9]{3})[0-9]{2}(?:-[0-9]{4})?"); + private static final Pattern WELL_FORMED_STATE_WITH_ZIP_CODE_AND_OPTIONAL_PLUS_FOUR = Pattern.compile("([A-Z]{2})[0-9]{5}(?:-[0-9]{4})?"); + + private static final Map US_STATE_ABBREVIATIONS_MAPPING = Arrays.stream(UsState.values()).collect( toUnmodifiableMap(NorthAmericaRegion::getAbbreviation, identity())); public Optional getState(String normalisedZipCode) {