org.jetbrains.kotlinx.jupyter.util.CompareUtil.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-jupyter-api Show documentation
Show all versions of kotlin-jupyter-api Show documentation
API for libraries supporting Kotlin Jupyter notebooks
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
}