Packages

  • package root
    Definition Classes
    root
  • package io
    Definition Classes
    root
  • package github
    Definition Classes
    io
  • package memo33
    Definition Classes
    github
  • package scalaenum
    Definition Classes
    memo33
  • abstract class Enum extends Serializable

    Defines a finite set of values specific to the enumeration.

    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
    Definition Classes
    scalaenum
    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)
  • Val
  • Value
  • ValueOrdering
  • ValueSet

class Val extends Ordered[Value] with Serializable

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.

Self Type
Value
Annotations
@SerialVersionUID()
Linear Supertypes
Serializable, Ordered[Value], Comparable[Value], AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Val
  2. Serializable
  3. Ordered
  4. Comparable
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new Val()
    Attributes
    protected
  2. new Val(name: String)
    Attributes
    protected
  3. new Val(i: Int)
    Attributes
    protected
  4. new Val(i: Int, name: String)
    Attributes
    protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. def +(v: Value): ValueSet

    Create a ValueSet which contains this value and another one

  4. def <(that: Value): Boolean
    Definition Classes
    Ordered
  5. def <=(that: Value): Boolean
    Definition Classes
    Ordered
  6. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  7. def >(that: Value): Boolean
    Definition Classes
    Ordered
  8. def >=(that: Value): Boolean
    Definition Classes
    Ordered
  9. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  10. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  11. def compare(that: Value): Int
    Definition Classes
    Val → Ordered
  12. def compareTo(that: Value): Int
    Definition Classes
    Ordered → Comparable
  13. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  14. def equals(other: Any): Boolean
    Definition Classes
    Val → AnyRef → Any
  15. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  16. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  17. def hashCode(): Int
    Definition Classes
    Val → AnyRef → Any
  18. def id: Int

    the id and bit location of this enumeration value

  19. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  20. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  21. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  22. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  23. def readResolve(): AnyRef
    Attributes
    protected
  24. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  25. def toString(): String
    Definition Classes
    Val → AnyRef → Any
  26. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  27. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  28. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from Serializable

Inherited from Ordered[Value]

Inherited from Comparable[Value]

Inherited from AnyRef

Inherited from Any

Ungrouped