Packages

abstract class Enum extends Serializable

Defines a finite set of values specific to the enumeration. Typically these values enumerate all possible forms something can take and provide a lightweight alternative to case classes.

Each call to a Value method adds a new unique value to the enumeration. To be accessible, these values are usually defined as val members of the enumeration.

All values in an enumeration share a common, unique type defined as the abstract Value type member of the enumeration (Value selected on the stable identifier path of the enumeration instance). Besides, in contrast to Scala's built-in Enumeration, the Value type member can be extended in subclasses, such that it is possible to mix-in traits, for example. In this case, make sure to make the constructor of Value private. Example:

// adding methods to Value
class Day private extends Day.Val {
  def isWorkingDay: Boolean = this != Day.Saturday && this != Day.Sunday
}
object Day extends Enum {
  type Value = Day
  val Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday = new Day
}

// usage:
Day.values filter (_.isWorkingDay) foreach println
// output:
// Monday
// Tuesday
// Wednesday
// Thursday
// Friday
Self Type
Enum
Annotations
@SerialVersionUID()
Example:
  1. // Example of adding attributes to an enumeration by extending the Enumeration.Val class
    object Planet extends Enumeration {
      protected case class PlanetVal(mass: Double, radius: Double) extends super.Val {
        def surfaceGravity: Double = Planet.G * mass / (radius * radius)
        def surfaceWeight(otherMass: Double): Double = otherMass * surfaceGravity
      }
      import scala.language.implicitConversions
      implicit def valueToPlanetVal(x: Value): PlanetVal = x.asInstanceOf[PlanetVal]
    
      val G: Double = 6.67300E-11
      val Mercury = PlanetVal(3.303e+23, 2.4397e6)
      val Venus   = PlanetVal(4.869e+24, 6.0518e6)
      val Earth   = PlanetVal(5.976e+24, 6.37814e6)
      val Mars    = PlanetVal(6.421e+23, 3.3972e6)
      val Jupiter = PlanetVal(1.9e+27, 7.1492e7)
      val Saturn  = PlanetVal(5.688e+26, 6.0268e7)
      val Uranus  = PlanetVal(8.686e+25, 2.5559e7)
      val Neptune = PlanetVal(1.024e+26, 2.4746e7)
    }
    
    println(Planet.values.filter(_.radius > 7.0e6))
    // output:
    // Planet.ValueSet(Jupiter, Saturn, Uranus, Neptune)
Linear Supertypes
Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Enum
  2. Serializable
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new Enum()
  2. new Enum(initial: Int)

    initial

    The initial value from which to count the integers that identifies values at run-time.

Type Members

  1. class Val extends Ordered[Value] with Serializable

    The superclass of the scala.Enum.Value type.

    The superclass of the scala.Enum.Value type. This class can be overridden to change the enumeration's naming and integer identification behaviour, as well as to add additional public functionality.

    Annotations
    @SerialVersionUID()
  2. abstract type Value <: Val

    The type of the enumerated values.

  3. class ValueSet extends AbstractSet[Value] with SortedSet[Value] with SortedSetOps[Value, SortedSet, ValueSet] with StrictOptimizedIterableOps[Value, Set, ValueSet] with Serializable

    A class for sets of values.

    A class for sets of values. Iterating through this set will yield values in increasing order of their ids.

    Annotations
    @SerialVersionUID()

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def apply(x: Int): Value

    The value of this enumeration with given id x

  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  9. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  10. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  12. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  13. final def maxId: Int

    The one higher than the highest integer amongst those used to identify values in this enumeration.

  14. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. var nextId: Int

    The integer to use to identify the next created value.

    The integer to use to identify the next created value.

    Attributes
    protected
  16. var nextName: Iterator[String]

    The string to use to name the next created value.

    The string to use to name the next created value.

    Attributes
    protected
  17. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  18. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  19. def readResolve(): AnyRef
    Attributes
    protected
  20. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  21. def toString(): String

    The name of this enumeration.

    The name of this enumeration.

    Definition Classes
    Enum → AnyRef → Any
  22. def values: ValueSet

    The values of this enumeration as a set.

  23. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  24. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  25. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  26. final def withName(s: String): Value

    Return a Value from this Enum whose name matches the argument s.

    Return a Value from this Enum whose name matches the argument s. The names are determined automatically via reflection.

    s

    an Enum name

    returns

    the Value of this Enum if its name matches s

    Exceptions thrown

    NoSuchElementException if no Value with a matching name is in this Enum

  27. implicit object ValueOrdering extends Ordering[Value]

    An ordering by id for values of this set

  28. object ValueSet extends SpecificIterableFactory[Value, ValueSet] with Serializable

    A factory object for value sets

    A factory object for value sets

    Annotations
    @SerialVersionUID()

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped