Skip to content

Commit 1508fd7

Browse files
authored
Merge pull request #482 from tomasherman/master
481: Add hashCode and equals for `Currency` class
2 parents fd536fb + dbb2dc3 commit 1508fd7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

shared/src/main/scala/squants/market/Money.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,24 @@ abstract class Currency(val code: String, val name: String, val symbol: String,
433433
protected def converterTo: Double Double = ???
434434
def /(that: Money): CurrencyExchangeRate = that toThe Money(1, this)
435435
override def toString: String = code
436+
437+
438+
def canEqual(other: Any): Boolean = other.isInstanceOf[Currency]
439+
440+
override def equals(other: Any): Boolean = other match {
441+
case that: Currency =>
442+
(that canEqual this) &&
443+
code == that.code &&
444+
name == that.name &&
445+
symbol == that.symbol &&
446+
formatDecimals == that.formatDecimals
447+
case _ => false
448+
}
449+
450+
override def hashCode(): Int = {
451+
val state = Seq(code, name, symbol, formatDecimals)
452+
state.map(_.hashCode()).foldLeft(0)((a, b) => 31 * a + b)
453+
}
436454
}
437455

438456
object Currency {

0 commit comments

Comments
 (0)