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

divkit.dsl.NumberVariable.kt Maven / Gradle / Ivy

Go to download

DivKit is an open source Server-Driven UI (SDUI) framework. SDUI is a an emerging technique that leverage the server to build the user interfaces of their mobile app.

There is a newer version: 30.19.0
Show newest version
@file:Suppress(
    "unused",
    "UNUSED_PARAMETER",
)

package divkit.dsl

import com.fasterxml.jackson.annotation.JsonAnyGetter
import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonValue
import divkit.dsl.annotation.*
import divkit.dsl.core.*
import divkit.dsl.scope.*
import kotlin.Any
import kotlin.String
import kotlin.Suppress
import kotlin.collections.List
import kotlin.collections.Map

/**
 * A floating-point variable.
 * 
 * Can be created using the method [numberVariable].
 * 
 * Required parameters: `value, type, name`.
 */
@Generated
class NumberVariable internal constructor(
    @JsonIgnore
    val properties: Properties,
) : Variable {
    @JsonAnyGetter
    internal fun getJsonProperties(): Map = properties.mergeWith(
        mapOf("type" to "number")
    )

    operator fun plus(additive: Properties): NumberVariable = NumberVariable(
        Properties(
            name = additive.name ?: properties.name,
            value = additive.value ?: properties.value,
        )
    )

    class Properties internal constructor(
        /**
         * Variable name.
         */
        val name: Property?,
        /**
         * Value.
         */
        val value: Property?,
    ) {
        internal fun mergeWith(properties: Map): Map {
            val result = mutableMapOf()
            result.putAll(properties)
            result.tryPutProperty("name", name)
            result.tryPutProperty("value", value)
            return result
        }
    }
}

/**
 * @param name Variable name.
 * @param value Value.
 */
@Generated
fun DivScope.numberVariable(
    `use named arguments`: Guard = Guard.instance,
    name: String? = null,
    value: Double? = null,
): NumberVariable = NumberVariable(
    NumberVariable.Properties(
        name = valueOrNull(name),
        value = valueOrNull(value),
    )
)

/**
 * @param name Variable name.
 * @param value Value.
 */
@Generated
fun DivScope.numberVariableProps(
    `use named arguments`: Guard = Guard.instance,
    name: String? = null,
    value: Double? = null,
) = NumberVariable.Properties(
    name = valueOrNull(name),
    value = valueOrNull(value),
)

/**
 * @param name Variable name.
 * @param value Value.
 */
@Generated
fun TemplateScope.numberVariableRefs(
    `use named arguments`: Guard = Guard.instance,
    name: ReferenceProperty? = null,
    value: ReferenceProperty? = null,
) = NumberVariable.Properties(
    name = name,
    value = value,
)

/**
 * @param name Variable name.
 * @param value Value.
 */
@Generated
fun NumberVariable.override(
    `use named arguments`: Guard = Guard.instance,
    name: String? = null,
    value: Double? = null,
): NumberVariable = NumberVariable(
    NumberVariable.Properties(
        name = valueOrNull(name) ?: properties.name,
        value = valueOrNull(value) ?: properties.value,
    )
)

/**
 * @param name Variable name.
 * @param value Value.
 */
@Generated
fun NumberVariable.defer(
    `use named arguments`: Guard = Guard.instance,
    name: ReferenceProperty? = null,
    value: ReferenceProperty? = null,
): NumberVariable = NumberVariable(
    NumberVariable.Properties(
        name = name ?: properties.name,
        value = value ?: properties.value,
    )
)

@Generated
fun NumberVariable.asList() = listOf(this)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy