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:
BooleanDoubleIntLongStringjava.time.Duration
 - Mapped (usually from strings converted using a factory method from the respective class):
scala.concurrent.duration.FiniteDurationscala.math.BigDecimalscala.math.BigIntjava.time.LocalDatejava.time.LocalDateTimejava.time.LocalTimejava.time.MonthDayjava.time.OffsetDateTimejava.time.Periodjava.time.Yearjava.time.YearMonthjava.time.ZonedDateTimejava.time.ZoneIdjava.util.Localejava.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
Readers 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
Readerfor 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
Cacheimplementation:opis always evaluated and returned.A non-caching
Cacheimplementation:opis 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
Cacheimplementation based on trie maps.A simple, thread-safe
Cacheimplementation 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
expif no exception is thrown,defaultif a non-fatal exception was thrown
val result = defaultsTo("") { "abc".substring(4) }
Example: -  object Config
 -  object Key
 -  object NoCache
 -  object SimpleCache