From dbb2dc39408f9cdb44901f233a4dbaa294c54141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=CC=81s=CC=8C=20Her=CC=8Cman?= Date: Thu, 12 Aug 2021 07:24:44 +0200 Subject: [PATCH] Fix #481: Add hashCode and equals for `Currency` class --- .../src/main/scala/squants/market/Money.scala | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/shared/src/main/scala/squants/market/Money.scala b/shared/src/main/scala/squants/market/Money.scala index 39617cf3..91a79e1d 100644 --- a/shared/src/main/scala/squants/market/Money.scala +++ b/shared/src/main/scala/squants/market/Money.scala @@ -433,6 +433,24 @@ abstract class Currency(val code: String, val name: String, val symbol: String, protected def converterTo: Double ⇒ Double = ??? def /(that: Money): CurrencyExchangeRate = that toThe Money(1, this) override def toString: String = code + + + def canEqual(other: Any): Boolean = other.isInstanceOf[Currency] + + override def equals(other: Any): Boolean = other match { + case that: Currency => + (that canEqual this) && + code == that.code && + name == that.name && + symbol == that.symbol && + formatDecimals == that.formatDecimals + case _ => false + } + + override def hashCode(): Int = { + val state = Seq(code, name, symbol, formatDecimals) + state.map(_.hashCode()).foldLeft(0)((a, b) => 31 * a + b) + } } object Currency {