Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ repositories {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation(kotlin("reflect"))
api("com.github.ProjectMapK:Shared:0.13")
api("com.github.ProjectMapK:Shared:0.14")

// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter
testImplementation(group = "org.junit.jupiter", name = "junit-jupiter", version = "5.6.2") {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/mapk/kmapper/BoundKMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class BoundKMapper<S : Any, D : Any> private constructor(
val adaptor = function.getArgumentAdaptor()

parameters.forEach {
adaptor.putIfAbsent(it.name, it.map(src))
adaptor.forcePut(it.name, it.map(src))
}

return function.call(adaptor)
Expand Down
10 changes: 4 additions & 6 deletions src/main/kotlin/com/mapk/kmapper/KMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class KMapper<T : Any> private constructor(
src.forEach { (key, value) ->
parameterMap[key]?.let { param ->
// 取得した内容がnullでなければ適切にmapする
argumentAdaptor.putIfAbsent(param.name, value?.let { param.mapObject(value) })
argumentAdaptor.putIfAbsent(param.name) { value?.let { param.mapObject(value) } }
// 終了判定
if (argumentAdaptor.isFullInitialized()) return
}
Expand All @@ -86,7 +86,7 @@ class KMapper<T : Any> private constructor(
val key = srcPair.first.toString()

parameterMap[key]?.let {
argumentAdaptor.putIfAbsent(key, srcPair.second?.let { value -> it.mapObject(value) })
argumentAdaptor.putIfAbsent(key) { srcPair.second?.let { value -> it.mapObject(value) } }
}
}

Expand Down Expand Up @@ -128,10 +128,8 @@ class KMapper<T : Any> private constructor(

private class ArgumentBinder(private val param: ParameterForMap<*>, private val javaGetter: Method) {
fun bindArgument(src: Any, adaptor: ArgumentAdaptor) {
// 初期化済みであれば高コストな取得処理は行わない
if (!adaptor.isInitialized(param.name)) {
// javaGetterを呼び出す方が高速
adaptor.putIfAbsent(param.name, javaGetter.invoke(src)?.let { param.mapObject(it) })
adaptor.putIfAbsent(param.name) {
javaGetter.invoke(src)?.let { param.mapObject(it) }
}
}
}
3 changes: 2 additions & 1 deletion src/main/kotlin/com/mapk/kmapper/ParameterForMap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ internal class ParameterForMap<T : Any>(
}
// リストの長さが小さいと期待されるためこの形で実装しているが、理想的にはmap的なものが使いたい
@Suppress("UNCHECKED_CAST")
private val converters: Set<Pair<KClass<*>, KFunction<T>>> =
private val converters: Set<Pair<KClass<*>, KFunction<T>>> by lazy {
(param.getConverters() as Set<Pair<KClass<*>, KFunction<T>>>) + clazz.getConverters()
}

private val convertCache: ConcurrentMap<KClass<*>, ParameterProcessor> = ConcurrentHashMap()

Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/com/mapk/kmapper/PlainKMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PlainKMapper<T : Any> private constructor(
parameterMap[alias!!]?.let {
// javaGetterを呼び出す方が高速
javaGetter.isAccessible = true
argumentAdaptor.putIfAbsent(alias!!, javaGetter.invoke(src)?.let { value -> it.mapObject(value) })
argumentAdaptor.putIfAbsent(alias!!) { javaGetter.invoke(src)?.let { value -> it.mapObject(value) } }
// 終了判定
if (argumentAdaptor.isFullInitialized()) return
}
Expand All @@ -58,7 +58,7 @@ class PlainKMapper<T : Any> private constructor(
src.forEach { (key, value) ->
parameterMap[key]?.let { param ->
// 取得した内容がnullでなければ適切にmapする
argumentAdaptor.putIfAbsent(key as String, value?.let { param.mapObject(value) })
argumentAdaptor.putIfAbsent(key as String) { value?.let { param.mapObject(value) } }
// 終了判定
if (argumentAdaptor.isFullInitialized()) return
}
Expand All @@ -69,7 +69,7 @@ class PlainKMapper<T : Any> private constructor(
val key = srcPair.first.toString()

parameterMap[key]?.let {
argumentBucket.putIfAbsent(key, srcPair.second?.let { value -> it.mapObject(value) })
argumentBucket.putIfAbsent(key) { srcPair.second?.let { value -> it.mapObject(value) } }
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/com/mapk/kmapper/PlainParameterForMap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ internal class PlainParameterForMap<T : Any>(
}
// リストの長さが小さいと期待されるためこの形で実装しているが、理想的にはmap的なものが使いたい
@Suppress("UNCHECKED_CAST")
private val converters: Set<Pair<KClass<*>, KFunction<T>>> =
private val converters: Set<Pair<KClass<*>, KFunction<T>>> by lazy {
(param.getConverters() as Set<Pair<KClass<*>, KFunction<T>>>) + clazz.getConverters()
}

fun <U : Any> mapObject(value: U): Any? {
val valueClazz: KClass<*> = value::class
Expand Down