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

commonMain.io.mockk.impl.platform.CommonIdentityHashMapOf.kt Maven / Gradle / Ivy

There is a newer version: 1.13.12
Show newest version
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)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy