package util
- Source
- package.scala
- Alphabetic
- By Inheritance
- util
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
trait
Cache[A, B] extends AnyRef
Simple facade interface to abstract over cache implementation.
Simple facade interface to abstract over cache implementation.
- A
the type of the keys used to store and retrieve values
- B
the type of the values stored in this cache
-
abstract
class
Config extends AnyRef
Type class based wrapper for Typesafe Config.
Type class based wrapper for Typesafe Config.
Supported types:
- Natively by Typesafe Config:
Boolean
Double
Int
Long
String
java.time.Duration
- Mapped (usually from strings converted using a factory method from the respective class):
scala.concurrent.duration.FiniteDuration
scala.math.BigDecimal
scala.math.BigInt
java.time.LocalDate
java.time.LocalDateTime
java.time.LocalTime
java.time.MonthDay
java.time.OffsetDateTime
java.time.Period
java.time.Year
java.time.YearMonth
java.time.ZonedDateTime
java.time.ZoneId
java.util.Locale
java.util.UUID
import scail.commons.util.Config import scail.commons.util.Config.ConfigOps import com.typesafe.config.{Config => TypesafeConfig} class MyConfig(underlying: TypesafeConfig) extends Config(underlying) { object Db extends Config('db) { // Throws an exception at construction time if the setting is missing, as recommended by // https://github.com/typesafehub/config#schemas-and-validation val url: String = 'url.required // equivalent to config.getString("db.url") } val a = 'a.required[Boolean] val b: Double = 'b.required val c = 'c.optional[Duration] // c: Option[Duration] val d: Option[Int] = 'd.optional val e = 'e orElse 42L // e: Long val f = 'f.orBlank // f: String val g = 'g.orFalse // g: Boolean val h = 'h.orTrue // h: Boolean val i = 'i.orZero // i: Int val r = 'r.required[Seq[FiniteDuration]] val s: Seq[BigDecimal] = 's.required val t = 't.optional[Seq[LocalDateTime]] // t: Option[Seq[LocalDateTime]] val u: Option[Seq[Year]] = 'u.optional val v = 'v.orEmpty[Locale] // v: Seq[Locale] val w: Seq[UUID] = 'w.orEmpty val x: String = Symbol("a.very-complicated:key_name!").required }
Custom
Reader
s are easily created by mapping on existing readers: , import scail.commons.util.Config.Reader case class Age(age: Int) case class Name(name: String) implicit val ageReader = Reader.int.map(Age.apply) implicit val nameReader = Reader.string.map(Name.apply) val myName: Name = 'myName.required val myAge = 'myAge.optional[Age] val friendNames: Seq[Name] = 'friendNames.orEmpty
Creating a custom
Reader
for composite data types is also straightforward: , case class Person(name: Name, age: Age, friends: Seq[Person]) object Person { implicit val personReader = Reader { implicit config => Person('name.required, 'age.required, 'friends.required) } }
Examples: - Natively by Typesafe Config:
- sealed trait Key extends AnyRef
- trait Logging extends LazyLogging
- trait MockConfig extends Mocking
-
class
NoCache[A, B] extends Cache[A, B]
A non-caching
Cache
implementation:op
is always evaluated and returned.A non-caching
Cache
implementation:op
is always evaluated and returned.- A
the type of the keys used to store and retrieve values
- B
the type of the values stored in this cache
-
class
SimpleCache[A, B] extends Cache[A, B]
A simple, thread-safe
Cache
implementation based on trie maps.A simple, thread-safe
Cache
implementation based on trie maps. Operations are atomic and allow concurrent access. Once in the cache, values do not expire and are never released, making this implementation not recommended when memory efficiency is of concern.- A
the type of the keys used to store and retrieve values
- B
the type of the values stored in this cache
Value Members
-
def
defaultsTo[A](default: ⇒ A)(exp: ⇒ A): A
Exception handler that returns a default value if a non-fatal exception is thrown.
Exception handler that returns a default value if a non-fatal exception is thrown.
- A
the type of the default return value
- default
the default value to return when a non-fatal exception is caught
- exp
the expression to be evaluated
- returns
the evaluation of
exp
if no exception is thrown,default
if a non-fatal exception was thrown
val result = defaultsTo("") { "abc".substring(4) }
Example: - object Config
- object Key
- object NoCache
- object SimpleCache