re-enabled the Map.Entry key/value properties (not quite sure why they were disabled, tests all seem to work?) and tidied up the sample code for the kdocs
This commit is contained in:
@@ -4,8 +4,7 @@ import java.util.Map as JMap
|
|||||||
import java.util.HashMap
|
import java.util.HashMap
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
|
|
||||||
// Temporary workaround: commenting out
|
import java.util.Map.Entry as JEntry
|
||||||
//import java.util.Map.Entry as JEntry
|
|
||||||
|
|
||||||
// Map APIs
|
// Map APIs
|
||||||
|
|
||||||
@@ -26,14 +25,12 @@ public inline fun <K,V> java.util.Map<K,V>?.orEmpty() : java.util.Map<K,V>
|
|||||||
|
|
||||||
|
|
||||||
/** Returns the key of the entry */
|
/** Returns the key of the entry */
|
||||||
// Temporary workaround: commenting out
|
val <K,V> JEntry<K,V>.key : K
|
||||||
//val <K,V> JEntry<K,V>.key : K
|
get() = getKey().sure()
|
||||||
// get() = getKey().sure()
|
|
||||||
|
|
||||||
/** Returns the value of the entry */
|
/** Returns the value of the entry */
|
||||||
// Temporary workaround: commenting out
|
val <K,V> JEntry<K,V>.value : V
|
||||||
//val <K,V> JEntry<K,V>.value : V
|
get() = getValue().sure()
|
||||||
// get() = getValue().sure()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value for the given key or returns the result of the defaultValue function if there was no entry for the given key
|
* Returns the value for the given key or returns the result of the defaultValue function if there was no entry for the given key
|
||||||
@@ -69,7 +66,7 @@ public inline fun <K,V> java.util.Map<K,V>.getOrPut(key: K, defaultValue: ()-> V
|
|||||||
/**
|
/**
|
||||||
* Returns an [[Iterator]] over the entries in the [[Map]]
|
* Returns an [[Iterator]] over the entries in the [[Map]]
|
||||||
*
|
*
|
||||||
* @includeFunctionBody ../../test/MapTest.kt iterate
|
* @includeFunctionBody ../../test/MapTest.kt iterateWithProperties
|
||||||
*/
|
*/
|
||||||
public inline fun <K,V> java.util.Map<K,V>.iterator(): java.util.Iterator<java.util.Map.Entry<K,V>> {
|
public inline fun <K,V> java.util.Map<K,V>.iterator(): java.util.Iterator<java.util.Map.Entry<K,V>> {
|
||||||
val entrySet = this.entrySet()!!
|
val entrySet = this.entrySet()!!
|
||||||
|
|||||||
@@ -52,42 +52,31 @@ class MapTest {
|
|||||||
map["location"] = "Mells"
|
map["location"] = "Mells"
|
||||||
map["name"] = "James"
|
map["name"] = "James"
|
||||||
|
|
||||||
var list = arrayList<String>()
|
val list = arrayList<String>()
|
||||||
for (e in map) {
|
for (e in map) {
|
||||||
println("key = ${e.getKey()}, value = ${e.getValue()}")
|
println("key = ${e.getKey()}, value = ${e.getValue()}")
|
||||||
|
|
||||||
list.add(e.getKey())
|
list.add(e.getKey())
|
||||||
list.add(e.getValue())
|
list.add(e.getValue())
|
||||||
/*
|
|
||||||
// TODO compiler bug
|
|
||||||
list += e.getKey()
|
|
||||||
list += e.getValue()
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(6, list.size())
|
assertEquals(6, list.size())
|
||||||
assertEquals("beverage,beer,location,Mells,name,James", list.makeString(","))
|
assertEquals("beverage,beer,location,Mells,name,James", list.makeString(","))
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
test fun iterateWithProperties() {
|
||||||
TODO compiler bug
|
|
||||||
|
|
||||||
test fun iteratorWithProperties() {
|
|
||||||
val map = TreeMap<String, String>()
|
val map = TreeMap<String, String>()
|
||||||
map["beverage"] = "beer"
|
map["beverage"] = "beer"
|
||||||
map["location"] = "Mells"
|
map["location"] = "Mells"
|
||||||
map["name"] = "James"
|
map["name"] = "James"
|
||||||
|
|
||||||
var list = arrayList<String>()
|
val list = arrayList<String>()
|
||||||
for (e in map) {
|
for (e in map) {
|
||||||
println("got $e")
|
|
||||||
println("key = ${e.key}, value = ${e.value}")
|
println("key = ${e.key}, value = ${e.value}")
|
||||||
list += e.key
|
list.add(e.key)
|
||||||
list += e.value
|
list.add(e.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(6, list.size())
|
assertEquals(6, list.size())
|
||||||
assertEquals("beverage,beer,location,Mells,name,James", list.makeString(","))
|
assertEquals("beverage,beer,location,Mells,name,James", list.makeString(","))
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user