got more map code compiling to JS and running as unit tests

This commit is contained in:
James Strachan
2012-07-03 07:43:15 +01:00
parent 8637373aa2
commit 541f3d4e78
12 changed files with 276 additions and 48 deletions
+5 -1
View File
@@ -30,6 +30,11 @@ public class UnsupportedOperationException(message: String = "") : Exception() {
library
public class NumberFormatException(message: String = "") : Exception() {}
library
public trait Runnable {
open fun run() : Unit;
}
public trait Comparable<T> {
fun compareTo(that: T): Int
}
@@ -39,4 +44,3 @@ public trait Appendable {
open fun append(csq: CharSequence?, start: Int, end: Int): Appendable?
open fun append(c: Char): Appendable?
}
+5
View File
@@ -244,3 +244,8 @@ public class StringBuilder() : Appendable {
library
public class NoSuchElementException() : Exception() {}
public trait Enumeration<E> {
open fun hasMoreElements(): Boolean
open fun nextElement(): E?
}
+21 -2
View File
@@ -1,7 +1,26 @@
package kotlin
import java.util.Map as JMap
import java.util.Map
/** Provides [] access to maps */
public fun <K, V> JMap<K, V>.set(key : K, value : V): Unit {
public fun <K, V> Map<K, V>.set(key : K, value : V): Unit {
this.put(key, value)
}
/**
* Returns a new [[HashMap]] populated with the given tuple values where the first value in each tuple
* is the key and the second value is the value
*
* @includeFunctionBody ../../test/MapTest.kt createUsingTuples
*/
public inline fun <K,V> hashMap(vararg values: #(K,V)): java.util.HashMap<K,V> {
val answer = java.util.HashMap<K,V>()
/**
TODO replace by this simpler call when we can pass vararg values into other methods
answer.putAll(values)
*/
for (v in values) {
answer.put(v._1, v._2)
}
return answer
}