All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.io.mockk.impl.instantiation.RefCounterMap.kt Maven / Gradle / Ivy

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 - 2024 Weber Informatics LLC | Privacy Policy