commonMain.piacenti.dslmaker.structures.LinkedNode.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dsl-maker-js Show documentation
Show all versions of dsl-maker-js Show documentation
Kotlin multiplatform library to facilitate creation of DSLs with ANTLR or a simple built in parser
package piacenti.dslmaker.structures
interface LinkNode {
val value: T
val next: LinkNode?
val previous: LinkNode?
}
class LinkNodeMutable(override var value: T, override var next: LinkNode? = null, override var previous: LinkNode? = null) : LinkNode
class LinkedNodes(list: List) {
var node: LinkNode?
init {
if (list.isEmpty()) {
node = null
} else {
node = LinkNodeMutable(list.first())
var current = node as LinkNodeMutable
list.forEachIndexed { index, item ->
if (index > 0) {
val next = LinkNodeMutable(item)
next.previous = current
current.next = next
current = next
}
}
}
}
fun next(): LinkNode? {
node = node?.next
return node
}
@Suppress("unused")
fun previous(): LinkNode? {
node = node?.previous
return node
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy