diff options
author | Paul Phillips <paulp@improving.org> | 2011-12-07 10:49:31 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-12-07 12:26:51 -0800 |
commit | 8677057f1462f5bc1c9f94ef11e45d9b4a57f7ab (patch) | |
tree | 72595ddfeb577cec6c74128f35cdd2d6abed6cc6 /src/library | |
parent | 21773d31c1e15d2eec3cf2c8623d582be0a8e4ca (diff) | |
download | scala-8677057f1462f5bc1c9f94ef11e45d9b4a57f7ab.tar.gz scala-8677057f1462f5bc1c9f94ef11e45d9b4a57f7ab.tar.bz2 scala-8677057f1462f5bc1c9f94ef11e45d9b4a57f7ab.zip |
Restructed Enumeration a little.
Nobody should be deprecating methods without ensuring that the
implementation doesn't rely on their existence (and the documentation
doesn't still suggest using them.) Made it more internally consistent.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/Enumeration.scala | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/src/library/scala/Enumeration.scala b/src/library/scala/Enumeration.scala index c967a48abc..3d85f2f52f 100644 --- a/src/library/scala/Enumeration.scala +++ b/src/library/scala/Enumeration.scala @@ -48,19 +48,20 @@ import java.util.regex.Pattern * * @param initial The initial value from which to count the integers that * identifies values at run-time. - * @param names The sequence of names to give to this enumeration's values. - * * @author Matthias Zenger */ @SerialVersionUID(8476000850333817230L) -abstract class Enumeration(initial: Int, - @deprecated("Names should be specified individually or discovered via reflection", "2.10") - names: String*) extends Serializable { +abstract class Enumeration (initial: Int) extends Serializable { thisenum => def this() = this(0) - - @deprecated("Names should be specified individually or discovered via reflection", "2.10") + + @deprecated("Names should be specified individually or discovered via reflection", "2.10.0") + def this(initial: Int, names: String*) = { + this(initial) + this.nextName = names.iterator + } + @deprecated("Names should be specified individually or discovered via reflection", "2.10.0") def this(names: String*) = this(0, names: _*) /* Note that `readResolve` cannot be private, since otherwise @@ -97,12 +98,13 @@ abstract class Enumeration(initial: Int, } /** The integer to use to identify the next created value. */ - protected var nextId = initial + protected var nextId: Int = initial /** The string to use to name the next created value. */ - protected var nextName = names.iterator + protected var nextName: Iterator[String] = _ + private def nextNameOrNull = - if (nextName.hasNext) nextName.next else null + if (nextName != null && nextName.hasNext) nextName.next else null /** The highest integer amongst those used to identify values in this * enumeration. */ @@ -120,17 +122,8 @@ abstract class Enumeration(initial: Int, */ final def apply(x: Int): Value = vmap(x) - /** - * Return a `Value` from this `Enumeration` whose name matches - * the argument `s`. - * - * You can pass a String* set of names to the constructor, or initialize - * each `Enumeration` with `Value(String)`. Otherwise, the names are - * determined automatically through reflection. - * - * Note the change here wrt 2.7 is intentional. You should know whether - * a name is in an `Enumeration` beforehand. If not, just use find on - * values. + /** Return a `Value` from this `Enumeration` whose name matches + * the argument `s`. The names are determined automatically via reflection. * * @param s an `Enumeration` name * @return the `Value` of this `Enumeration` if its name matches `s` |