From c1896eaeb1e4aedbf73cc893a01ba9dc5c2f7f08 Mon Sep 17 00:00:00 2001 From: Alex Bishop Date: Wed, 12 Feb 2020 19:09:25 +0000 Subject: [PATCH] =?UTF-8?q?BAU=20=E2=80=94=20Make=20some=20specific=20stri?= =?UTF-8?q?ng=20types=20extend=20WrappedStringValue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make some specific string types extend WrappedStringValue to leverage its equals(…), hashCode() and toString() methods. Delete CardHolderName because it is unused. --- .../charge/model/CardHolderName.java | 36 ------------------- .../charge/model/FirstDigitsCardNumber.java | 26 ++------------ .../charge/model/LastDigitsCardNumber.java | 28 +++------------ .../charge/model/ServicePaymentReference.java | 27 ++------------ 4 files changed, 10 insertions(+), 107 deletions(-) delete mode 100644 src/main/java/uk/gov/pay/connector/charge/model/CardHolderName.java diff --git a/src/main/java/uk/gov/pay/connector/charge/model/CardHolderName.java b/src/main/java/uk/gov/pay/connector/charge/model/CardHolderName.java deleted file mode 100644 index df19d405bf..0000000000 --- a/src/main/java/uk/gov/pay/connector/charge/model/CardHolderName.java +++ /dev/null @@ -1,36 +0,0 @@ -package uk.gov.pay.connector.charge.model; - -import java.util.Objects; - -public class CardHolderName { - - private final String cardHolderName; - - private CardHolderName(String cardHolderName) { - this.cardHolderName = Objects.requireNonNull(cardHolderName); - } - - public static CardHolderName of(String cardHolderName) { - return new CardHolderName(cardHolderName); - } - - @Override - public boolean equals(Object other) { - if (other != null && other.getClass() == CardHolderName.class) { - CardHolderName that = (CardHolderName) other; - return this.cardHolderName.equals(that.cardHolderName); - } - return false; - } - - @Override - public int hashCode() { - return cardHolderName.hashCode(); - } - - @Override - public String toString() { - return cardHolderName; - } - -} diff --git a/src/main/java/uk/gov/pay/connector/charge/model/FirstDigitsCardNumber.java b/src/main/java/uk/gov/pay/connector/charge/model/FirstDigitsCardNumber.java index bd610fa5b9..641e8c9999 100644 --- a/src/main/java/uk/gov/pay/connector/charge/model/FirstDigitsCardNumber.java +++ b/src/main/java/uk/gov/pay/connector/charge/model/FirstDigitsCardNumber.java @@ -1,15 +1,14 @@ package uk.gov.pay.connector.charge.model; import org.apache.commons.lang3.StringUtils; +import uk.gov.pay.commons.model.WrappedStringValue; import java.util.Objects; -public class FirstDigitsCardNumber { - - private final String firstDigitsCardNumber; +public class FirstDigitsCardNumber extends WrappedStringValue { private FirstDigitsCardNumber(String firstDigitsCardNumber) { - this.firstDigitsCardNumber = Objects.requireNonNull(firstDigitsCardNumber); + super(firstDigitsCardNumber); } private static boolean isValid(String firstDigitsCardNumber) { @@ -30,23 +29,4 @@ public static FirstDigitsCardNumber ofNullable(String firstDigitsCardNumber) { return new FirstDigitsCardNumber(firstDigitsCardNumber); } - @Override - public boolean equals(Object other) { - if (other != null && other.getClass() == FirstDigitsCardNumber.class) { - FirstDigitsCardNumber that = (FirstDigitsCardNumber) other; - return this.firstDigitsCardNumber.equals(that.firstDigitsCardNumber); - } - return false; - } - - @Override - public int hashCode() { - return firstDigitsCardNumber.hashCode(); - } - - @Override - public String toString() { - return firstDigitsCardNumber; - } - } diff --git a/src/main/java/uk/gov/pay/connector/charge/model/LastDigitsCardNumber.java b/src/main/java/uk/gov/pay/connector/charge/model/LastDigitsCardNumber.java index 3e3ad4a693..8e34a55b33 100644 --- a/src/main/java/uk/gov/pay/connector/charge/model/LastDigitsCardNumber.java +++ b/src/main/java/uk/gov/pay/connector/charge/model/LastDigitsCardNumber.java @@ -1,19 +1,18 @@ package uk.gov.pay.connector.charge.model; import org.apache.commons.lang3.StringUtils; +import uk.gov.pay.commons.model.WrappedStringValue; -public class LastDigitsCardNumber { - - private final String lastDigitsCardNumber; +public class LastDigitsCardNumber extends WrappedStringValue { private LastDigitsCardNumber(String lastDigitsCardNumber) { - this.lastDigitsCardNumber = lastDigitsCardNumber; + super(lastDigitsCardNumber); } private static boolean isValid(String lastDigitsCardNumber) { return lastDigitsCardNumber != null && lastDigitsCardNumber.length() == 4 && StringUtils.isNumeric(lastDigitsCardNumber); } - + public static LastDigitsCardNumber of(String lastDigitsCardNumber) { if (!(isValid(lastDigitsCardNumber))) { throw new RuntimeException("Expecting 4 last digits of card number"); @@ -28,23 +27,4 @@ public static LastDigitsCardNumber ofNullable(String lastDigitsCardNumber) { return new LastDigitsCardNumber(lastDigitsCardNumber); } - @Override - public boolean equals(Object other) { - if (other != null && other.getClass() == LastDigitsCardNumber.class) { - LastDigitsCardNumber that = (LastDigitsCardNumber) other; - return this.lastDigitsCardNumber.equals(that.lastDigitsCardNumber); - } - return false; - } - - @Override - public int hashCode() { - return lastDigitsCardNumber.hashCode(); - } - - @Override - public String toString() { - return lastDigitsCardNumber; - } - } diff --git a/src/main/java/uk/gov/pay/connector/charge/model/ServicePaymentReference.java b/src/main/java/uk/gov/pay/connector/charge/model/ServicePaymentReference.java index 421464cba0..9a584906c9 100644 --- a/src/main/java/uk/gov/pay/connector/charge/model/ServicePaymentReference.java +++ b/src/main/java/uk/gov/pay/connector/charge/model/ServicePaymentReference.java @@ -1,36 +1,15 @@ package uk.gov.pay.connector.charge.model; -import java.util.Objects; +import uk.gov.pay.commons.model.WrappedStringValue; -public class ServicePaymentReference { - - private final String servicePaymentReference; +public class ServicePaymentReference extends WrappedStringValue { private ServicePaymentReference(String servicePaymentReference) { - this.servicePaymentReference = Objects.requireNonNull(servicePaymentReference); + super(servicePaymentReference); } public static ServicePaymentReference of(String servicePaymentReference) { return new ServicePaymentReference(servicePaymentReference); } - @Override - public boolean equals(Object other) { - if (other != null && other.getClass() == ServicePaymentReference.class) { - ServicePaymentReference that = (ServicePaymentReference) other; - return this.servicePaymentReference.equals(that.servicePaymentReference); - } - return false; - } - - @Override - public int hashCode() { - return servicePaymentReference.hashCode(); - } - - @Override - public String toString() { - return servicePaymentReference; - } - }