Created
January 21, 2019 21:43
-
-
Save efontan/70437cfd404c1730a0b89ea8169e6e56 to your computer and use it in GitHub Desktop.
Scala Enumeration - Intellij fileTemplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if ((${PACKAGE_NAME} && ${PACKAGE_NAME} != ""))package ${PACKAGE_NAME} #end | |
#parse("File Header.java") | |
object ${NAME} extends Enumeration { | |
type ${NAME} = Value | |
val ValueOne, ValueTwo = Value | |
def apply(name: String): ${NAME}.Value = name.toLowerCase() match { | |
case "valueone" => ValueOne | |
// ... | |
} | |
def valueOf(valueAsString: String): Option[${NAME}.Value] = { | |
val maybeValue = if (valueAsString == null || "null".equals(valueAsString.trim.toLowerCase())) { | |
None | |
} else { | |
Some(${NAME}(valueAsString.trim)) | |
} | |
maybeValue | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment