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
+27 -1
View File
@@ -198,6 +198,7 @@ var kotlin = {set:function (receiver, key, value) {
}
});
//TODO: should be JS Array-like (https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Predefined_Core_Objects#Working_with_Array-like_objects)
Kotlin.ArrayList = Kotlin.$createClass(Kotlin.AbstractList, {
initialize: function () {
this.array = [];
@@ -364,7 +365,7 @@ var kotlin = {set:function (receiver, key, value) {
},
next: function () {
var value = this.$i;
this.set_i(this.$i + this.$increment)
this.set_i(this.$i + this.$increment);
return value;
},
get_hasNext: function () {
@@ -446,6 +447,31 @@ var kotlin = {set:function (receiver, key, value) {
return max;
};
Kotlin.collectionsSort = function (mutableList, comparator) {
var boundComparator = undefined;
if (comparator !== undefined) {
boundComparator = comparator.compare.bind(comparator);
}
if (mutableList instanceof Array) {
mutableList.sort(boundComparator);
}
//TODO: should be deleted when List will be JS Array-like (https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Predefined_Core_Objects#Working_with_Array-like_objects)
var array = [];
var it = mutableList.iterator();
while (it.hasNext()) {
array.push(it.next());
}
array.sort(boundComparator);
for (var i = 0, n = array.length; i < n; i++) {
mutableList.set(i, array[i]);
}
};
Kotlin.StringBuilder = Kotlin.$createClass(
{
initialize:function () {