add TypeAdapter

This commit is contained in:
tursom 2020-08-11 00:55:57 +08:00
parent 1314480e1b
commit e3c117f126

View File

@ -12,7 +12,6 @@ import kotlin.reflect.full.isSubclassOf
object TypeAdapterFactory { object TypeAdapterFactory {
private val adapterMap = ConcurrentSkipListMap<Int, ConcurrentLinkedQueue<TypeAdapter<*>>>() private val adapterMap = ConcurrentSkipListMap<Int, ConcurrentLinkedQueue<TypeAdapter<*>>>()
private val adapterQueue = ConcurrentLinkedQueue<TypeAdapter<*>>()
init { init {
scanPackage("cn.tursom.database.typeadapter") scanPackage("cn.tursom.database.typeadapter")
@ -29,8 +28,11 @@ object TypeAdapterFactory {
return queue!! return queue!!
} }
fun scanPackage(pkg: String) { fun scanPackage(
getClassByPackage(pkg).forEach { pkg: String,
classLoader: ClassLoader = this.javaClass.classLoader
) {
classLoader.getClassByPackage(pkg).forEach {
try { try {
val clazz = Class.forName(it).kotlin val clazz = Class.forName(it).kotlin
if (clazz.isSubclassOf(TypeAdapter::class)) { if (clazz.isSubclassOf(TypeAdapter::class)) {