@@ -10,7 +10,7 @@ import scala.language.postfixOps
1010 * This is yet another one.
1111 *
1212 * Oh yeah, [[Enum ]] is BYOO (bring your own ordinality). Take care of that when
13- * you implement the value method.
13+ * you implement the values method.
1414 *
1515 * How to use:
1616 *
@@ -34,7 +34,7 @@ import scala.language.postfixOps
3434 * }}}
3535 * @tparam A The sealed trait
3636 */
37- trait Enum [A ] {
37+ trait Enum [A <: EnumEntry ] {
3838
3939 /**
4040 * The sequence of values for your [[Enum ]]. You will typically want
@@ -57,12 +57,12 @@ trait Enum[A] {
5757 /**
5858 * Map of [[A ]] object names to [[A ]]s
5959 */
60- lazy final val namesToValuesMap : Map [String , A ] = values map (v => v.toString -> v) toMap
60+ lazy final val namesToValuesMap : Map [String , A ] = values map (v => v.entryName -> v) toMap
6161
6262 /**
6363 * Map of [[A ]] object names in lower case to [[A ]]s for case-insensitive comparison
6464 */
65- lazy final val lowerCaseNamesToValuesMap : Map [String , A ] = values map (v => v.toString .toLowerCase -> v) toMap
65+ lazy final val lowerCaseNamesToValuesMap : Map [String , A ] = values map (v => v.entryName .toLowerCase -> v) toMap
6666
6767 /**
6868 * Optionally returns an [[A ]] for a given name.
@@ -75,11 +75,11 @@ trait Enum[A] {
7575 def withNameInsensitiveOption (name : String ): Option [A ] = lowerCaseNamesToValuesMap get name.toLowerCase
7676
7777 /**
78- * Tries to get an [[A ]] by the supplied name. The name corresponds to the .toString
78+ * Tries to get an [[A ]] by the supplied name. The name corresponds to the .name
7979 * of the case objects implementing [[A ]]
8080 *
8181 * Like [[Enumeration ]]'s `withName`, this method will throw if the name does not match any of the values'
82- * .toString names .
82+ * .entryName values .
8383 */
8484 def withName (name : String ): A =
8585 withNameOption(name) getOrElse (throw new NoSuchElementException (s " $name is not a member of Enum $this" ))
0 commit comments