added AbstractCollection base class and equals/toString to HashSet
This commit is contained in:
@@ -113,10 +113,7 @@ var kotlin = {set:function (receiver, key, value) {
|
||||
}
|
||||
});
|
||||
|
||||
Kotlin.AbstractList = Kotlin.$createClass({
|
||||
iterator: function () {
|
||||
return Kotlin.$new(ListIterator)(this);
|
||||
},
|
||||
Kotlin.AbstractCollection = Kotlin.$createClass({
|
||||
isEmpty: function () {
|
||||
return this.size() == 0;
|
||||
},
|
||||
@@ -126,17 +123,8 @@ var kotlin = {set:function (receiver, key, value) {
|
||||
this.add(it.next());
|
||||
}
|
||||
},
|
||||
remove: function (o) {
|
||||
var index = this.indexOf(o);
|
||||
if (index != -1) {
|
||||
this.removeAt(index);
|
||||
}
|
||||
},
|
||||
contains: function (o) {
|
||||
return this.indexOf(o) != -1;
|
||||
},
|
||||
equals: function (o) {
|
||||
if (this.$size === o.$size) {
|
||||
if (this.size() === o.size()) {
|
||||
var iter1 = this.iterator();
|
||||
var iter2 = o.iterator();
|
||||
while (true) {
|
||||
@@ -170,6 +158,23 @@ var kotlin = {set:function (receiver, key, value) {
|
||||
}
|
||||
});
|
||||
|
||||
Kotlin.AbstractList = Kotlin.$createClass(Kotlin.AbstractCollection, {
|
||||
iterator: function () {
|
||||
return Kotlin.$new(ListIterator)(this);
|
||||
},
|
||||
isEmpty: function () {
|
||||
return this.size() == 0;
|
||||
},
|
||||
remove: function (o) {
|
||||
var index = this.indexOf(o);
|
||||
if (index != -1) {
|
||||
this.removeAt(index);
|
||||
}
|
||||
},
|
||||
contains: function (o) {
|
||||
return this.indexOf(o) != -1;
|
||||
}
|
||||
});
|
||||
Kotlin.ArrayList = Kotlin.$createClass(Kotlin.AbstractList, {
|
||||
initialize: function () {
|
||||
this.array = [];
|
||||
@@ -903,6 +908,41 @@ var kotlin = {set:function (receiver, key, value) {
|
||||
return h;
|
||||
};
|
||||
|
||||
this.equals = function (o) {
|
||||
if (this.size() === o.size()) {
|
||||
var iter1 = this.iterator();
|
||||
var iter2 = o.iterator();
|
||||
while (true) {
|
||||
var hn1 = iter1.get_hasNext();
|
||||
var hn2 = iter2.get_hasNext();
|
||||
if (hn1 != hn2) return false;
|
||||
if (!hn2)
|
||||
return true;
|
||||
else {
|
||||
var o1 = iter1.next();
|
||||
var o2 = iter2.next();
|
||||
if (!Kotlin.equals(o1, o2)) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
this.toString = function() {
|
||||
var builder = "[";
|
||||
var iter = this.iterator();
|
||||
var first = true;
|
||||
while (iter.get_hasNext()) {
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
builder += ", ";
|
||||
builder += iter.next();
|
||||
}
|
||||
builder += "]";
|
||||
return builder;
|
||||
};
|
||||
|
||||
this.intersection = function (hashSet) {
|
||||
var intersection = new HashSet(hashingFunction, equalityFunction);
|
||||
var values = hashSet.values(), i = values.length, val;
|
||||
|
||||
Reference in New Issue
Block a user