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

com.tairitsu.ignotus.translation.provider.resource.model.ResourceMessageNode.kt Maven / Gradle / Ivy

There is a newer version: 1.0.32
Show newest version
package com.tairitsu.ignotus.translation.provider.resource.model

/**
 * 文本字段节点
 */
class ResourceMessageNode {
    private val children = HashMap()

    var value: ResourceMessageLine? = null

    operator fun get(key: String): ResourceMessageNode? {
        return children[key]
    }

    operator fun set(key: String, value: ResourceMessageNode) {
        children[key] = value
    }

    fun walkOrNull(prefix: String): ResourceMessageNode? {
        return walkOrNull(prefix.split("."))
    }

    private fun walkOrNull(prefix: List): ResourceMessageNode? {
        if (prefix.isEmpty()) {
            return this
        }

        val key = prefix[0]
        val node = children[key] ?: return null

        return node.walkOrNull(prefix.subList(1, prefix.size))
    }

    fun walkOrCreate(prefix: String): ResourceMessageNode {
        return walkOrCreate(prefix.split("."))
    }

    private fun walkOrCreate(prefix: List): ResourceMessageNode {
        if (prefix.isEmpty()) {
            return this
        }

        val key = prefix[0]
        val node = children[key]
        if (node == null) {
            val newNode = ResourceMessageNode()
            children[key] = newNode
            return newNode.walkOrCreate(prefix.subList(1, prefix.size))
        }

        return node.walkOrCreate(prefix.subList(1, prefix.size))
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy