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

posixMain.io.ktor.util.AttributesNative.kt Maven / Gradle / Ivy

Go to download

Ktor is a framework for quickly creating web applications in Kotlin with minimal effort.

The newest version!
/*
 * Copyright 2014-2019 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
 */

package io.ktor.util

import io.ktor.util.collections.*

private const val ATTRIBUTES_INITIAL_CAPACITY = 32

/**
 * Create native specific attributes instance.
 */
public actual fun Attributes(concurrent: Boolean): Attributes = AttributesNative()

private class AttributesNative : Attributes {
    private val map = ConcurrentMap, Any>(ATTRIBUTES_INITIAL_CAPACITY)

    @Suppress("UNCHECKED_CAST")
    override fun  getOrNull(key: AttributeKey): T? = map[key] as T?

    override operator fun contains(key: AttributeKey<*>): Boolean = map.containsKey(key)

    override fun  put(key: AttributeKey, value: T) {
        map[key] = value
    }

    override fun  remove(key: AttributeKey) {
        map.remove(key)
    }

    @Suppress("UNCHECKED_CAST")
    override fun  computeIfAbsent(key: AttributeKey, block: () -> T): T {
        return map.computeIfAbsent(key, block) as T
    }

    override val allKeys: List>
        get() = map.keys.toList()
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy