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

commonMain.jetbrains.datalore.plot.base.data.Dummies.kt Maven / Gradle / Ivy

There is a newer version: 4.5.3-alpha1
Show newest version
/*
 * Copyright (c) 2019. JetBrains s.r.o.
 * Use of this source code is governed by the MIT license that can be found in the LICENSE file.
 */

package jetbrains.datalore.plot.base.data

import jetbrains.datalore.plot.base.DataFrame

object Dummies {

    private const val PREFIX = "__"

    fun isDummyVar(varName: String): Boolean {
        if (varName.isNotBlank() && varName.length > PREFIX.length && varName.startsWith(
                PREFIX
            )
        ) {
            val numStr = varName.substring(PREFIX.length)
            return numStr.matches("[0-9]+".toRegex())
        }
        return false
    }

    fun dummyNames(count: Int): List {
        val l = ArrayList()
        for (i in 0 until count) {
            l.add(PREFIX + i)
        }
        return l
    }

    fun newDummy(varName: String): DataFrame.Variable {
        require(isDummyVar(varName)) { "Not a dummy var name" }
        // no label
        return DataFrame.Variable(varName, DataFrame.Variable.Source.ORIGIN, "")
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy