diff --git a/kotlinx-uuid-core/api/android/kotlinx-uuid-core.api b/kotlinx-uuid-core/api/android/kotlinx-uuid-core.api index f058655..446b213 100644 --- a/kotlinx-uuid-core/api/android/kotlinx-uuid-core.api +++ b/kotlinx-uuid-core/api/android/kotlinx-uuid-core.api @@ -28,6 +28,7 @@ public final class app/softwork/uuid/UuidKt { public static final fun getNode (Lkotlin/uuid/Uuid;)J public static final fun getTimeStamp (Lkotlin/uuid/Uuid;)J public static final fun getVariant (Lkotlin/uuid/Uuid;)I + public static final fun getVersion (Lkotlin/uuid/Uuid;)I public static final fun getVersionNumber (Lkotlin/uuid/Uuid;)I public static final fun isRfcVariant (Lkotlin/uuid/Uuid;)Z public static final fun isValidUuidString (Lkotlin/uuid/Uuid$Companion;Ljava/lang/String;)Z diff --git a/kotlinx-uuid-core/api/jvm/kotlinx-uuid-core.api b/kotlinx-uuid-core/api/jvm/kotlinx-uuid-core.api index 9719e1a..2c161b8 100644 --- a/kotlinx-uuid-core/api/jvm/kotlinx-uuid-core.api +++ b/kotlinx-uuid-core/api/jvm/kotlinx-uuid-core.api @@ -28,6 +28,7 @@ public final class app/softwork/uuid/UuidKt { public static final fun getNode (Lkotlin/uuid/Uuid;)J public static final fun getTimeStamp (Lkotlin/uuid/Uuid;)J public static final fun getVariant (Lkotlin/uuid/Uuid;)I + public static final fun getVersion (Lkotlin/uuid/Uuid;)I public static final fun getVersionNumber (Lkotlin/uuid/Uuid;)I public static final fun isRfcVariant (Lkotlin/uuid/Uuid;)Z public static final fun isValidUuidString (Lkotlin/uuid/Uuid$Companion;Ljava/lang/String;)Z diff --git a/kotlinx-uuid-core/api/kotlinx-uuid-core.klib.api b/kotlinx-uuid-core/api/kotlinx-uuid-core.klib.api index d3dea44..26aa938 100644 --- a/kotlinx-uuid-core/api/kotlinx-uuid-core.klib.api +++ b/kotlinx-uuid-core/api/kotlinx-uuid-core.klib.api @@ -32,6 +32,8 @@ final val app.softwork.uuid/unixTimeStamp // app.softwork.uuid/unixTimeStamp|@ko final fun (kotlin.uuid/Uuid).(): kotlin/Long // app.softwork.uuid/unixTimeStamp.|@kotlin.uuid.Uuid(){}[0] final val app.softwork.uuid/variant // app.softwork.uuid/variant|@kotlin.uuid.Uuid{}variant[0] final fun (kotlin.uuid/Uuid).(): kotlin/Int // app.softwork.uuid/variant.|@kotlin.uuid.Uuid(){}[0] +final val app.softwork.uuid/version // app.softwork.uuid/version|@kotlin.uuid.Uuid{}version[0] + final fun (kotlin.uuid/Uuid).(): kotlin/Int // app.softwork.uuid/version.|@kotlin.uuid.Uuid(){}[0] final val app.softwork.uuid/versionNumber // app.softwork.uuid/versionNumber|@kotlin.uuid.Uuid{}versionNumber[0] final fun (kotlin.uuid/Uuid).(): kotlin/Int // app.softwork.uuid/versionNumber.|@kotlin.uuid.Uuid(){}[0] diff --git a/kotlinx-uuid-core/src/commonMain/kotlin/app/softwork/uuid/Uuid.kt b/kotlinx-uuid-core/src/commonMain/kotlin/app/softwork/uuid/Uuid.kt index 1b753ba..e02c125 100644 --- a/kotlinx-uuid-core/src/commonMain/kotlin/app/softwork/uuid/Uuid.kt +++ b/kotlinx-uuid-core/src/commonMain/kotlin/app/softwork/uuid/Uuid.kt @@ -31,7 +31,7 @@ public fun Uuid.Companion.from( } /** - * A 60-bits non-negative number. Depending on the Uuid version it could have different semantics: + * A 60-bits non-negative number. Depending on the Uuid [version] it could have different semantics: * - UTC time * - a number constructed from the namespace * - a random number @@ -51,15 +51,21 @@ public val Uuid.clockSequence: Int get() = toLongs { _, clockSequenceVariantAndNodeRaw -> (clockSequenceVariantAndNodeRaw shr 48 and 0x1fff).toInt() } /** - * Uuid [numeric version](https://tools.ietf.org/html/rfc4122#section-4.1.3) in range `[0..15] + * Uuid [numeric version](https://tools.ietf.org/html/rfc4122#section-4.1.3) in range `[0..15]` */ -public val Uuid.versionNumber: Int +@Deprecated("Use version instead", replaceWith = ReplaceWith("version")) +public val Uuid.versionNumber: Int get() = version + +/** + * Uuid [numeric version](https://tools.ietf.org/html/rfc4122#section-4.1.3) in range `[0..15]` + */ +public val Uuid.version: Int get() = toLongs { timeStampAndVersionRaw, _ -> (timeStampAndVersionRaw and 0xf000L shr 12).toInt() } /** - * Uuid variant in range `[0..7]`, similar to version + * Uuid variant in range `[0..7]`, similar to [version] */ public val Uuid.variant: Int get() = toLongs { _, clockSequenceVariantAndNodeRaw -> @@ -67,7 +73,7 @@ public val Uuid.variant: Int } /** - * Uuid variant specified and documented by the RFC + * Uuid [variant] specified and documented by the RFC */ public val Uuid.isRfcVariant: Boolean get() = variant == 4 || variant == 5 diff --git a/kotlinx-uuid-core/src/commonTest/kotlin/app/softwork/uuid/GenerationTest.kt b/kotlinx-uuid-core/src/commonTest/kotlin/app/softwork/uuid/GenerationTest.kt index 6d127c5..435b176 100644 --- a/kotlinx-uuid-core/src/commonTest/kotlin/app/softwork/uuid/GenerationTest.kt +++ b/kotlinx-uuid-core/src/commonTest/kotlin/app/softwork/uuid/GenerationTest.kt @@ -31,20 +31,20 @@ class GenerationTest { fun testGenerateFromName() { val baseUuid = Uuid.parse(SOME_UUID_STRING) val generated = Uuid.generateUuid(baseUuid, "test") - assertEquals(5, generated.versionNumber) + assertEquals(5, generated.version) assertEquals("9dc3df60-4ed1-5ea9-9e66-5c2030d5827b", generated.toString()) } @Test fun testGenerateFromBytes() { val generated = Uuid.generateUuid(SOME_UUID_STRING.explodeToBytes().toByteArray()) - assertEquals(5, generated.versionNumber) + assertEquals(5, generated.version) assertEquals("29e5befd-ca93-58bf-9ef0-30f7da112935", generated.toString()) } private fun Uuid.assertRandomGenerated() { assertTrue(isRfcVariant) - assertEquals(4, versionNumber) + assertEquals(4, version) } private fun String.explodeToBytes(): List { diff --git a/kotlinx-uuid-core/src/commonTest/kotlin/app/softwork/uuid/UuidTest.kt b/kotlinx-uuid-core/src/commonTest/kotlin/app/softwork/uuid/UuidTest.kt index 7ee6ad3..21d9df0 100644 --- a/kotlinx-uuid-core/src/commonTest/kotlin/app/softwork/uuid/UuidTest.kt +++ b/kotlinx-uuid-core/src/commonTest/kotlin/app/softwork/uuid/UuidTest.kt @@ -17,7 +17,7 @@ class UuidTest { fun testZero() { assertEquals("00000000-0000-0000-0000-000000000000", Uuid.NIL.toString()) assertEquals(0, Uuid.NIL.variant) - assertEquals(0, Uuid.NIL.versionNumber) + assertEquals(0, Uuid.NIL.version) assertEquals(0, Uuid.NIL.timeStamp) assertEquals(0, Uuid.NIL.clockSequence) assertEquals(0, Uuid.NIL.node) @@ -28,7 +28,7 @@ class UuidTest { fun testMax() { assertEquals("ffffffff-ffff-ffff-ffff-ffffffffffff", Uuid.MAX.toString()) assertEquals(7, Uuid.MAX.variant) - assertEquals(15, Uuid.MAX.versionNumber) + assertEquals(15, Uuid.MAX.version) assertEquals(1152921504606846975, Uuid.MAX.timeStamp) assertEquals(8191, Uuid.MAX.clockSequence) assertEquals(281474976710655, Uuid.MAX.node) @@ -39,7 +39,7 @@ class UuidTest { fun testConstructingFromString() { val uuid = Uuid.parse(UUID_STRING) - assertEquals(1, uuid.versionNumber) + assertEquals(1, uuid.version) assertEquals(5, uuid.variant) assertEquals("3d3e99b1b3e4567", uuid.timeStamp.toString(16)) assertEquals("476", uuid.clockSequence.toString(16)) @@ -53,7 +53,7 @@ class UuidTest { fun testConstructingFromStringAllFf() { val uuid = Uuid.parse(UUID_STRING_ALL_FF) - assertEquals(0xf, uuid.versionNumber) + assertEquals(0xf, uuid.version) assertEquals(7, uuid.variant) assertEquals("fffffffffffffff", uuid.timeStamp.toString(16)) assertEquals("1fff", uuid.clockSequence.toString(16)) @@ -65,7 +65,7 @@ class UuidTest { val first = Uuid.parse(SOME_UUID_STRING) val second = Uuid.from( timeStamp = first.timeStamp, - versionNumber = first.versionNumber, + versionNumber = first.version, clockSequence = first.clockSequence, node = first.node, variant = first.variant @@ -79,7 +79,7 @@ class UuidTest { val first = Uuid.parse(SOME_UUID_STRING) val second = Uuid.from( timeStamp = first.timeStamp, - versionNumber = first.versionNumber, + versionNumber = first.version, clockSequence = first.clockSequence, node = first.node ) @@ -92,7 +92,7 @@ class UuidTest { val first = Uuid.parse(UUID_STRING_ALL_FF) val second = Uuid.from( timeStamp = first.timeStamp, - versionNumber = first.versionNumber, + versionNumber = first.version, clockSequence = first.clockSequence, node = first.node, variant = first.variant @@ -113,11 +113,11 @@ class UuidTest { } assertFailsWith { - Uuid.from(first.versionNumber, first.timeStamp, Int.MAX_VALUE, first.node, first.variant) + Uuid.from(first.version, first.timeStamp, Int.MAX_VALUE, first.node, first.variant) } assertFailsWith { - Uuid.from(first.versionNumber, first.timeStamp, first.clockSequence, Long.MAX_VALUE, first.variant) + Uuid.from(first.version, first.timeStamp, first.clockSequence, Long.MAX_VALUE, first.variant) } assertFailsWith { @@ -125,19 +125,19 @@ class UuidTest { } assertFailsWith { - Uuid.from(first.versionNumber, -1, first.clockSequence, first.node, first.variant) + Uuid.from(first.version, -1, first.clockSequence, first.node, first.variant) } assertFailsWith { - Uuid.from(first.versionNumber, first.timeStamp, -1, first.node, first.variant) + Uuid.from(first.version, first.timeStamp, -1, first.node, first.variant) } assertFailsWith { - Uuid.from(first.versionNumber, first.timeStamp, first.clockSequence, -1, first.variant) + Uuid.from(first.version, first.timeStamp, first.clockSequence, -1, first.variant) } assertFailsWith { - Uuid.from(first.versionNumber, first.timeStamp, first.clockSequence, first.node, -1) + Uuid.from(first.version, first.timeStamp, first.clockSequence, first.node, -1) } } @@ -154,12 +154,12 @@ class UuidTest { @Test fun testVersionNumbers() { - assertEquals(1, Uuid.parse("1b3e4567-e99b-13d3-a476-446657420000").versionNumber) - assertEquals(2, Uuid.parse("1b3e4567-e99b-23d3-a476-446657420000").versionNumber) - assertEquals(3, Uuid.parse("1b3e4567-e99b-33d3-a476-446657420000").versionNumber) - assertEquals(4, Uuid.parse("1b3e4567-e99b-43d3-a476-446657420000").versionNumber) - assertEquals(5, Uuid.parse("1b3e4567-e99b-53d3-a476-446657420000").versionNumber) - assertEquals(0xf, Uuid.parse("1b3e4567-e99b-f3d3-a476-446657420000").versionNumber) + assertEquals(1, Uuid.parse("1b3e4567-e99b-13d3-a476-446657420000").version) + assertEquals(2, Uuid.parse("1b3e4567-e99b-23d3-a476-446657420000").version) + assertEquals(3, Uuid.parse("1b3e4567-e99b-33d3-a476-446657420000").version) + assertEquals(4, Uuid.parse("1b3e4567-e99b-43d3-a476-446657420000").version) + assertEquals(5, Uuid.parse("1b3e4567-e99b-53d3-a476-446657420000").version) + assertEquals(0xf, Uuid.parse("1b3e4567-e99b-f3d3-a476-446657420000").version) } @Test @@ -174,7 +174,7 @@ class UuidTest { @Test fun testRandomCreation() { - assertEquals(4, Uuid.random().versionNumber) - assertEquals(4, Random.nextUuid().versionNumber) + assertEquals(4, Uuid.random().version) + assertEquals(4, Random.nextUuid().version) } } diff --git a/kotlinx-uuid-core/src/commonTest/kotlin/app/softwork/uuid/Uuidv7Test.kt b/kotlinx-uuid-core/src/commonTest/kotlin/app/softwork/uuid/Uuidv7Test.kt index 4cac0e0..39f6bec 100644 --- a/kotlinx-uuid-core/src/commonTest/kotlin/app/softwork/uuid/Uuidv7Test.kt +++ b/kotlinx-uuid-core/src/commonTest/kotlin/app/softwork/uuid/Uuidv7Test.kt @@ -10,7 +10,7 @@ class Uuidv7Test { assertEquals(1645557742000, uuid.unixTimeStamp) assertEquals("017f22e2-79b0-7a1e-ad73-08cd2f61d78a", uuid.toString()) - assertEquals(7, uuid.versionNumber) + assertEquals(7, uuid.version) assertEquals(5, uuid.variant) } } diff --git a/kotlinx-uuid-datetime/src/commonTest/kotlin/app/softwork/uuid/datetime/InstantTest.kt b/kotlinx-uuid-datetime/src/commonTest/kotlin/app/softwork/uuid/datetime/InstantTest.kt index 8970cf4..81339b7 100644 --- a/kotlinx-uuid-datetime/src/commonTest/kotlin/app/softwork/uuid/datetime/InstantTest.kt +++ b/kotlinx-uuid-datetime/src/commonTest/kotlin/app/softwork/uuid/datetime/InstantTest.kt @@ -1,6 +1,6 @@ package app.softwork.uuid.datetime -import app.softwork.uuid.versionNumber +import app.softwork.uuid.version import kotlinx.datetime.Instant import kotlin.random.Random import kotlin.test.Test @@ -14,6 +14,6 @@ class InstantTest { val uuid = Uuidv7(timeStamp = timestamp, random = Random(4242)) assertEquals(timestamp, uuid.instant) assertEquals("0170621e-0ef0-7a1e-ad73-08cd2f61d78a", uuid.toString()) - assertEquals(7, uuid.versionNumber) + assertEquals(7, uuid.version) } }