
jvmMain.io.mockk.impl.instantiation.RefCounterMap.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockk-jvm Show documentation
Show all versions of mockk-jvm Show documentation
Mocking library for Kotlin
The newest version!
package io.mockk.impl.instantiation
import java.util.WeakHashMap
class RefCounterMap {
val counter = WeakHashMap()
fun incrementRefCnt(cls: T) =
synchronized(counter) {
val cnt = counter[cls] ?: 0
counter[cls] = cnt + 1
cnt == 0
}
fun decrementRefCnt(cls: T) =
synchronized(counter) {
val cnt = counter[cls] ?: return true
counter[cls] = cnt - 1
cnt == 1
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy