From 48f7aa41dc8928c8fb8895a705a24efa2ad06f9d Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Thu, 25 Apr 2019 16:29:06 +0200 Subject: [PATCH] Allow to evolve l.d.Attributes while maintaining bin compat --- .../lmcoursier/definitions/Attributes.scala | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/modules/lm-coursier/src/main/scala/lmcoursier/definitions/Attributes.scala b/modules/lm-coursier/src/main/scala/lmcoursier/definitions/Attributes.scala index fa6a8aeb5..2daf0c1d1 100644 --- a/modules/lm-coursier/src/main/scala/lmcoursier/definitions/Attributes.scala +++ b/modules/lm-coursier/src/main/scala/lmcoursier/definitions/Attributes.scala @@ -1,6 +1,35 @@ package lmcoursier.definitions -final case class Attributes( - `type`: Type, - classifier: Classifier -) +final class Attributes private ( + val `type`: Type, + val classifier: Classifier +) { + + override def equals(obj: Any): Boolean = + obj match { + case other: Attributes => + `type` == other.`type` && classifier == other.classifier + case _ => false + } + override def hashCode(): Int = + 37 * (37 * (37 * (17 + "lmcoursier.definitions.Attributes".##) + `type`.##) + classifier.##) + override def toString: String = + s"Attributes(${`type`}, $classifier)" + + private def copy( + `type`: Type = `type`, + classifier: Classifier = classifier + ): Attributes = + new Attributes(`type`, classifier) + + def withType(`type`: Type): Attributes = + copy(`type` = `type`) + def withClassifier(classifier: Classifier): Attributes = + copy(classifier = classifier) + +} + +object Attributes { + def apply(`type`: Type, classifier: Classifier): Attributes = + new Attributes(`type`, classifier) +}