Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.

Commit 79500bc

Browse files
committed
処理の共通化
1 parent 2a92908 commit 79500bc

File tree

1 file changed

+10
-6
lines changed
  • src/main/kotlin/com/wrongwrong/mapk/core

1 file changed

+10
-6
lines changed

src/main/kotlin/com/wrongwrong/mapk/core/KMapper.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,22 @@ class KMapper<T : Any> private constructor(
6363
}
6464
}
6565

66+
private fun bindParameters(targetArray: Array<Any?>, srcPair: Pair<*, *>) {
67+
parameterMap.getValue(srcPair.first.toString()).let {
68+
targetArray[it.index] = srcPair.second?.let { value -> mapObject(it, value) }
69+
}
70+
}
71+
6672
fun map(srcMap: Map<String, Any?>): T {
6773
val array: Array<Any?> = function.argumentArray
6874
srcMap.bindParameters(array)
6975
return function.call(array)
7076
}
7177

72-
fun map(srcPair: Pair<String, Any?>): T = parameterMap.getValue(srcPair.first).let {
78+
fun map(srcPair: Pair<String, Any?>): T {
7379
val array: Array<Any?> = function.argumentArray
74-
array[it.index] = srcPair.second?.let { value -> mapObject(it, value) }
75-
function.call(array)
80+
bindParameters(array, srcPair)
81+
return function.call(array)
7682
}
7783

7884
fun map(src: Any): T {
@@ -87,9 +93,7 @@ class KMapper<T : Any> private constructor(
8793
listOf(*args).forEach { arg ->
8894
when (arg) {
8995
is Map<*, *> -> arg.bindParameters(array)
90-
is Pair<*, *> -> parameterMap.getValue(arg.first as String).let {
91-
array[it.index] = arg.second?.let { value -> mapObject(it, value) }
92-
}
96+
is Pair<*, *> -> bindParameters(array, arg)
9397
else -> arg::class.bindParameters(array, arg)
9498
}
9599
}

0 commit comments

Comments
 (0)