From 65ba7e2bec96f07beba13fcf1035496a94ca76b3 Mon Sep 17 00:00:00 2001 From: Geoffrey Washburn Date: Tue, 18 Nov 2008 15:41:08 +0000 Subject: Applied patch from #1505, modified supplied exa... Applied patch from #1505, modified supplied example to be a test. --- src/library/scala/Enumeration.scala | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/library') diff --git a/src/library/scala/Enumeration.scala b/src/library/scala/Enumeration.scala index 6d6203e415..283c60beeb 100644 --- a/src/library/scala/Enumeration.scala +++ b/src/library/scala/Enumeration.scala @@ -130,6 +130,21 @@ abstract class Enumeration(initial: Int, names: String*) { override def toString(): String = updateCache.mkString("{", ", ", "}") + /** 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. + * @param s an enumeration name + * @return Some(Value) if an enumeration's name matches s, + * else None + */ + def valueOf(s:String) = { + var v: Option[Value] = None + for( e <- elements ) if (s == e.toString()) v = Some(e) + v + } + /** Creates a fresh value, part of this enumeration. */ protected final def Value: Value = new Val(nextId, if (nextName.hasNext) nextName.next else null) -- cgit v1.2.3