trait Enum[A <: EnumEntry] extends AnyRef
All the cool kids have their own Enumeration implementation, most of which try to do so in the name of implementing exhaustive pattern matching.
This is yet another one.
Example:
scala> import enumeratum._ scala> sealed trait DummyEnum extends EnumEntry scala> object DummyEnum extends Enum[DummyEnum] { | val values = findValues | case object Hello extends DummyEnum | case object GoodBye extends DummyEnum | case object Hi extends DummyEnum | } scala> DummyEnum.withNameOption("Hello") res0: Option[DummyEnum] = Some(Hello) scala> DummyEnum.withNameOption("Nope") res1: Option[DummyEnum] = None
- A
The sealed trait
- Alphabetic
- By Inheritance
- Enum
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Abstract Value Members
- abstract def values: IndexedSeq[A]
The sequence of values for your Enum.
The sequence of values for your Enum. You will typically want to implement this in your extending class as a
val
so thatwithName
and friends are as efficient as possible.Feel free to implement this however you'd like (including messing around with ordering, etc) if that fits your needs better.
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def extraNamesToValuesMap: Map[String, A]
Additional list of names which can be mapped to values, for example to allow mapping of legacy values.
Additional list of names which can be mapped to values, for example to allow mapping of legacy values.
- returns
a Map of names to Values
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- macro def findValues: IndexedSeq[A]
Method that returns a Seq of A objects that the macro was able to find.
Method that returns a Seq of A objects that the macro was able to find.
You will want to use this in some way to implement your values method. In fact, if you aren't using this method...why are you even bothering with this lib?
- Attributes
- protected
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def indexOf(member: A): Int
Returns the index number of the member passed in the values picked up by this enum
Returns the index number of the member passed in the values picked up by this enum
- member
the member you want to check the index of
- returns
the index of the first element of values that is equal (as determined by ==) to member, or -1, if none exists.
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final lazy val lowerCaseNamesToValuesMap: Map[String, A]
Map of A object names in lower case to As for case-insensitive comparison
- lazy val namesToValuesMap: Map[String, A]
Map of A object names to As
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final lazy val upperCaseNameValuesToMap: Map[String, A]
Map of A object names in upper case to As for case-insensitive comparison
- final lazy val valuesToIndex: Map[A, Int]
Map of A to their index in the values sequence.
Map of A to their index in the values sequence.
A performance optimisation so that indexOf can be found in constant time.
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- def withName(name: String): A
Tries to get an A by the supplied name.
Tries to get an A by the supplied name. The name corresponds to the .name of the case objects implementing A
Like Enumeration's
withName
, this method will throw if the name does not match any of the values' .entryName values.- Annotations
- @SuppressWarnings()
- def withNameEither(name: String): Either[NoSuchMember[A], A]
Returns an Right[A] for a given name, or a Left[NoSuchMember] if the name does not match any of the values' .entryName values.
- def withNameInsensitive(name: String): A
Tries to get an A by the supplied name.
Tries to get an A by the supplied name. The name corresponds to the .name of the case objects implementing A, disregarding case
Like Enumeration's
withName
, this method will throw if the name does not match any of the values' .entryName values.- Annotations
- @SuppressWarnings()
- def withNameInsensitiveEither(name: String): Either[NoSuchMember[A], A]
Returns an Right[A] for a given name, or a Left[NoSuchMember] if the name does not match any of the values' .entryName values, disregarding case.
- def withNameInsensitiveOption(name: String): Option[A]
Optionally returns an A for a given name, disregarding case
- def withNameLowercaseOnly(name: String): A
Tries to get an A by the supplied name.
Tries to get an A by the supplied name. The name corresponds to the .name of the case objects implementing A transformed to lower case
Like Enumeration's
withName
, this method will throw if the name does not match any of the values' .entryName values.- Annotations
- @SuppressWarnings()
- def withNameLowercaseOnlyEither(name: String): Either[NoSuchMember[A], A]
Returns an Right[A] for a given name, or a Left[NoSuchMember] if the name does not match any of the values' .entryName values, disregarding case.
- def withNameLowercaseOnlyOption(name: String): Option[A]
Optionally returns an A for a given name assuming the value is lower case
- def withNameOption(name: String): Option[A]
Optionally returns an A for a given name.
- def withNameUppercaseOnly(name: String): A
Tries to get an A by the supplied name.
Tries to get an A by the supplied name. The name corresponds to the .name of the case objects implementing A transformed to upper case
Like Enumeration's
withName
, this method will throw if the name does not match any of the values' .entryName values.- Annotations
- @SuppressWarnings()
- def withNameUppercaseOnlyEither(name: String): Either[NoSuchMember[A], A]
Returns an Right[A] for a given name, or a Left[NoSuchMember] if the name does not match any of the values' .entryName values, disregarding case.
- def withNameUppercaseOnlyOption(name: String): Option[A]
Optionally returns an A for a given name assuming the value is upper case