Skip to content

Commit

Permalink
Make KsuidValue sortable
Browse files Browse the repository at this point in the history
  • Loading branch information
oharaandrew314 committed Sep 18, 2023
1 parent 8fb89c2 commit eba9f12
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion values4k/src/main/kotlin/dev/forkhandles/values/ksuid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import java.time.Clock
import java.time.Instant
import java.util.Random

typealias KsuidValue = AbstractValue<Ksuid>
abstract class KsuidValue(value: Ksuid): AbstractValue<Ksuid>(value), Comparable<KsuidValue> {
override fun compareTo(other: KsuidValue) = value.compareTo(other.value)
}

open class KsuidValueFactory<DOMAIN : Value<Ksuid>>(
fn: (Ksuid) -> DOMAIN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.github.ksuid.Ksuid
import com.github.ksuid.KsuidGenerator
import com.natpryce.hamkrest.assertion.assertThat
import com.natpryce.hamkrest.equalTo
import com.natpryce.hamkrest.lessThan
import org.junit.jupiter.api.Test
import java.time.Clock
import java.time.Instant
Expand Down Expand Up @@ -33,4 +34,11 @@ class KsuidValueTest {
assertThat(ksuid.instant, equalTo(Instant.parse("2023-09-18T19:08:58Z")))
assertThat(ksuid.value.toString(), equalTo( "2VaB6tloDoOktDfrzWsjLnnTe9T"))
}

@Test
fun `compare ids`() {
val value1 = MyKsuidValue.parse("2VaFa3DfKMINqSUtdJoTtAMwsHU")
val value2 = MyKsuidValue.parse("2VaFcctoWGZV2W7coyJab0p99Sa")
assertThat(value1, lessThan(value2))
}
}

0 comments on commit eba9f12

Please sign in to comment.