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? {

View File

@@ -12,22 +12,22 @@ interface EntityI<T> {
@JsonIgnore() get() = this::class as KClass<EntityI<T?>>
}
abstract class Entity<T>(override var id: T? = null) : EntityI<T?>
abstract class UuidEntity(override var id: UUID? = UUID.randomUUID()) : Entity<UUID?>(id)
abstract class IdEntity(override var id: Int? = null) : Entity<Int?>(id)
abstract class Entity<T>(override var id: T? = null): EntityI<T?>
abstract class UuidEntity(override var id: UUID? = UUID.randomUUID()): Entity<UUID?>(id)
abstract class IdEntity(override var id: Int? = null): Entity<Int?>(id)
/* Version */
interface EntityVersioning<T> {
var version: T
}
interface EntityVersioningIncrement : EntityVersioning<Int?>
class EntityVersioningIncrementImp() : EntityVersioningIncrement {
interface EntityVersioningIncrement: EntityVersioning<Int?>
class EntityVersioningIncrementImp: EntityVersioningIncrement {
override var version: Int? = null
}
interface EntityVersioningDate : EntityVersioning<DateTime?>
class EntityVersioningDateImp() : EntityVersioningDate {
interface EntityVersioningDate: EntityVersioning<DateTime?>
class EntityVersioningDateImp: EntityVersioningDate {
override var version: DateTime? = null
}
@@ -40,15 +40,15 @@ interface EntityUpdatedAt {
var updatedAt: DateTime?
}
class EntityCreatedAtImp : EntityCreatedAt {
class EntityCreatedAtImp: EntityCreatedAt {
override var createdAt: DateTime? = null
}
class EntityUpdatedAtImp : EntityUpdatedAt {
class EntityUpdatedAtImp: EntityUpdatedAt {
override var updatedAt: DateTime? = null
}
interface User<T> : EntityI<T> {
interface User<T>: EntityI<T> {
fun isValid(): Boolean
}
@@ -61,11 +61,11 @@ interface UpdatedBy<T> {
var updatedBy: User<T>?
}
class EntityCreatedByImp<T> : CreatedBy<T> {
class EntityCreatedByImp<T>: CreatedBy<T> {
override var createdBy: User<T>? = null
}
class EntityUpdatedByImp<T> : UpdatedBy<T> {
class EntityUpdatedByImp<T>: UpdatedBy<T> {
override var updatedBy: User<T>? = null
}
@@ -75,19 +75,19 @@ interface Published<UserT> {
var publishedBy: User<UserT>?
}
class EntityPublishedImp<UserT> : Published<UserT> {
class EntityPublishedImp<UserT>: Published<UserT> {
override var publishedAt: DateTime? = null
override var publishedBy: User<UserT>? = null
}
/* Implementation */
abstract class EntityImp<T, UserT> : Entity<T>(),
abstract class EntityImp<T, UserT>: Entity<T>(),
EntityCreatedAt by EntityCreatedAtImp(),
EntityUpdatedAt by EntityUpdatedAtImp(),
CreatedBy<UserT> by EntityCreatedByImp(),
UpdatedBy<UserT> by EntityUpdatedByImp()
abstract class EntityExtended<T, UserT> :
abstract class EntityExtended<T, UserT>:
EntityImp<T, UserT>(),
EntityVersioningIncrement by EntityVersioningIncrementImp(),
Published<UserT> by EntityPublishedImp()