views:

80

answers:

1

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?

+2  A: 

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.

Thomas Jung