Skip to content

Instantly share code, notes, and snippets.

@eutkin
Created May 21, 2024 16:07
Show Gist options
  • Save eutkin/cd66190f856313f745a35e2d76291515 to your computer and use it in GitHub Desktop.
Save eutkin/cd66190f856313f745a35e2d76291515 to your computer and use it in GitHub Desktop.
interface Component
class Detail : Component
class Model(val details: List<Component> = ArrayList()) : Component
operator fun Model.plusAssign(component: Component) {
this.details + component
}
interface Source
class DetailSource : Source
class Packet(val content : List<Source>) : Source
val rootPacket = Packet(arrayListOf()) // пакет с другими пакетами и деталями
val rootModel = Model()
rootModel += buildModel(rootPacket)
fun buildModel(packet: Packet) : Model {
val packets = packet.content
val model = Model()
for (childPacket in packets) {
val childModel = buildModel(packet)
model += childModel
}
return model
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment