added support for map[key] = value on java.util.Map

This commit is contained in:
James Strachan
2012-01-04 16:14:49 +00:00
parent 1cd8f3c2ba
commit e73e81c526
3 changed files with 21 additions and 10 deletions
+3
View File
@@ -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()
+5 -10
View File
@@ -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 {
+13
View File
@@ -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"])
}
}