Add EntityCollection

This commit is contained in:
2019-06-03 11:49:30 +02:00
parent 366d8edab3
commit 65fb032ad9
6 changed files with 69 additions and 11 deletions

View File

@@ -6,7 +6,7 @@ interface EntityI<T> {
var id: T
}
abstract class Entity<T>(override var id: T) : EntityI<T>
abstract class UuidEntity(override var id: UUID = UUID.randomUUID()) : Entity<UUID>(id) {}
abstract class UuidEntity(override var id: UUID = UUID.randomUUID()) : Entity<UUID>(id)
abstract class IdEntity(override var id: Int) : Entity<Int>(id)
interface EntityVersioning<T> {

View File

@@ -0,0 +1,13 @@
package fr.postgresjson.entity
class EntityCollection<T, E : EntityI<T>> {
var collection: MutableMap<T, E> = mutableMapOf()
fun get(id: T): E? {
return collection[id]
}
fun set(entity: E) {
collection.set(entity.id, entity)
}
}