commonMain.implementations.persistentOrderedMap.PersistentOrderedMapContentViews.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlinx-collections-immutable-jvm Show documentation
Show all versions of kotlinx-collections-immutable-jvm Show documentation
Kotlin Immutable Collections multiplatform library
/*
* Copyright 2016-2019 JetBrains s.r.o.
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
*/
package kotlinx.collections.immutable.implementations.persistentOrderedMap
import kotlinx.collections.immutable.ImmutableCollection
import kotlinx.collections.immutable.ImmutableSet
internal class PersistentOrderedMapEntries(private val map: PersistentOrderedMap) : ImmutableSet>, AbstractSet>() {
override val size: Int get() = map.size
override fun contains(element: Map.Entry): Boolean {
// TODO: Eliminate this check after KT-30016 gets fixed.
if ((element as Any?) !is Map.Entry<*, *>) return false
return map[element.key]?.let { candidate -> candidate == element.value }
?: (element.value == null && map.containsKey(element.key))
}
override fun iterator(): Iterator> {
return PersistentOrderedMapEntriesIterator(map)
}
}
internal class PersistentOrderedMapKeys(private val map: PersistentOrderedMap) : ImmutableSet, AbstractSet() {
override val size: Int
get() = map.size
override fun contains(element: K): Boolean {
return map.containsKey(element)
}
override fun iterator(): Iterator {
return PersistentOrderedMapKeysIterator(map)
}
}
internal class PersistentOrderedMapValues(private val map: PersistentOrderedMap) : ImmutableCollection, AbstractCollection() {
override val size: Int
get() = map.size
override fun contains(element: V): Boolean {
return map.containsValue(element)
}
override fun iterator(): Iterator {
return PersistentOrderedMapValuesIterator(map)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy