In Scala 2.7, Enumeration provide Set32/Set64 to build enum set and easily get the bitwise value in Long/Int or build enum set back from a Long/Int value (which ease db storage). Scala 2.8 removed these classes. Is there a replacement in 2.8 lib?
The representation is quite easy to implement and you should do this yourself as the internal implementation of the Scala libs may change and your data would be broken:
object WeekDay extends Enumeration {
type WeekDay = Value
val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value
}
import WeekDay._
val values = Set(Mon,Wed,Fri)
require(values.length < 31)
(0 /: values) ((s, c) => s | 1 << c.id).toBinaryString
Keep in mind that storing the ordinal in the database is fragile: Storing EnumSet in a database?. You should pick a stabile ordinal for each value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With