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

commonMain.com.bselzer.ktx.comparator.StringComparator.kt Maven / Gradle / Ivy

There is a newer version: 7.0.0
Show newest version
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