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

org.jetbrains.kotlinx.jupyter.util.CompareUtil.kt Maven / Gradle / Ivy

There is a newer version: 0.12.0-335
Show newest version
package org.jetbrains.kotlinx.jupyter.util

import kotlin.reflect.KProperty1

fun > compareNullable(
    s1: T?,
    s2: T?,
): Int {
    return if (s1 == null) {
        if (s2 == null) {
            0
        } else {
            -1
        }
    } else {
        if (s2 == null) {
            1
        } else {
            s1.compareTo(s2)
        }
    }
}

fun , P : Comparable

> T.compareProperty( other: T, property: KProperty1, ): Int { val thisP = property.get(this) val otherP = property.get(other) return compareNullable(thisP, otherP) } fun , P : Comparable

> T.compareByProperties( other: T, vararg properties: KProperty1, ): Int { for (prop in properties) { val comparison = compareProperty(other, prop) if (comparison != 0) return comparison } return 0 }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy