added support for map[key] = value on java.util.Map
This commit is contained in:
@@ -13,6 +13,9 @@ val JMap<*,*>.size : Int
|
||||
val JMap<*,*>.empty : Boolean
|
||||
get() = isEmpty()
|
||||
|
||||
/** Provides [] access to maps */
|
||||
fun <K, V> JMap<K, V>.set(key : K, value : V) = this.put(key, value)
|
||||
|
||||
/** Returns the key of the entry */
|
||||
val <K,V> JEntry<K,V>.key : K
|
||||
get() = getKey()
|
||||
|
||||
@@ -120,7 +120,6 @@ class Body() : BodyTag("body") {
|
||||
fun a(href : String, init : A.()-> Unit) {
|
||||
val a = initTag(init)
|
||||
a.href = href
|
||||
a.attributes.put("href", href)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,15 +145,11 @@ class A() : BodyTag("a") {
|
||||
override fun create() = A()
|
||||
}
|
||||
|
||||
var href: String? = null
|
||||
/*
|
||||
TODO this doesn't compile
|
||||
see http://youtrack.jetbrains.net/issue/KT-866
|
||||
|
||||
var href : String
|
||||
get() = attributes["href"]
|
||||
set(value) { attributes["href"] = value }
|
||||
*/
|
||||
var href : String
|
||||
get() = attributes["href"]
|
||||
set(value) {
|
||||
attributes["href"] = value
|
||||
}
|
||||
}
|
||||
|
||||
fun body(init: Body.()-> Unit): Body {
|
||||
|
||||
@@ -36,4 +36,17 @@ class MapTest() : TestSupport() {
|
||||
|
||||
assertEquals(data.size, 0)
|
||||
}
|
||||
|
||||
fun testSetViaIndexOperators() {
|
||||
// TODO cant just create a HashMap due to KT-834
|
||||
val map: Map<String,String> = HashMap<String, String>()
|
||||
assert{ map.empty }
|
||||
assertEquals(map.size, 0)
|
||||
|
||||
map["name"] = "James"
|
||||
|
||||
assert{ !map.empty }
|
||||
assertEquals(map.size, 1)
|
||||
assertEquals("James", map["name"])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user