Scala Library
|
|
scala/Enumeration.scala
]
abstract
class
Enumeration(initial : Int, names : java.lang.String*)
extends
AnyRefDefines 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 WeekDay extends Enumeration { type WeekDay = Value val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value } import WeekDay._ def isWorkingDay(d: WeekDay) = ! (d == Sat || d == Sun) WeekDay.iterator filter isWorkingDay foreach println }
initial -
The initial value from which to count the integers that identifies values at run-time.names -
The sequence of names to give to this enumeration's values.Additional Constructor Summary | |
def
|
this : Enumeration |
def
|
this (names : java.lang.String*) : Enumeration |
Value Summary | |
protected var
|
nextId
: Int
The integer to use to identify the next created value.
|
protected var
|
nextName
: Iterator[java.lang.String]
The string to use to name the next created value.
|
Method Summary | |
protected final def
|
Value
: Value
Creates a fresh value, part of this enumeration.
|
protected final def
|
Value
(name : java.lang.String) : Value
Creates a fresh value, part of this enumeration, called
name . |
protected final def
|
Value
(i : Int, name : java.lang.String) : Value
Creates a fresh value, part of this enumeration, called
name
and identified by the integer i . |
protected final def
|
Value
(i : Int) : Value
Creates a fresh value, part of this enumeration, identified by the integer
i . |
final def
|
apply
(x : Int) : Value
The value of this enumeration with given id `x`
|
def
|
exists
(p : (Value) => Boolean) : 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 : (Value) => Boolean) : Iterator[Value]
Returns all values of this enumeration that satisfy the predicate p.
The order of values is preserved.
|
def
|
flatMap
[B](f : (Value) => Iterator[B]) : Iterator[B]
Applies the given function f to each value of this enumeration, then
concatenates the results.
|
def
|
forall
(p : (Value) => Boolean) : 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 : (Value) => Unit) : Unit
Apply a function f to all values of this enumeration.
|
final def
|
iterator
: Iterator[Value]
A new iterator over all values of this enumeration.
|
def
|
map
[B](f : (Value) => B) : Iterator[B]
Returns an iterator resulting from applying the given function f to each
value of this enumeration.
|
final def
|
maxId
: 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
The name of this enumeration.
|
def
|
valueOf (s : java.lang.String) : Option[Value] |
def
|
values
: ValueSet
The values of this enumeration as a set.
|
def
|
withName
(s : java.lang.String) : Value
Returns a Value from this Enumeration whose name matches
the argument s.
You must pass a String* set of names to the constructor,
or initialize each Enumeration with Value(String),
for valueOf to work.
|
Methods inherited from AnyRef | |
getClass, hashCode, equals, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized |
Methods inherited from Any | |
==, !=, isInstanceOf, asInstanceOf |
Class Summary | |
protected class
|
Val
(i : Int, name : java.lang.String) extends Value
A class implementing the
Value type. This class can be
overriden to change the enumeration's naming and integer identification
behaviour. |
abstract class
|
Value
extends Ordered[Value]
The type of the enumerated values.
|
class
|
ValueSet
(val ids : BitSet) extends Set[Value] with SetTemplate[Value, ValueSet]
A class for sets of values
Iterating through this set will yield values in increasing order of their ids.
|
Object Summary | |
object
|
ValueSet
extends AnyRef
A factory object for value sets
|
Additional Constructor Details |
Value Details |
protected
var
nextId : Int
protected
var
nextName : Iterator[java.lang.String]
Method Details |
override
def
toString : java.lang.String
def
values : ValueSet
final
def
maxId : Int
def
withName(s : java.lang.String) : Value
s -
an enumeration nameprotected final
def
Value : Value
i
.i -
An integer that identifies this value at run-time. It must be unique amongst all values of the enumeration.protected final
def
Value(name : java.lang.String) : Value
name
.name -
A human-readable name for that value.protected final
def
Value(i : Int, name : java.lang.String) : Value
name
and identified by the integer i
.i -
An integer that identifies this value at run-time. It must be unique amongst all values of the enumeration.name -
A human-readable name for that value.
def
name : java.lang.String
def
valueOf(s : java.lang.String) : Option[Value]
final
def
iterator : Iterator[Value]
def
foreach(f : (Value) => Unit) : Unit
def
forall(p : (Value) => Boolean) : Boolean
def
exists(p : (Value) => Boolean) : Boolean
def
map[B](f : (Value) => B) : Iterator[B]
def
filter(p : (Value) => Boolean) : Iterator[Value]
Scala Library
|
|