LEXICAL_ORDER

Deprecated

Warning since 2.1

Use naturalOrder<Uuid>() instead

Replace with

import kotlin.comparisons.naturalOrder
naturalOrder<Uuid>()

A Comparator that lexically orders uuids.

Note: Uuid is a Comparable type, and its compareTo function establishes lexical order. LEXICAL_ORDER was introduced when Uuids were not comparable. It is now deprecated and will be removed in a future release. Instead, use naturalOrder<Uuid>(), which is equivalent to LEXICAL_ORDER.

This comparator compares the given two 128-bit uuids bit by bit sequentially, starting from the most significant bit to the least significant. uuid a is considered less than b if, at the first position where corresponding bits of the two uuids differ, the bit in a is zero and the bit in b is one. Conversely, a is considered greater than b if, at the first differing position, the bit in a is one and the bit in b is zero. If no differing bits are found, the two uuids are considered equal.

The result of the comparison of uuids a and b by this comparator is equivalent to:

a.toString().compareTo(b.toString())

Since Kotlin

2.0

Samples

import kotlin.test.*
import kotlin.uuid.*

fun main() { 
   //sampleStart 
   val uuid1 = Uuid.parse("49d6d991-c780-4eb5-8585-5169c25af912")
val uuid2 = Uuid.parse("c0bac692-7208-4448-a8fe-3e3eb128db2a")
val uuid3 = Uuid.parse("49d6d991-aa92-4da0-917e-527c69621cb7")

val sortedUuids = listOf(uuid1, uuid2, uuid3).sortedWith(Uuid.LEXICAL_ORDER)

println(sortedUuids[0]) // 49d6d991-aa92-4da0-917e-527c69621cb7
println(sortedUuids[1]) // 49d6d991-c780-4eb5-8585-5169c25af912
println(sortedUuids[2]) // c0bac692-7208-4448-a8fe-3e3eb128db2a 
   //sampleEnd
}