add java.util.Map's size and empty properties
This commit is contained in:
@@ -1,20 +1,16 @@
|
|||||||
package std.util
|
package std.util
|
||||||
|
|
||||||
import java.util.*
|
import java.util.Map as JMap
|
||||||
|
|
||||||
// Map APIs
|
// Map APIs
|
||||||
|
|
||||||
/** Returns the size of the map */
|
/** Returns the size of the map */
|
||||||
/* TODO get redeclaration errors
|
val JMap<*,*>.size : Int
|
||||||
val Map<*,*>.size : Int
|
|
||||||
get() = size()
|
get() = size()
|
||||||
*/
|
|
||||||
|
|
||||||
/** Returns true if this map is empty */
|
/** Returns true if this map is empty */
|
||||||
/* TODO get redeclaration errors
|
val JMap<*,*>.empty : Boolean
|
||||||
val Map<*,*>.empty : Boolean
|
|
||||||
get() = isEmpty()
|
get() = isEmpty()
|
||||||
*/
|
|
||||||
|
|
||||||
/** 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 */
|
||||||
inline fun <K,V> java.util.Map<K,V>.getOrElse(key: K, defaultValue: ()-> V) : V {
|
inline fun <K,V> java.util.Map<K,V>.getOrElse(key: K, defaultValue: ()-> V) : V {
|
||||||
|
|||||||
@@ -18,9 +18,7 @@ class MapTest() : TestSupport() {
|
|||||||
|
|
||||||
val b = data.getOrElse("foo"){3}
|
val b = data.getOrElse("foo"){3}
|
||||||
assertEquals(3, b)
|
assertEquals(3, b)
|
||||||
|
assertEquals(0, data.size)
|
||||||
// TODO should be able to miss the () off of size
|
|
||||||
assertEquals(0, data.size())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testGetOrElseUpdate() {
|
fun testGetOrElseUpdate() {
|
||||||
@@ -33,11 +31,9 @@ class MapTest() : TestSupport() {
|
|||||||
assertEquals(1, data.size())
|
assertEquals(1, data.size())
|
||||||
}
|
}
|
||||||
|
|
||||||
/** TODO can't seem to define size/empty properties for Map
|
|
||||||
fun testSizeAndEmpty() {
|
fun testSizeAndEmpty() {
|
||||||
assert{ data.empty }
|
assert{ data.empty }
|
||||||
|
|
||||||
assertEquals(data.size, 0)
|
assertEquals(data.size, 0)
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user