spice.store.Store.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spice-core_3 Show documentation
Show all versions of spice-core_3 Show documentation
Core functionality leveraged and shared by most other sub-projects of YouI.
package spice.store
trait Store {
def get[T](key: String): Option[T]
def update[T](key: String, value: T): Unit
def remove(key: String): Unit
def apply[T](key: String): T = get[T](key).getOrElse(throw new NullPointerException(s"$key not found."))
def getOrElse[T](key: String, default: => T): T = get[T](key).getOrElse(default)
def getOrSet[T](key: String, default: => T): T = synchronized {
get[T](key) match {
case Some(value) => value
case None =>
val value: T = default
update(key, value)
value
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy