diff --git a/core/src/main/java/org/bitcoinj/utils/MonetaryFormat.java b/core/src/main/java/org/bitcoinj/utils/MonetaryFormat.java index dc5e9b4b..63f56d8e 100644 --- a/core/src/main/java/org/bitcoinj/utils/MonetaryFormat.java +++ b/core/src/main/java/org/bitcoinj/utils/MonetaryFormat.java @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Locale; +import java.util.Objects; import org.bitcoinj.core.Coin; import org.bitcoinj.core.Monetary; @@ -451,4 +452,45 @@ public final class MonetaryFormat { throw new NumberFormatException("missing code for shift: " + shift); return codes[shift]; } + + /** + * Two formats are equal if they have the same parameters. + */ + @Override + public boolean equals(final Object o) { + if (o == this) + return true; + if (o == null || o.getClass() != getClass()) + return false; + final MonetaryFormat other = (MonetaryFormat) o; + if (!Objects.equals(this.negativeSign, other.negativeSign)) + return false; + if (!Objects.equals(this.positiveSign, other.positiveSign)) + return false; + if (!Objects.equals(this.zeroDigit, other.zeroDigit)) + return false; + if (!Objects.equals(this.decimalMark, other.decimalMark)) + return false; + if (!Objects.equals(this.minDecimals, other.minDecimals)) + return false; + if (!Objects.equals(this.decimalGroups, other.decimalGroups)) + return false; + if (!Objects.equals(this.shift, other.shift)) + return false; + if (!Objects.equals(this.roundingMode, other.roundingMode)) + return false; + if (!Objects.equals(this.codes, other.codes)) + return false; + if (!Objects.equals(this.codeSeparator, other.codeSeparator)) + return false; + if (!Objects.equals(this.codePrefixed, other.codePrefixed)) + return false; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(negativeSign, positiveSign, zeroDigit, decimalMark, minDecimals, decimalGroups, shift, + roundingMode, codes, codeSeparator, codePrefixed); + } }