com.stackmob.newman.enumeration

Enumeration

trait Enumeration extends Serializable

This is a fully type safe enumeration framework. It takes more setup & code than the built-in Scala Enumeration class, but it will pay off in 2 major ways:

1. you get to decide what happens when a conversion from a string to enum value fails 2. you get compiler warnings when you miss a match on one or more enum values (ie: non-exhaustive match error)

these benefits are worth the relatively small bit of extra code per enumeration.

How to use this to create enumerations of your own:

1. create your enumeration: package my.package //you must include this to avoid extending build-in scala enumerations import com.stackmob.common.enumeration._ //make sure this is sealed and an abstract class, not a trait sealed abstract class MyEnum extends Enumeration object MyEnumValue1 extends MyEnum { override lazy val stringVal = "my_enum_value_1" } object MyEnumValue2 extends MyEnum { override lazy val stringVal = "my_enum_value_2" } //create an EnumReader that knows how to convert strings into a MyEnum if the lowercase of the string //matches the lowercase of the enum string value value implicit val reader: EnumReader[MyEnum] = lowerEnumReader(MyEnumValue1, MyEnumValue2)

2. import your enum & the Enumeration implicits where you want to use the enum: package my.package import com.stackmob.common.enumeration._

3. use your enumeration & the implicits you imported to convert strings to your enum values: "my_enum_value_1".readEnum[MyEnum] match { case Some(MyEnumValue1) => doStuffForMyEnumValue1() case Some(MyEnumValue2) => doStuffForMyEnumValue2() //you will get warnings for non-exhaustive matches if you have more MyEnum subclasses than these case None => doStuffForNoEnum() }

Linear Supertypes
Serializable, Serializable, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Enumeration
  2. Serializable
  3. Serializable
  4. AnyRef
  5. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def stringVal: String

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  12. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  13. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  14. def matches(s: String): Boolean

  15. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  16. final def notify(): Unit

    Definition Classes
    AnyRef
  17. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  18. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  19. def toString(): String

    Definition Classes
    Enumeration → AnyRef → Any
  20. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped