-
Notifications
You must be signed in to change notification settings - Fork 0
Home
hunterpayne edited this page Jan 15, 2019
·
4 revisions
This library provides typesafe and extensible properties for Scala projects. Encourages strong typing and provides jars providing support for various valid types of properties.
Currently, a default set of types: Int, Long, Float, Double, String, Boolean, Date, and Enumeration are supported by the core jar. The eprop-squants jar adds additional type support for the squants types: Mass, Energy, Density, etc. The eprop-joda jar adds additional type support for the joda types: DateTime, Instant, MutableDateTime, Seconds, Minutes, Hours, Days, Weeks, Months, and Years.
object ColorPType extends EKeyType[String]('color)
object LengthPType extends EKeyType[Double]('length)
object WidthPType extends EKeyType[Double]('width)
// declare your extensible model type
class Container(props: EProperty[_]*) extends Extensible {
merge(Seq("blue" as ColorPType)) // a default
merge(props)
def color: Option[String] = get[String](ColorPType)
def length: Option[Double] = get[Double](LengthPType)
def width: Option[Double] = get[Double](WidthPType)
}
// now make an instance of your container with some values
val container = new Container(
"red" as ColorPType, 20.0 as LengthPType, 23.3 as WidthPType)
assert(container.color == Some("red"))
assert(container.length == Some(20.0))
assert(container.width == Some(23.3))