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

Commit 22b5154

Browse files
committed
値がABSENT_VALUEならnullを返すよう修正
1 parent c7b7ea2 commit 22b5154

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/main/kotlin/com/mapk/fastkfunction/argumentbucket/ArgumentBucket.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ class ArgumentBucket(
1616

1717
operator fun set(key: KParameter, value: Any?): Any? = set(key.index, value)
1818

19-
operator fun set(index: Int, value: Any?): Any? = valueArray[index].apply {
20-
if (this === ABSENT_VALUE) count++
19+
operator fun set(index: Int, value: Any?): Any? = if (isInitialized(index))
20+
valueArray[index].apply { valueArray[index] = value }
21+
else {
22+
count++
2123
valueArray[index] = value
24+
null // 値がABSENT_VALUEならnullを返す
2225
}
2326

2427
/**
@@ -31,11 +34,12 @@ class ArgumentBucket(
3134
* If the specified key is not already associated with a value associates it with the given value and returns
3235
* {@code null}, else returns the current value.
3336
*/
34-
fun setIfAbsent(index: Int, value: Any?): Any? = valueArray[index].apply {
35-
if (this === ABSENT_VALUE) {
36-
count++
37-
valueArray[index] = value
38-
}
37+
fun setIfAbsent(index: Int, value: Any?): Any? = if (isInitialized(index))
38+
valueArray[index]
39+
else {
40+
count++
41+
valueArray[index] = value
42+
null // 値がABSENT_VALUEならnullを返す
3943
}
4044

4145
private fun isInitialized(index: Int): Boolean = valueArray[index] !== ABSENT_VALUE

0 commit comments

Comments
 (0)