in scala
class Enumeration

abstract class Enumeration
extends java.lang.Object
with scala.ScalaObject

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 Value type member of the enumeration (Value selected on the stable identifier path of the enumeration instance).

Example use

  object Main extends Application {
 
    object WeekDays extends Enumeration  {
      val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value
    }
 
    def isWorkingDay(d: WeekDays.Value) =
      ! (d == WeekDays.Sat || d == WeekDays.Sun)
  
    WeekDays filter (isWorkingDay) foreach { d => Console.println(d) }
  }
Author:
Matthias Zenger
Version:
1.0, 10/02/04

Class Summary
protected class Val
A class implementing the Value type. This class can be overriden to change the enumeration's naming and integer identification behaviour.
abstract class Value
The type of the enumerated values.
Constructor Summary
def this

def this (initial: scala.Int, names: java.lang.String*)

def this (names: java.lang.String*)

Var Summary
protected var nextId : scala.Int
The integer to use to identify the next created value.
protected var nextName : scala.Iterator[java.lang.String]
The string to use to name the next created value.
Def Summary
final protected def Value (i: scala.Int) : Enumeration.this.Value
Creates a fresh value, part of this enumeration, identified by the integer i.
final protected def Value (i: scala.Int, name: java.lang.String) : Enumeration.this.Value
Creates a fresh value, part of this enumeration, called name and identified by the integer i.
final protected def Value (name: java.lang.String) : Enumeration.this.Value
Creates a fresh value, part of this enumeration, called name.
final protected def Value : Enumeration.this.Value
Creates a fresh value, part of this enumeration.
final def apply (x: scala.Int) : Enumeration.this.Value
The value in this enumeration identified by integer x.
final def elements : scala.Iterator[Enumeration.this.Value]
A new iterator over all values of this enumeration.
def exists (p: (Enumeration.this.Value) => scala.Boolean) : scala.Boolean
Apply a predicate p to all values of this enumeration and return true, iff there is at least one value for which p yields true.
def filter (p: (Enumeration.this.Value) => scala.Boolean) : scala.Iterator[Enumeration.this.Value]
Returns all values of this enumeration that satisfy the predicate p. The order of values is preserved.
def flatMap [b] (f: (Enumeration.this.Value) => scala.Iterator[b]) : scala.Iterator[b]
Applies the given function f to each value of this enumeration, then concatenates the results.
def forall (p: (Enumeration.this.Value) => scala.Boolean) : scala.Boolean
Apply a predicate p to all values of this enumeration and return true, iff the predicate yields true for all values.
def foreach (f: (Enumeration.this.Value) => scala.Unit) : scala.Unit
Apply a function f to all values of this enumeration.
def map [b] (f: (Enumeration.this.Value) => b) : scala.Iterator[b]
Returns an iterator resulting from applying the given function f to each value of this enumeration.
final def maxId : scala.Int
The highest integer amongst those used to identify values in this enumeration.
def name : java.lang.String
The name of this enumeration.
override def toString : java.lang.String

Constructor Detail
def this

def this (initial: scala.Int, names: java.lang.String*)
Parameters:
initial - The initial value from which to count the integers that identifies values at run-time.
Parameters:
names - The sequence of names to give to this enumeration's values.

def this (names: java.lang.String*)

Var Detail
protected var nextId : scala.Int
The integer to use to identify the next created value.

protected var nextName : scala.Iterator[java.lang.String]
The string to use to name the next created value.

Def Detail
final protected def Value (i: scala.Int): Enumeration.this.Value
Creates a fresh value, part of this enumeration, identified by the integer i.
Parameters:
i - An integer that identifies this value at run-time. It must be unique amongst all values of the enumeration.

final protected def Value (i: scala.Int, name: java.lang.String): Enumeration.this.Value
Creates a fresh value, part of this enumeration, called name and identified by the integer i.
Parameters:
i - An integer that identifies this value at run-time. It must be unique amongst all values of the enumeration.
Parameters:
name - A human-readable name for that value.

final protected def Value (name: java.lang.String): Enumeration.this.Value
Creates a fresh value, part of this enumeration, called name.
Parameters:
name - A human-readable name for that value.

final protected def Value : Enumeration.this.Value
Creates a fresh value, part of this enumeration.

final def apply (x: scala.Int): Enumeration.this.Value
The value in this enumeration identified by integer x.

final def elements : scala.Iterator[Enumeration.this.Value]
A new iterator over all values of this enumeration.

def exists (p: (Enumeration.this.Value) => scala.Boolean): scala.Boolean
Apply a predicate p to all values of this enumeration and return true, iff there is at least one value for which p yields true.

def filter (p: (Enumeration.this.Value) => scala.Boolean): scala.Iterator[Enumeration.this.Value]
Returns all values of this enumeration that satisfy the predicate p. The order of values is preserved.

def flatMap [b](f: (Enumeration.this.Value) => scala.Iterator[b]): scala.Iterator[b]
Applies the given function f to each value of this enumeration, then concatenates the results.

def forall (p: (Enumeration.this.Value) => scala.Boolean): scala.Boolean
Apply a predicate p to all values of this enumeration and return true, iff the predicate yields true for all values.

def foreach (f: (Enumeration.this.Value) => scala.Unit): scala.Unit
Apply a function f to all values of this enumeration.

def map [b](f: (Enumeration.this.Value) => b): scala.Iterator[b]
Returns an iterator resulting from applying the given function f to each value of this enumeration.

final def maxId : scala.Int
The highest integer amongst those used to identify values in this enumeration.

def name : java.lang.String
The name of this enumeration.

override def toString : java.lang.String