io.elderscrollslegends.CardCache.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elderscrolls-legends-sdk-java Show documentation
Show all versions of elderscrolls-legends-sdk-java Show documentation
A java wrapper around the Elder Scrolls: Legends API of https://elderscrollslegends.io
package io.elderscrollslegends
class CardCache {
companion object {
private val cache = mutableMapOf()
@JvmStatic
fun load() {
cache.clear()
Card.all().forEach { card ->
cache[card.id] = card
}
}
@JvmStatic
fun findById(id: String): Card? {
return if (!hasCard(id)) {
val card = Card.find(id)
if (card != null) {
cache[id] = card
}
card
} else {
cache[id]
}
}
@JvmStatic
fun findByCode(code: String): Card? {
val id = Decoder.codeToIdMap[code] ?: return null
return findById(id)
}
fun hasCard(id: String): Boolean = cache.containsKey(id)
}
}