3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-12 18:25:51 +00:00

MonetaryFormat: Implement equals() and hashCode().

This commit is contained in:
Andreas Schildbach 2018-04-01 19:50:32 +02:00
parent 8663236de0
commit 03f404506c

View File

@ -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);
}
}