scala

class Enumeration

[source: scala/Enumeration.scala]

@serializable

@SerialVersionUID(8476000850333817230L)

abstract class Enumeration(initial : Int, names : java.lang.String*)
extends AnyRef

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 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 filter isWorkingDay foreach println
  }
Parameters
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.
Author
Matthias Zenger
Version
1.0, 10/02/2004
Direct Known Subclasses:
BigDecimal.RoundingMode, Alignment, BorderPanel.Position, Dialog.Message, Dialog.Options, Dialog.Result, FileChooser.Result, FileChooser.SelectionMode, FlowPanel.Alignment, FormattedTextField.FocusLostBehavior, GridBagPanel.Fill, GridBagPanel.Anchor, Key, ListView.IntervalMode, Orientation, TabbedPane.Layout, Table.AutoResizeMode, Table.IntervalMode, Table.ElementMode

Additional Constructor Summary
def this (names : java.lang.String*) : Enumeration
def this : 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
def Set32 (underlying : Int) : Set32
create a bit enumeration set according ot underlying
def Set32 : Set32
create an empty 32 bit enumeration set
def Set64 (underlying : Long) : Set64
create a bit enumeration set according ot underlying
def Set64 : Set64
create an empty 64 bit enumeration set
protected final def Value (i : Int) : Value
Creates a fresh value, part of this enumeration, identified by the integer i.
protected final def Value : Value
Creates a fresh value, part of this enumeration.
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 (name : java.lang.String) : Value
Creates a fresh value, part of this enumeration, called name.
final def apply (x : Int) : Value
The value in this enumeration identified by integer x.
final def elements : Iterator[Value]
A new iterator over all values of this enumeration.
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.
def map [B](f : (Value) => B) : Iterator[B]
Returns an iterator resulting from applying the given function f to each value of this enumeration.
def maskToBit (n : Long) : Int
used to reverse engineer bit locations from pre-defined bit masks
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
Returns a string representation of the object.
def valueOf (s : java.lang.String) : Option[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
class Set32 (val underlying : Int) extends SetXX
An enumeration bit set that can handle enumeration values with ids up to 31 in an Int.
class Set64 (val underlying : Long) extends SetXX
An enumeration bit set that can handle enumeration values with ids up to 63 in a Long.
abstract class SetXX extends Set[Value]
A set that efficiently stores enumeration values as bits.
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.
Additional Constructor Details
def this : Enumeration

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

Value Details
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 Details
def name : java.lang.String
The name of this enumeration.

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

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

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

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

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 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 map[B](f : (Value) => B) : Iterator[B]
Returns an iterator resulting from applying the given function f to each value of this enumeration.

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 filter(p : (Value) => Boolean) : Iterator[Value]
Returns all values of this enumeration that satisfy the predicate p. The order of values is preserved.

override def toString : java.lang.String
Returns a string representation of the object.

The default representation is platform dependent.

Returns
a string representation of the object.


def valueOf(s : java.lang.String) : Option[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.
Parameters
s - an enumeration name
Returns
Some(Value) if an enumeration's name matches s, else None

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

protected final def Value(i : Int) : 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.
Returns
..

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

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.
Parameters
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.
Returns
..

def Set32 : Set32
create an empty 32 bit enumeration set

def Set32(underlying : Int) : Set32
create a bit enumeration set according ot underlying

def Set64 : Set64
create an empty 64 bit enumeration set

def Set64(underlying : Long) : Set64
create a bit enumeration set according ot underlying

def maskToBit(n : Long) : Int
used to reverse engineer bit locations from pre-defined bit masks