diff --git a/src/main/scala/se/nimsa/dicom/data/CharacterSets.scala b/src/main/scala/se/nimsa/dicom/data/CharacterSets.scala index b3e4bd7..cf18dd2 100644 --- a/src/main/scala/se/nimsa/dicom/data/CharacterSets.scala +++ b/src/main/scala/se/nimsa/dicom/data/CharacterSets.scala @@ -73,6 +73,13 @@ class CharacterSets(val charsetNames: Seq[String]) { } override def toString: String = s"${getClass.getSimpleName} [${specifiedCharsets.map(_.charset.toString).mkString(",")}]" + + override def equals(that: Any): Boolean = that match { + case thatCharSets: CharacterSets => charsetNames == thatCharSets.charsetNames + case _ => this == that + } + + override def hashCode(): Int = charsetNames.hashCode } object CharacterSets { diff --git a/src/test/scala/se/nimsa/dicom/data/CharacterSetsTest.scala b/src/test/scala/se/nimsa/dicom/data/CharacterSetsTest.scala index f8d1ec9..ede9603 100644 --- a/src/test/scala/se/nimsa/dicom/data/CharacterSetsTest.scala +++ b/src/test/scala/se/nimsa/dicom/data/CharacterSetsTest.scala @@ -103,6 +103,13 @@ class CharacterSetsTest extends TestKit(ActorSystem("CharacterSetsSpec")) with F checkPatientName(name, nameCodePoints) } + "CharacterSets" should "be comparable" in { + val cs1 = new CharacterSets(Seq("ISO 2022 IR 13", "ISO 2022 IR 87")) + val cs2 = new CharacterSets(Seq("ISO 2022 IR 13", "ISO 2022 IR 87")) + cs1 shouldBe cs2 + cs1.hashCode shouldBe cs2.hashCode + } + private def checkPatientName(name: String, expectedCodePoints: Array[Int]): Unit = { val codePoints = new Array[Int](name.codePointCount(0, name.length)) val length = name.length