Packages

package util

Source
package.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. util
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. 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

  2. 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
    Examples:
    1. 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:

    2. ,
    3. 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:

    4. ,
    5. 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)
        }
      }
  3. sealed trait Key extends AnyRef
  4. trait Logging extends LazyLogging
  5. trait MockConfig extends Mocking
  6. 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

  7. 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

  1. 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

    Example:
    1. val result = defaultsTo("") {
        "abc".substring(4)
      }
  2. object Config
  3. object Key
  4. object NoCache
  5. object SimpleCache

Inherited from AnyRef

Inherited from Any

Ungrouped