commonMain.io.mockk.impl.platform.CommonIdentityHashMapOf.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
package io.mockk.impl.platform
import io.mockk.impl.InternalPlatform
import io.mockk.impl.Ref
class CommonIdentityHashMapOf : MutableMap {
val map = linkedMapOf()
override val size: Int
get() = map.size
override fun containsKey(key: K): Boolean = map.containsKey(ref(key))
override fun containsValue(value: V): Boolean = map.containsValue(value)
override fun get(key: K): V? = map[ref(key)]
override fun isEmpty(): Boolean = map.isEmpty()
override val entries: MutableSet>
get() = throw UnsupportedOperationException("entries")
override val keys: MutableSet
get() = throw UnsupportedOperationException("keys")
override val values: MutableCollection
get() = map.values
override fun clear() = map.clear()
override fun put(key: K, value: V): V? = map.put(ref(key), value)
override fun putAll(from: Map): Unit = throw UnsupportedOperationException("putAll")
override fun remove(key: K): V? = map.remove(ref(key))
private fun ref(key: K) = if (key == null) null else InternalPlatform.ref(key)
}