JS lib: added hasNext to Kotlin.ListIterator and fixed next.
#KT-6506 Fixed Additionally made abstract AbstractList::get and AbstractCollection::size.
This commit is contained in:
@@ -26,7 +26,7 @@ public abstract class AbstractCollection<E>() : MutableCollection<E> {
|
||||
override fun retainAll(c: Collection<Any?>): Boolean = noImpl
|
||||
|
||||
override fun clear(): Unit = noImpl
|
||||
override fun size(): Int = noImpl
|
||||
abstract override fun size(): Int
|
||||
|
||||
override fun hashCode(): Int = noImpl
|
||||
override fun equals(other: Any?): Boolean = noImpl
|
||||
@@ -34,7 +34,7 @@ public abstract class AbstractCollection<E>() : MutableCollection<E> {
|
||||
|
||||
library
|
||||
public abstract class AbstractList<E>() : AbstractCollection<E>(), MutableList<E> {
|
||||
override fun get(index: Int): E = noImpl
|
||||
abstract override fun get(index: Int): E
|
||||
override fun set(index: Int, element: E): E = noImpl
|
||||
|
||||
override fun add(e: E): Boolean = noImpl
|
||||
@@ -60,6 +60,8 @@ public abstract class AbstractList<E>() : AbstractCollection<E>(), MutableList<E
|
||||
|
||||
library
|
||||
public open class ArrayList<E>(capacity: Int = 0) : AbstractList<E>() {
|
||||
override fun get(index: Int): E = noImpl
|
||||
override fun size(): Int = noImpl
|
||||
}
|
||||
|
||||
library
|
||||
@@ -78,7 +80,9 @@ public open class LinkedList<E>() : AbstractList<E>() {
|
||||
library
|
||||
public open class HashSet<E>(
|
||||
initialCapacity: Int = DEFAULT_INITIAL_CAPACITY, loadFactor: Float = DEFAULT_LOAD_FACTOR
|
||||
) : AbstractCollection<E>(), MutableSet<E>
|
||||
) : AbstractCollection<E>(), MutableSet<E> {
|
||||
override fun size(): Int = noImpl
|
||||
}
|
||||
|
||||
library
|
||||
public trait SortedSet<E> : Set<E> {
|
||||
@@ -86,12 +90,15 @@ public trait SortedSet<E> : Set<E> {
|
||||
|
||||
library
|
||||
public open class TreeSet<E>() : AbstractCollection<E>(), MutableSet<E>, SortedSet<E> {
|
||||
override fun size(): Int = noImpl
|
||||
}
|
||||
|
||||
library
|
||||
public open class LinkedHashSet<E>(
|
||||
initialCapacity: Int = DEFAULT_INITIAL_CAPACITY, loadFactor: Float = DEFAULT_LOAD_FACTOR
|
||||
) : HashSet<E>(initialCapacity, loadFactor), MutableSet<E>
|
||||
) : HashSet<E>(initialCapacity, loadFactor), MutableSet<E> {
|
||||
override fun size(): Int = noImpl
|
||||
}
|
||||
|
||||
library
|
||||
public open class HashMap<K, V>(initialCapacity: Int = DEFAULT_INITIAL_CAPACITY, loadFactor: Float = DEFAULT_LOAD_FACTOR) : MutableMap<K, V> {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2010-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.k2js.test.semantics;
|
||||
|
||||
public final class AbstractListTest extends JavaClassesTest {
|
||||
|
||||
public AbstractListTest() {
|
||||
super("abstractList/");
|
||||
}
|
||||
|
||||
public void testIterator() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package foo
|
||||
|
||||
import java.util.AbstractList
|
||||
|
||||
class MyList<T>(vararg val data: T) : AbstractList<T>() {
|
||||
override fun get(index: Int) = data[index]
|
||||
override fun size() = data.size()
|
||||
}
|
||||
|
||||
fun test<T>(expected: String, list: List<T>) {
|
||||
var s = ""
|
||||
for (e in list) {
|
||||
s += "$e,"
|
||||
}
|
||||
assertEquals(expected, s)
|
||||
|
||||
val it = list.iterator()
|
||||
s = ""
|
||||
while (it.hasNext()) {
|
||||
val e = it.next()
|
||||
s += "$e,"
|
||||
}
|
||||
assertEquals(expected, s)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
test("32,12,23,444,", MyList(32, 12, 23, 444))
|
||||
test("", MyList<Any>())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -276,8 +276,11 @@
|
||||
this.size = list.size();
|
||||
this.index = 0;
|
||||
}, {
|
||||
hasNext: function () {
|
||||
return this.index < this.size;
|
||||
},
|
||||
next: function () {
|
||||
return this.list.get(this.index++);
|
||||
return this.list.get_za3lpa$(this.index++);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user