Deconstructing Ids

Id is a Value Class with an underlying Long and it contains methods which extract its parameters. Id’s companion object contains factory methods, extractors and Orderings.

import gr.jkl.uid.{ Id, Scheme }
val id = Id(-9217076510208286673L)
implicit val scheme = Scheme(44, 12, 8, 1351728000000L)

id.timestamp
// res0: Long = 1357731882071

id.node
// res1: Long = 32

id.sequence
// res2: Long = 47

id.underlying
// res3: Long = -9217076510208286673

Id.create(1357731882071L, 32, 47)
// res4: Option[gr.jkl.uid.Id] = Some(--LMQy4R1-j)

Timestamp, node and sequence, among other methods, depend on the id’s underlying Long and on the scheme. A different scheme would produce different results.

import gr.jkl.uid.{ Id, Scheme }

val id = Id(-9217076510208286673L)

implicit val scheme = Scheme(43, 16, 5, 1357700000000L)

id.timestamp
// res0: Long = 1360701941035

id.node
// res1: Long = 33025

id.sequence
// res2: Long = 15
Fork me on GitHub