Support "key in map" using extension contains() function. #KT-3607 Fixed

This commit is contained in:
Ilya Ryzhenkov
2014-05-07 19:00:36 +04:00
committed by Andrey Breslav
parent 5f224efdc1
commit 5b73fba2d4
2 changed files with 7 additions and 0 deletions
@@ -20,6 +20,7 @@ public fun <K, V> MutableMap<K, V>.set(key : K, value : V) : V? = this.put(key,
public fun <K,V> Map<K,V>?.orEmpty() : Map<K,V>
= if (this != null) this else Collections.emptyMap<K,V>() as Map<K,V>
public fun <K,V> Map<K,V>.contains(key : K) : Boolean = containsKey(key)
/** Returns the key of the entry */
public val <K,V> Map.Entry<K,V>.key : K
@@ -105,6 +105,12 @@ class MapTest {
assertEquals("beverage,beer,location,Mells,name,James", list.makeString(","))
}
test fun contains() {
val map = hashMapOf("a" to 1, "b" to 2)
assert("a" in map)
assert("c" !in map)
}
test fun map() {
val m1 = TreeMap<String, String>()
m1["beverage"] = "beer"