in scala
class Enumeration
-
abstract class Enumeration(initial: Int, names: String*)
- extends Object
- with ScalaObject
-
The class Enumeration
provides the same functionality as the
enum
construct found in C-like languages like C++ or Java.
Here is an example:
object Main with 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 => System.out.println(d) }
}
- Author:
-
Matthias Zenger
- Version:
-
1.0, 10/02/04
- Parameters:
initial
-
the initial integer value associated with the first element
names
-
the sequence of element names of the enumeration
Methods inherited from java/lang/Object-class
|
clone, eq, equals, finalize, getClass, hashCode, ne, notify, notifyAll, synchronized, wait, wait, wait |
Trait Summary
|
|
trait Value()
|
Class Summary
|
protected
|
class Val(i: Int, name: String)
|
name
def name: String
nextId
protected var nextId: Int
nextName
protected var nextName: Iterator[String]
maxId
final def maxId: Int
apply
final def apply(x: Int): Value
-
Returns the enumeration value for the given id.
elements
final def elements: Iterator[Value]
-
Returns all values of this enumeration.
foreach
def foreach(f: (Value) => Unit): Unit
forall
def forall(p: (Value) => Boolean): Boolean
exists
def exists(p: (Value) => Boolean): Boolean
map
def map[b](f: (Value) => b): Iterator[b]
flatMap
def flatMap[b](f: (Value) => Iterator[b]): Iterator[b]
filter
def filter(p: (Value) => Boolean): Iterator[Value]
toString
override def toString(): String
Value
protected final def Value: Value
Value
protected final def Value(i: Int): Value
Value
protected final def Value(name: String): Value
Value
protected final def Value(i: Int, name: String): Value