package fr.postgresjson.entity import kotlin.reflect.KClass class EntitiesCollections { private val collections: MutableMap, EntityCollection>> = mutableMapOf() fun > get(id: I, className: KClass): R? { val collection = collections[className] val entity = collection?.get(id!!) return entity as R? } inline fun > get(id: I): R? { return get(id, R::class) } fun > set(entity: R): EntitiesCollections { if (collections[entity.className] == null) { collections[entity.className] = EntityCollection() } collections[entity.className]!!.set(entity as EntityI) return this } class EntityCollection> { private var collection: MutableMap = mutableMapOf() fun get(id: T): E? { return collection[id] } fun set(entity: E) { val id = entity.id if (id !== null) { collection[id] = entity } } } }