All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.piacenti.dslmaker.structures.LinkedNode.kt Maven / Gradle / Ivy

Go to download

Kotlin multiplatform library to facilitate creation of DSLs with ANTLR or a simple built in parser

There is a newer version: 1.1.55
Show newest version
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