added Collections.max

added another test for extension properties
This commit is contained in:
Pavel Talanov
2012-02-02 16:27:11 +04:00
parent aa30c264c0
commit c8e08e3ca2
8 changed files with 68 additions and 26 deletions
+7 -10
View File
@@ -2,16 +2,13 @@ package java.util
import js.annotations.*;
//LibraryClass
//public trait Comparator<T> {
// fun compare(obj1 : T, obj2 : T) : Int;
//}
//
//LibraryFun("comparator")
//public fun comparator<T>(f : (T, T) -> Int) : Comparator<T> {}
//
//LibraryFun("max")
//public fun max<T>(col : Collection<T>, comp : Comparator<T>) {}
LibraryClass
public trait Comparator<T> {
fun compare(obj1 : T, obj2 : T) : Int;
}
LibraryFun("comparator")
public fun comparator<T>(f : (T, T) -> Int) : Comparator<T> {}
LibraryClass
+8
View File
@@ -0,0 +1,8 @@
package java.util.Collections;
import js.annotations.LibraryFun
import java.util.Collection
import java.util.Comparator
LibraryFun("collectionsMax")
public fun max<T>(col : Collection<T>, comp : Comparator<T>) {}
@@ -31,7 +31,8 @@ public abstract class Config {
PATH_TO_JS_LIB_SRC + "\\core\\core.kt",
PATH_TO_JS_LIB_SRC + "\\raphael\\raphael.kt",
PATH_TO_JS_LIB_SRC + "\\core\\json.kt",
PATH_TO_JS_LIB_SRC + "\\html5\\core.kt"
PATH_TO_JS_LIB_SRC + "\\html5\\core.kt",
PATH_TO_JS_LIB_SRC + "\\core\\javautilcollections.kt"
);
@@ -18,9 +18,13 @@ public final class ExtensionPropertyTest extends TranslationTest {
testFooBoxIsTrue("simplePropertyWithGetter.kt");
}
@Test
public void propertyWithGetterAndSetter() throws Exception {
testFooBoxIsTrue("propertyWithGetterAndSetter.kt");
}
@Test
public void absExtension() throws Exception {
testFooBoxIsTrue("absExtension.kt");
}
}
@@ -32,7 +32,7 @@ public final class WebDemoExamples2Test extends TranslationTest {
testWithMain("builder", "1", "over9000");
}
//TODO: comparator dependencies
//TODO: comparator LinkedList dependencies
// @Test
// public void maze() throws Exception {
// testWithMain("maze", "");
@@ -0,0 +1,11 @@
package foo;
val Double.abs : Double
get() = if (this > 0) this else -this
fun box() : Boolean {
if (4.0.abs != 4.0) return false;
if ((-5.2).abs != 5.2) return false;
return true;
}
+32 -11
View File
@@ -109,16 +109,15 @@
current = current.superclass;
}
return true;
}
};
var emptyFunction = function () {
}
};
var Class = (function () {
function subclass() {
}
;
function create() {
var parent = null, properties = $A(arguments);
@@ -203,7 +202,7 @@
var Trait = (function () {
function add(object, source) {
properties = Object.keys(source);
var properties = Object.keys(source);
for (var i = 0, length = properties.length; i < length; i++) {
var property = properties[i];
var value = source[property];
@@ -238,7 +237,17 @@
};
})();
Kotlin = {}
var object = (function () {
function create() {
var singletonClass = Class.create.apply(Class, arguments);
return new singletonClass;
}
return {
create:create
};
})();
Kotlin = {};
Kotlin.Class = Class;
Kotlin.Namespace = Namespace;
Kotlin.Trait = Trait;
@@ -315,9 +324,9 @@
Kotlin.parseInt =
function (str) {
return parseInt(str);
}
function (str) {
return parseInt(str);
}
;
Kotlin.System = function () {
@@ -454,14 +463,26 @@
{
initialize:function () {
},
compare:function () {
compare:function (el1, el2) {
throw new Kotlin.AbstractFunctionInvokationError();
}
}
);
Kotlin.collectionsMax = function(col, comp) {
Kotlin.collectionsMax = function (col, comp) {
var it = col.iterator();
if (col.isEmpty()) {
//TODO: which exception?
throw Kotlin.Exception();
}
var max = it.next();
while (it.hasNext()) {
var el = it.next();
if (comp.compare(max, el) < 0) {
max = el;
}
}
return max;
};
Kotlin.StringBuilder = Kotlin.Class.create(
@@ -31,10 +31,10 @@ import java.util.*
fun findPath(maze : Maze) : List<#(Int, Int)>? {
val previous = HashMap<#(Int, Int), #(Int, Int)>
val queue = LinkedList<#(Int, Int)>
val queue = ArrayList<#(Int, Int)>
val visited = HashSet<#(Int, Int)>
queue.offer(maze.start)
queue.add(maze.start)
visited.add(maze.start)
while (!queue.isEmpty()) {
val cell = queue.poll()