fixed mapping sort and max functions from java.util.Collections

This commit is contained in:
Zalim Bashorov
2013-03-06 18:47:04 +04:00
parent dd7d584478
commit 220682afe2
9 changed files with 135 additions and 54 deletions
-48
View File
@@ -1,48 +0,0 @@
package java.util
import java.lang.*
public object Collections {
library("collectionsMax")
public fun max<T>(col : Collection<T>, comp : Comparator<T>) : T = js.noImpl
// TODO should be immutable!
library
public val emptyList: List<Any> = ArrayList<Any>()
library
public val emptyMap: Map<Any, Any> = HashMap<Any,Any>()
library
public val <T> EMPTY_LIST: List<T>
get() = emptyList<T>()
library
public val <K,V> EMPTY_MAP: Map<K,V>
get() = emptyMap<K,V>()
library
public fun <T> emptyList(): List<T> = emptyList as List<T>
library
public fun <K,V> emptyMap(): Map<K,V> = emptyMap as Map<K,V>
library
public fun <T> sort(list: MutableList<T>): Unit {
throw UnsupportedOperationException()
}
library("sortWithComp")
public fun <T> sort(list: MutableList<T>, comparator: java.util.Comparator<T>): Unit {
throw UnsupportedOperationException()
}
library
public fun <T> reverse(list: MutableList<T>): Unit {
val size = list.size()
for (i in 0.rangeTo(size / 2)) {
val i2 = size - i
val tmp = list[i]
list[i] = list[i2]
list[i2] = tmp
}
}
}
@@ -0,0 +1,13 @@
package java.util.Collections
import java.lang.*
import java.util.*
library("collectionsMax")
public fun max<T>(col : Collection<T>, comp : Comparator<T>) : T = js.noImpl
library("collectionsSort")
public fun <T> sort(list: MutableList<T>): Unit = js.noImpl
library("collectionsSort")
public fun <T> sort(list: MutableList<T>, comparator: java.util.Comparator<T>): Unit = js.noImpl
@@ -0,0 +1,34 @@
package java.util.Collections
import java.lang.*
import java.util.*
// TODO should be immutable!
library
public val emptyList: List<Any> = ArrayList<Any>()
library
public val emptyMap: Map<Any, Any> = HashMap<Any,Any>()
library
public val <T> EMPTY_LIST: List<T>
get() = emptyList<T>()
library
public val <K,V> EMPTY_MAP: Map<K,V>
get() = emptyMap<K,V>()
library
public fun <T> emptyList(): List<T> = emptyList as List<T>
library
public fun <K,V> emptyMap(): Map<K,V> = emptyMap as Map<K,V>
library
public fun <T> reverse(list: MutableList<T>): Unit {
val size = list.size()
for (i in 0.rangeTo(size / 2)) {
val i2 = size - i
val tmp = list[i]
list[i] = list[i2]
list[i2] = tmp
}
}