Skip to content

Commit

Permalink
replace asInstanceOf[List[A]] with asInstanceOf[Seq[A]]
Browse files Browse the repository at this point in the history
  • Loading branch information
iRevive committed Mar 27, 2024
1 parent 03bb112 commit 8ca7f6d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ trait Cogens {
def primitive[A: Cogen](seed: Seed): Seed =
Cogen[A].perturb(seed, attr.value.asInstanceOf[A])

def list[A: Cogen](seed: Seed): Seed =
Cogen[List[A]].perturb(seed, attr.value.asInstanceOf[List[A]])
def seq[A: Cogen](seed: Seed): Seed =
Cogen[Seq[A]].perturb(seed, attr.value.asInstanceOf[Seq[A]])

val valueCogen: Seed => Seed = attr.key.`type` match {
case AttributeType.Boolean => primitive[Boolean]
case AttributeType.Double => primitive[Double]
case AttributeType.String => primitive[String]
case AttributeType.Long => primitive[Long]
case AttributeType.BooleanSeq => list[Boolean]
case AttributeType.DoubleSeq => list[Double]
case AttributeType.StringSeq => list[String]
case AttributeType.LongSeq => list[Long]
case AttributeType.BooleanSeq => seq[Boolean]
case AttributeType.DoubleSeq => seq[Double]
case AttributeType.StringSeq => seq[String]
case AttributeType.LongSeq => seq[Long]
}

valueCogen(attributeKeyCogen.perturb(seed, attr.key))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ trait JsonCodecs {
def primitive[A: Encoder]: Json =
Encoder[A].apply(value.asInstanceOf[A])

def list[A: Encoder](attributeType: AttributeType[A]): Json = {
def seq[A: Encoder](attributeType: AttributeType[A]): Json = {
val typeName = attributeTypeName(attributeType)
val list = value.asInstanceOf[List[A]]
Json.obj("values" := list.map(value => Json.obj(typeName := value)))
val values = value.asInstanceOf[Seq[A]]
Json.obj("values" := values.map(value => Json.obj(typeName := value)))
}

implicit val longEncoder: Encoder[Long] =
Expand All @@ -83,10 +83,10 @@ trait JsonCodecs {
case AttributeType.Double => primitive[Double]
case AttributeType.String => primitive[String]
case AttributeType.Long => primitive[Long]
case AttributeType.BooleanSeq => list[Boolean](AttributeType.Boolean)
case AttributeType.DoubleSeq => list[Double](AttributeType.Double)
case AttributeType.StringSeq => list[String](AttributeType.String)
case AttributeType.LongSeq => list[Long](AttributeType.Long)
case AttributeType.BooleanSeq => seq[Boolean](AttributeType.Boolean)
case AttributeType.DoubleSeq => seq[Double](AttributeType.Double)
case AttributeType.StringSeq => seq[String](AttributeType.String)
case AttributeType.LongSeq => seq[Long](AttributeType.Long)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class ProtoEncoderSuite extends ScalaCheckSuite {
Prop.forAll(Arbitrary.arbitrary[Attribute[_]]) { attribute =>
val value = attribute.value

def list[A: Encoder](typeName: String): Json = {
val list = value.asInstanceOf[List[A]]
Json.obj("values" := list.map(value => Json.obj(typeName := value)))
def seq[A: Encoder](typeName: String): Json = {
val values = value.asInstanceOf[Seq[A]]
Json.obj("values" := values.map(value => Json.obj(typeName := value)))
}

implicit val longEncoder: Encoder[Long] =
Expand All @@ -64,13 +64,13 @@ class ProtoEncoderSuite extends ScalaCheckSuite {
case AttributeType.Long =>
Json.obj("intValue" := value.asInstanceOf[Long])
case AttributeType.BooleanSeq =>
Json.obj("arrayValue" := list[Boolean]("boolValue"))
Json.obj("arrayValue" := seq[Boolean]("boolValue"))
case AttributeType.DoubleSeq =>
Json.obj("arrayValue" := list[Double]("doubleValue"))
Json.obj("arrayValue" := seq[Double]("doubleValue"))
case AttributeType.StringSeq =>
Json.obj("arrayValue" := list[String]("stringValue"))
Json.obj("arrayValue" := seq[String]("stringValue"))
case AttributeType.LongSeq =>
Json.obj("arrayValue" := list[Long]("intValue"))
Json.obj("arrayValue" := seq[Long]("intValue"))
}

Json.obj("key" := attribute.key.name, "value" := v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ class OtlpHttpSpanExporterSuite
def primitive[A: Encoder](tpe: String): JaegerTag =
JaegerTag(a.key.name, tpe, a.value.asInstanceOf[A].asJson)

def list[A: Encoder]: JaegerTag = {
val json = a.value.asInstanceOf[List[A]].map(_.asJson).asJson
def seq[A: Encoder]: JaegerTag = {
val json = a.value.asInstanceOf[Seq[A]].map(_.asJson).asJson
JaegerTag(a.key.name, "string", json.noSpaces.asJson)
}

Expand All @@ -234,10 +234,10 @@ class OtlpHttpSpanExporterSuite
case AttributeType.String => primitive[String]("string")
case AttributeType.Double => primitive[Double]("float64")
case AttributeType.Long => primitive[Long]("int64")
case AttributeType.BooleanSeq => list[Boolean]
case AttributeType.StringSeq => list[String]
case AttributeType.DoubleSeq => list[Double]
case AttributeType.LongSeq => list[Long]
case AttributeType.BooleanSeq => seq[Boolean]
case AttributeType.StringSeq => seq[String]
case AttributeType.DoubleSeq => seq[Double]
case AttributeType.LongSeq => seq[Long]
}
}

Expand Down

0 comments on commit 8ca7f6d

Please sign in to comment.