com.paypal.cascade.common

enumeration

package enumeration

Contains a fully type-safe enumeration framework. Takes more setup & code than the built-in scala.Enumeration, but has two distinct advantages:

1. Configurable outcomes when a conversion from a String to Enumeration value fails 2. Non-exhaustive match warnings when one or more Enumeration values are not included in a match

By comparison, scala.Enumeration will allow a match over as few as one Enumeration type, which runs the risk of a scala.MatchError. This will alert at compile time as to the possibility of a match miss.

As of Jackson 2.x, a method exists to directly serialize scala.Enumeration, which involves writing less up-front boilerplate. One distinct downside, however, is the need for a special Jackson annotation on case classes that use Enumerations in this way. The annotation must be applied directly to each case class member that is an Enumeration. In this way, serializing scala.Enumeration in Jackson involves substantially more boilerplate effort than the custom Enumeration presented here. See https://github.com/FasterXML/jackson-module-scala/wiki/Enumeration for more information.

For these reasons, our custom Enumeration type should be preferred instead of scala.Enumeration or java.util.Enumeration. See the examples subproject for a sample implementation.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. enumeration
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. trait EnumReader[T] extends AnyRef

    Base trait for reading Strings into our com.paypal.cascade.common.enumeration.Enumeration.

  2. trait EnumUnapply[T <: Enumeration] extends AnyRef

    Allows pattern matching on String values that correspond to com.paypal.cascade.common.enumeration.Enumeration subtypes.

    Allows pattern matching on String values that correspond to com.paypal.cascade.common.enumeration.Enumeration subtypes. Note that the type returned by the extractor is the general sealed trait T, not an Enumeration instance.

    scala> "SOMETYPE" match { case AnEnumeration(a) => a; case _ => throw new Exception("fail!") }
    res0: com.project.AnEnumeration = SOMETYPE
    scala> "OTHERTYPE" match { case AnEnumeration(a) => a; case _ => throw new Exception("fail!") }
    res1: com.project.AnEnumeration = OTHERTYPE
    scala> "not a type" match { case AnEnumeration(a) => a; case _ => throw new Exception("fail!") }
    java.lang.Exception: fail!
  3. trait Enumeration extends Serializable

    Our custom Enumeration type.

  4. class EnumerationException extends Exception

    Exception type for failed String-to-Enumeration reading

  5. implicit class RichStringEnumReader extends AnyRef

    Implicit wrapper for Strings to perform Enumeration reading, using an implicit com.paypal.cascade.common.enumeration.EnumReader

Value Members

  1. def enumReader[T <: Enumeration](reader: (String) ⇒ Option[T]): EnumReader[T]

    Creates an com.paypal.cascade.common.enumeration.EnumReader

    T

    the Enumeration type

    reader

    the method to convert a String to an Enumeration

    returns

    an EnumReader that knows how to read a String to an Enumeration

  2. def lowerEnumReader[T <: Enumeration](values: T*): EnumReader[T]

    Creates an com.paypal.cascade.common.enumeration.EnumReader that converts a String to an Enumeration if the lowercase version of that String matches the lowercase of the Enumeration's stringVal

    Creates an com.paypal.cascade.common.enumeration.EnumReader that converts a String to an Enumeration if the lowercase version of that String matches the lowercase of the Enumeration's stringVal

    T

    the Enumeration type

    values

    the Enumeration values that are candidates to convert

    returns

    an EnumReader that has the aforementioned properties

  3. def upperEnumReader[T <: Enumeration](values: T*): EnumReader[T]

    Creates an com.paypal.cascade.common.enumeration.EnumReader that converts a String to an Enumeration if the uppercase version of that String matches the uppercase of the Enumeration's stringVal

    Creates an com.paypal.cascade.common.enumeration.EnumReader that converts a String to an Enumeration if the uppercase version of that String matches the uppercase of the Enumeration's stringVal

    T

    the Enumeration type

    values

    the Enumeration values that are candidates to convert

    returns

    an EnumReader that has the aforementioned properties

Inherited from AnyRef

Inherited from Any

Ungrouped