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

org.partiql.lang.util.LongExtensions.kt Maven / Gradle / Ivy

There is a newer version: 1.0.0-perf.1
Show newest version
package org.partiql.lang.util

/**
 * Converts [this] [Long] to a [Int], throwing an exception in case the value is outside the range of an [Int].
 *
 * This is needed because Kotlin's default [Long.toInt()] returns `-1` instead of throwing an exception.
 */
fun Long.toIntExact(): Int =
    if (this !in Int.MIN_VALUE..Int.MAX_VALUE) {
        throw IllegalStateException("Long value is not within Int.MIN_VALUE..Int.MAX_VALUE")
    } else {
        this.toInt()
    }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy