Skip to content

Commit

Permalink
Merge pull request #482 from tomasherman/master
Browse files Browse the repository at this point in the history
481: Add hashCode and equals for `Currency` class
  • Loading branch information
cquiroz authored Aug 12, 2021
2 parents fd536fb + dbb2dc3 commit 1508fd7
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions shared/src/main/scala/squants/market/Money.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1508fd7

Please sign in to comment.