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

commonMain.io.ktor.util.CaseInsensitiveSet.kt Maven / Gradle / Ivy

There is a newer version: 4.0.0
Show newest version
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
package io.ktor.util

@InternalAPI
public class CaseInsensitiveSet() : MutableSet {
    private val backingMap = CaseInsensitiveMap()

    public constructor(initial: Iterable) : this() {
        addAll(initial)
    }

    override fun add(element: String): Boolean {
        if (element in backingMap) {
            return false
        }
        backingMap[element] = true
        return true
    }

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

    override fun remove(element: String): Boolean {
        return backingMap.remove(element) == true
    }

    override fun addAll(elements: Collection): Boolean {
        var added = false
        for (element in elements) {
            if (add(element)) {
                added = true
            }
        }
        return added
    }

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

    override fun removeAll(elements: Collection): Boolean {
        return backingMap.keys.removeAll(elements)
    }

    override fun retainAll(elements: Collection): Boolean {
        return backingMap.keys.retainAll(elements)
    }

    override fun contains(element: String): Boolean {
        return backingMap.contains(element)
    }

    override fun containsAll(elements: Collection): Boolean {
        return backingMap.keys.containsAll(elements)
    }

    override fun isEmpty(): Boolean {
        return backingMap.isEmpty()
    }

    override fun iterator(): MutableIterator = backingMap.keys.iterator()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy