Skip to content

Commit

Permalink
Merge pull request #2107 from alphagov/bau_use_WrappedStringValue
Browse files Browse the repository at this point in the history
BAU — Make some specific string types extend WrappedStringValue
  • Loading branch information
alexbishop1 authored Feb 13, 2020
2 parents 3ce59cf + c1896ea commit 910d080
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 107 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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;
}

}

0 comments on commit 910d080

Please sign in to comment.