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

commonMain.implementations.persistentOrderedMap.PersistentOrderedMapBuilderContentViews.kt Maven / Gradle / Ivy

There is a newer version: 0.3.8
Show newest version
/*
 * 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.implementations.immutableMap.AbstractMapBuilderEntries
import kotlinx.collections.immutable.internal.MapImplementation

internal class PersistentOrderedMapBuilderEntries(private val builder: PersistentOrderedMapBuilder)
    : AbstractMapBuilderEntries, K, V>() {
    override fun add(element: MutableMap.MutableEntry): Boolean {
        throw UnsupportedOperationException()
    }

    override fun clear() {
        builder.clear()
    }

    override fun iterator(): MutableIterator> {
        return PersistentOrderedMapBuilderEntriesIterator(builder)
    }

    override fun removeEntry(element: Map.Entry): Boolean {
        return builder.remove(element.key, element.value)
    }

    override val size: Int
        get() = builder.size

    override fun containsEntry(element: Map.Entry): Boolean {
        return MapImplementation.containsEntry(builder, element)
    }
}

internal class PersistentOrderedMapBuilderKeys(private val builder: PersistentOrderedMapBuilder) : MutableSet, AbstractMutableSet() {
    override fun add(element: K): Boolean {
        throw UnsupportedOperationException()
    }

    override fun clear() {
        builder.clear()
    }

    override fun iterator(): MutableIterator {
        return PersistentOrderedMapBuilderKeysIterator(builder)
    }

    override fun remove(element: K): Boolean {
        if (builder.containsKey(element)) {
            builder.remove(element)
            return true
        }
        return false
    }

    override val size: Int
        get() = builder.size

    override fun contains(element: K): Boolean {
        return builder.containsKey(element)
    }
}

internal class PersistentOrderedMapBuilderValues(private val builder: PersistentOrderedMapBuilder) : MutableCollection, AbstractMutableCollection() {
    override val size: Int
        get() = builder.size

    override fun contains(element: V): Boolean {
        return builder.containsValue(element)
    }

    override fun add(element: V): Boolean {
        throw UnsupportedOperationException()
    }

    override fun clear() {
        builder.clear()
    }

    override fun iterator(): MutableIterator {
        return PersistentOrderedMapBuilderValuesIterator(builder)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy