scala

Enumeration

class Enumeration 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.iterator filter isWorkingDay foreach println }

attributes: abstract
known subclasses: RoundingMode, Key, Location, ElementMode, IntervalMode, AutoResizeMode, Layout, BarPolicy, Result, Options, Message, Orientation, IntervalMode, Anchor, Fill, FocusLostBehavior, Alignment, SelectionMode, Result, Position, Alignment

Inherits

  1. AnyRef
  2. Any

Type Members

  1. class Value extends Ordered[Value]

    The type of the enumerated values

  2. class ValueSet extends Set[Value] with SetLike[Value, ValueSet]

    A class for sets of values Iterating through this set will yield values in increasing order of their ids

Value Members

  1. object ValueSet extends AnyRef

    A factory object for value sets

  2. def equals(arg0: Any): Boolean

    This method is used to compare the receiver object (this) with the argument object (arg0) for equivalence

    This method is used to compare the receiver object (this) with the argument object (arg0) for equivalence.

    The default implementations of this method is an equivalence relation:

    • It is reflexive: for any instance x of type Any, x.equals(x) should return true.
    • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
    • It is transitive: for any instances x, y, and z of type AnyRef if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

    If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is often necessary to override hashCode to ensure that objects that are "equal" (o1.equals(o2) returns true) hash to the same Int (o1.hashCode.equals(o2.hashCode)).

    arg0

    the object to compare against this object for equality.

    returns

    true if the receiver object is equivalent to the argument; false otherwise.

    definition classes: AnyRef ⇐ Any
  3. 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

    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.

  4. def filter(p: (Value) ⇒ Boolean): Iterator[Value]

    Returns all values of this enumeration that satisfy the predicate p

    Returns all values of this enumeration that satisfy the predicate p. The order of values is preserved.

  5. def flatMap[B](f: (Value) ⇒ Iterator[B]): Iterator[B]

    Applies the given function f to each value of this enumeration, then concatenates the results

    Applies the given function f to each value of this enumeration, then concatenates the results.

  6. 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

    Apply a predicate p to all values of this enumeration and return true, iff the predicate yields true for all values.

  7. def foreach(f: (Value) ⇒ Unit): Unit

    Apply a function f to all values of this enumeration

    Apply a function f to all values of this enumeration.

  8. def hashCode(): Int

    Returns a hash code value for the object

    Returns a hash code value for the object.

    The default hashing algorithm is platform dependent.

    Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returns false). A degenerate implementation could always return 0. However, it is required that if two objects are equal (o1.equals(o2) returns true) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals method.

    definition classes: AnyRef ⇐ Any
  9. def map[B](f: (Value) ⇒ B): Iterator[B]

    Returns an iterator resulting from applying the given function f to each value of this enumeration

    Returns an iterator resulting from applying the given function f to each value of this enumeration.

  10. def name: String

    The name of this enumeration

    The name of this enumeration.

  11. def toString(): String

    The name of this enumeration

    The name of this enumeration.

  12. def valueOf(s: String): Option[Value]

  13. def values: ValueSet

    The values of this enumeration as a set

    The values of this enumeration as a set.

Instance constructors

  1. new Enumeration(names: String*)

  2. new Enumeration()

  3. new Enumeration(initial: Int, names: String*)