refactoring: cleanup and reformat

This commit is contained in:
2019-07-18 18:50:02 +02:00
parent 5949bc5d7b
commit ade162451c
15 changed files with 301 additions and 100 deletions

View File

@@ -5,17 +5,17 @@ import kotlin.reflect.KClass
class EntitiesCollections {
private val collections: MutableMap<KClass<*>, EntityCollection<Any, EntityI<Any?>>> = mutableMapOf()
fun <I, R : EntityI<I?>> get(id: I, className: KClass<R>): R? {
fun <I, R: EntityI<I?>> get(id: I, className: KClass<R>): R? {
val collection = collections[className]
val entity = collection?.get(id!!)
return entity as R?
}
inline fun <I, reified R : EntityI<I?>> get(id: I): R? {
inline fun <I, reified R: EntityI<I?>> get(id: I): R? {
return get(id, R::class)
}
fun <I, R : EntityI<out I?>> set(entity: R): EntitiesCollections {
fun <I, R: EntityI<out I?>> set(entity: R): EntitiesCollections {
if (collections[entity.className] == null) {
collections[entity.className] = EntityCollection()
}
@@ -25,7 +25,7 @@ class EntitiesCollections {
return this
}
class EntityCollection<T, E : EntityI<T?>> {
class EntityCollection<T, E: EntityI<T?>> {
private var collection: MutableMap<T, E> = mutableMapOf()
fun get(id: T): E? {