Files
kotlin-fork/kotlin-native/backend.native/tests/framework/stdlib/stdlib.kt
T
Stanislav Erokhin f624800b84 Move everything under kotlin-native folder
I was forced to manually do update the following files, because otherwise
they would be ignored according .gitignore settings. Probably they
should be deleted from repo.

Interop/.idea/compiler.xml
Interop/.idea/gradle.xml
Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_runtime_1_0_3.xml
Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_0_3.xml
Interop/.idea/modules.xml
Interop/.idea/modules/Indexer/Indexer.iml
Interop/.idea/modules/Runtime/Runtime.iml
Interop/.idea/modules/StubGenerator/StubGenerator.iml
backend.native/backend.native.iml
backend.native/bc.frontend/bc.frontend.iml
backend.native/cli.bc/cli.bc.iml
backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt
backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt
backend.native/tests/link/lib/foo.kt
backend.native/tests/link/lib/foo2.kt
backend.native/tests/teamcity-test.property
2020-10-27 21:00:28 +03:00

64 lines
2.0 KiB
Kotlin

/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
@file:Suppress("UNUSED")
package stdlib
fun <K, V> isEmpty(map: Map<K, V>) = map.isEmpty()
fun <K, V> getKeysAsSet(map: Map<K, V>) = map.keys
fun <K, V> getKeysAsList(map: Map<K, V>) = map.keys.toList()
fun <K, V> toMutableMap(map: HashMap<K, V>) = map.toMutableMap()
fun <E> getFirstElement(collection: Collection<E>) = collection.first()
class GenericExtensionClass<K, out V, out T : Map<K, V>> (private val holder: T?) {
fun getFirstKey(): K? = holder?.entries?.first()?.key
fun getFirstValue() : V? {
holder?.entries?.forEach { e -> println("KEY: ${e.key} VALUE: ${e.value}") }
return holder?.entries?.first()?.value
}
}
fun <K, V> createPair():
Pair<LinkedHashMap<K, V>, GenericExtensionClass<K, V, Map<K, V>>> {
val l = createLinkedMap<K, V>()
val g = GenericExtensionClass(l)
return Pair(l, g)
}
fun <K, V> createLinkedMap() = linkedMapOf<K, V>()
fun createTypedMutableMap() = linkedMapOf<Int, String>()
fun addSomeElementsToMap(map: MutableMap<String, Int>) {
map.put(key = "XYZ", value = 321)
map.put(key = "TMP", value = 451)
}
fun list(vararg elements: Any?): Any = listOf(*elements)
fun set(vararg elements: Any?): Any = setOf(*elements)
fun map(vararg keysAndValues: Any?): Any = mutableMapOf<Any?, Any?>().apply {
(0 until keysAndValues.size step 2).forEach {index ->
this[keysAndValues[index]] = keysAndValues[index + 1]
}
}
fun emptyMutableList(): Any = mutableListOf<Any?>()
fun emptyMutableSet(): Any = mutableSetOf<Any?>()
fun emptyMutableMap(): Any = mutableMapOf<Any?, Any?>()
data class TripleVals<T>(val first: T, val second: T, val third: T)
data class TripleVars<T>(var first: T, var second: T, var third: T) {
override fun toString(): String {
return "[$first, $second, $third]"
}
}
fun gc() = kotlin.native.internal.GC.collect()