Upgrade to nucleus 3

This commit is contained in:
len
2016-04-22 13:50:51 +02:00
parent 50ae08ed8d
commit 9f0da3f1d6
13 changed files with 66 additions and 75 deletions

View File

@@ -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
}