Support "key in map" using extension contains() function. #KT-3607 Fixed
This commit is contained in:
committed by
Andrey Breslav
parent
5f224efdc1
commit
5b73fba2d4
@@ -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>
|
public fun <K,V> Map<K,V>?.orEmpty() : Map<K,V>
|
||||||
= if (this != null) this else Collections.emptyMap<K,V>() as 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 */
|
/** Returns the key of the entry */
|
||||||
public val <K,V> Map.Entry<K,V>.key : K
|
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(","))
|
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() {
|
test fun map() {
|
||||||
val m1 = TreeMap<String, String>()
|
val m1 = TreeMap<String, String>()
|
||||||
m1["beverage"] = "beer"
|
m1["beverage"] = "beer"
|
||||||
|
|||||||
Reference in New Issue
Block a user