mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-12 20:19:05 +01:00
Upgrade to nucleus 3
This commit is contained in:
@@ -14,7 +14,7 @@ object SharedData {
|
||||
/**
|
||||
* Map where the objects are saved.
|
||||
*/
|
||||
private val map = HashMap<Class<*>, Any>()
|
||||
val map = HashMap<Class<*>, Any>()
|
||||
|
||||
/**
|
||||
* Publish an object to the shared data.
|
||||
@@ -42,4 +42,14 @@ object SharedData {
|
||||
*/
|
||||
fun <T : Any> remove(classType: Class<T>) = get(classType)?.apply { map.remove(classType) }
|
||||
|
||||
/**
|
||||
* Returns an object from the shared data or introduces a new one with the given function.
|
||||
*
|
||||
* @param classType the class of the object to retrieve.
|
||||
* @param fn the function to execute if it didn't find the object.
|
||||
* @return an object of type T.
|
||||
*/
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
inline fun <T : Any> getOrPut(classType: Class<T>, fn: () -> T) = map.getOrPut(classType, fn) as T
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user