commonMain.com.bselzer.ktx.comparator.StringComparator.kt Maven / Gradle / Ivy
package com.bselzer.ktx.comparator
/**
* Compare nullable strings.
*/
open class StringComparator(private val ascending: Boolean = true) : Comparator
{
override fun compare(a: String?, b: String?): Int
{
return when
{
a == null && b == null -> 0
a == null -> -1
b == null -> 1
ascending -> a.compareTo(b)
else -> b.compareTo(a)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy