This question is related to the first one: Iteration over a sealed trait in Scala?
I have the following sealed trait
/**
* @author Sebastien Lorber (<i>lorber.sebastien@gmail.com</i>)
* Date: 02/12/12 - Time: 17:49
*/
sealed trait ResizedImageKey {
/**
* Get the dimensions to use on the resized image associated with this key
*/
def getDimension(originalDimension: Dimension): Dimension
}
object ResizedImageKey {
val ALL_KEYS: List[ResizedImageKey] = List(Large,Medium,Small,X2)
}
case class Dimension(width: Int, height: Int)
case object Large extends ResizedImageKey {
def getDimension(originalDimension: Dimension) = Dimension(1000,1000)
}
case object Medium extends ResizedImageKey{
def getDimension(originalDimension: Dimension) = Dimension(500,500)
}
case object Small extends ResizedImageKey{
def getDimension(originalDimension: Dimension) = Dimension(100,100)
}
case object X2 extends ResizedImageKey{
def getDimension(originalDimension: Dimension) = Dimension(
width = originalDimension.width * 2,
height = originalDimension.height * 2
)
}
This works fine for now. The matter is that I need to be able to use my ResizedImageKey as a key for a map that will be stored in MongoDB with Salat.
I don't think Salat support "sealed trait convertion" right? So should I move to Enumeration, which forces me to do a match / case for the dimensions computations? Or is there any known solution to this problem? Is it possible to create enumeration Value object without extending Enumeration or something?
Thanks