![JAR search and dependency download from the Maven repository](/logo.png)
org.jetbrains.kotlinx.jupyter.util.CompareUtil.kt Maven / Gradle / Ivy
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 - 2025 Weber Informatics LLC | Privacy Policy