/* * 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 isEmpty(map: Map) = map.isEmpty() fun getKeysAsSet(map: Map) = map.keys fun getKeysAsList(map: Map) = map.keys.toList() fun toMutableMap(map: HashMap) = map.toMutableMap() fun getFirstElement(collection: Collection) = collection.first() class GenericExtensionClass> (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 createPair(): Pair, GenericExtensionClass>> { val l = createLinkedMap() val g = GenericExtensionClass(l) return Pair(l, g) } fun createLinkedMap() = linkedMapOf() fun createTypedMutableMap() = linkedMapOf() fun addSomeElementsToMap(map: MutableMap) { 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().apply { (0 until keysAndValues.size step 2).forEach {index -> this[keysAndValues[index]] = keysAndValues[index + 1] } } fun emptyMutableList(): Any = mutableListOf() fun emptyMutableSet(): Any = mutableSetOf() fun emptyMutableMap(): Any = mutableMapOf() data class TripleVals(val first: T, val second: T, val third: T) data class TripleVars(var first: T, var second: T, var third: T) { override fun toString(): String { return "[$first, $second, $third]" } } fun gc() = kotlin.native.internal.GC.collect()