Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
mkljakubowski committed Dec 24, 2024
1 parent 1b9ff46 commit b0e0cbd
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions avrohugger-core/src/main/scala/generators/FileGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,25 @@ private[avrohugger] class FileGenerator {
}

private def distinctSchemaOrProtocol(schemaOrProtocols: List[Either[Schema, Protocol]]): List[Either[Schema, Protocol]] = {
schemaOrProtocols.map {
case Left(schema) => schema.getFullName -> Left(schema)
case Right(protocol) => Option(protocol.getNamespace).map(_ + ".").getOrElse("") + protocol.getName -> Right(protocol)
}
.toMap
.values
.toList
var processed = Set.empty[String]

schemaOrProtocols.flatMap {
case Left(schema) =>
if (!processed.contains(schema.getFullName)) {
processed += schema.getFullName
Some(Left(schema))
} else {
None
}
case Right(protocol) =>
val fullName = Option(protocol.getNamespace).map(ns => s"$ns.${protocol.getName}").getOrElse(protocol.getName)
if (!processed.contains(fullName)) {
processed += fullName
Some(Right(protocol))
} else {
None
}
}
}

}

0 comments on commit b0e0cbd

Please sign in to comment.