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 evaluation.
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()
- Alphabetic
- By Inheritance
- Enum
- Serializable
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
Type Members
-
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()
-
abstract
type
Value <: Val
The type of the enumerated values.
-
class
ValueSet extends AbstractSet[Value] with SortedSet[Value] with SortedSetLike[Value, 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.
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
apply(x: Int): Value
The value of this enumeration with given id
x
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
maxId: Int
The one higher than the highest integer amongst those used to identify values in this enumeration.
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
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
-
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
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
readResolve(): AnyRef
- Attributes
- protected
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
The name of this enumeration.
The name of this enumeration.
- Definition Classes
- Enum → AnyRef → Any
-
def
values: ValueSet
The values of this enumeration as a set.
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
withName(s: String): Value
Return a
Value
from thisEnum
whose name matches the arguments
.Return a
Value
from thisEnum
whose name matches the arguments
. The names are determined automatically via reflection.- s
an
Enum
name- returns
the
Value
of thisEnum
if its name matchess
- Exceptions thrown
NoSuchElementException
if noValue
with a matching name is in thisEnum
-
implicit
object
ValueOrdering extends Ordering[Value]
An ordering by id for values of this set
-
object
ValueSet extends Serializable
A factory object for value sets