diff options
author | Paul Phillips <paulp@improving.org> | 2009-05-12 12:28:55 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-05-12 12:28:55 +0000 |
commit | 99e44f21fef0b75791b7b08387bdcdfc8f6dfb65 (patch) | |
tree | b4efc0ef096ad6f83d294a630d83bcb6a092a03d | |
parent | 11f5744d1f3370d5519e80f4814e273c5d82b5c1 (diff) | |
download | scala-99e44f21fef0b75791b7b08387bdcdfc8f6dfb65.tar.gz scala-99e44f21fef0b75791b7b08387bdcdfc8f6dfb65.tar.bz2 scala-99e44f21fef0b75791b7b08387bdcdfc8f6dfb65.zip |
Reverted probably unintentional change to Enume...
Reverted probably unintentional change to Enumeration (the method
formerly called valueOf and now called withName needs to return
Option[Value], not Value) and updated the failing tests to use the new
Enumeration interface.
-rw-r--r-- | src/library/scala/Enumeration.scala | 4 | ||||
-rw-r--r-- | test/files/run/enums.scala | 6 | ||||
-rw-r--r-- | test/files/run/t1505.scala | 18 |
3 files changed, 14 insertions, 14 deletions
diff --git a/src/library/scala/Enumeration.scala b/src/library/scala/Enumeration.scala index e752fcd523..3dfd9bb740 100644 --- a/src/library/scala/Enumeration.scala +++ b/src/library/scala/Enumeration.scala @@ -113,12 +113,12 @@ abstract class Enumeration(initial: Int, names: String*) { * the argument <var>s</var>. * You must pass a String* set of names to the constructor, * or initialize each Enumeration with Value(String), - * for valueOf to work. + * for withName to work. * @param s an enumeration name * @return <tt>Some(Value)</tt> if an enumeration's name matches <var>s</var>, * else <tt>None</tt> */ - def withName(s: String): Value = values.find(_.toString == s).get + def withName(s: String): Option[Value] = values.find(_.toString == s) /** Creates a fresh value, part of this enumeration. */ protected final def Value: Value = Value(nextId) diff --git a/test/files/run/enums.scala b/test/files/run/enums.scala index 48571ee010..8ccdf138a2 100644 --- a/test/files/run/enums.scala +++ b/test/files/run/enums.scala @@ -13,7 +13,7 @@ object Test1 { ! (d == WeekDays.Sat || d == WeekDays.Sun); def run: Int = { - val it = WeekDays.elements filter (isWorkingDay); + val it = WeekDays.values filter (isWorkingDay); it.toList.length } } @@ -30,7 +30,7 @@ object Test2 { } def run: Int = { - val it = for (val s <- ThreadState.elements; s.id != 0) yield s; + val it = for (val s <- ThreadState.values; s.id != 0) yield s; it.toList.length } } @@ -42,7 +42,7 @@ object Test3 { } def run: Int = { - val it = for (val d <- Direction.elements; d.toString() startsWith "N") yield d; + val it = for (val d <- Direction.values; d.toString() startsWith "N") yield d; it.toList.length } } diff --git a/test/files/run/t1505.scala b/test/files/run/t1505.scala index 25c1a9117b..caadee8a0f 100644 --- a/test/files/run/t1505.scala +++ b/test/files/run/t1505.scala @@ -11,15 +11,15 @@ object R extends Enumeration { } object Test extends Application { - assert(Some(P(0)) == P.valueOf("A")) - assert(Some(P.C) == P.valueOf("C")) - assert(None == P.valueOf("Q")) + assert(Some(P(0)) == P.withName("A")) + assert(Some(P.C) == P.withName("C")) + assert(None == P.withName("Q")) - assert(Some(Q(0)) == Q.valueOf("A")) - assert(Some(Q.C) == Q.valueOf("C")) - assert(None == Q.valueOf("Q")) + assert(Some(Q(0)) == Q.withName("A")) + assert(Some(Q.C) == Q.withName("C")) + assert(None == Q.withName("Q")) - assert(None == R.valueOf("A")) - assert(None == R.valueOf("C")) - assert(None == R.valueOf("Q")) + assert(None == R.withName("A")) + assert(None == R.withName("C")) + assert(None == R.withName("Q")) } |