Scala Enums are fine, you could define Formats
and Extensions
like this:
object Formats extends Enumeration {
type Eny = Value
val YAML, XML, JSON = Value
}
object Extensions extends Enumeration {
type Eny = Value
val YAML, YML, XML, JSON = Value
}
And if you want to a map, just use a map:
val configFormats: Map[Extensions.Value, Formats.Value] = Map(
Extensions.YAML -> Formats.YAML,
Extensions.YML -> Formats.YAML,
Extensions.XML -> Formats.XML,
Extensions.JSON -> Formats.JSON)
Then I'm not really sure of what your methods are supposed to do, but it looks like your setFormat
could start like this:
def setFormat(extension: String): Unit = {
val format: Formats.Value = configFormats(Extensions withName extension)
...
}
You see, just like Java :) If you describe better what you are trying to do we might be able to give you a more "idiomatic way".