Split AbstractCollection, List, Set in JS to readonly Abstract[Collection] and mutable AbstractMutable[Collection].
Update compatibility type aliases.
This commit is contained in:
@@ -15,14 +15,14 @@
|
||||
*/
|
||||
package kotlin.collections
|
||||
|
||||
public abstract class AbstractCollection<out E> : Collection<E> {
|
||||
public abstract class AbstractCollection<out E> protected constructor() : Collection<E> {
|
||||
abstract override val size: Int
|
||||
abstract override fun iterator(): Iterator<E>
|
||||
|
||||
override fun contains(element: @UnsafeVariance E): Boolean = any { it == element }
|
||||
|
||||
override fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean =
|
||||
elements.all(this::contains)
|
||||
elements.all { contains(it) } // use when js will support bound refs: elements.all(this::contains)
|
||||
|
||||
override fun isEmpty(): Boolean = size == 0
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
package kotlin.collections
|
||||
|
||||
public abstract class AbstractList<out E> : AbstractCollection<E>(), List<E> {
|
||||
public abstract class AbstractList<out E> protected constructor() : AbstractCollection<E>(), List<E> {
|
||||
abstract override val size: Int
|
||||
abstract override fun get(index: Int): E
|
||||
|
||||
@@ -62,7 +62,7 @@ public abstract class AbstractList<out E> : AbstractCollection<E>(), List<E> {
|
||||
|
||||
override fun hashCode(): Int = orderedHashCode(this)
|
||||
|
||||
internal open inner class IteratorImpl : Iterator<E> {
|
||||
private open inner class IteratorImpl : Iterator<E> {
|
||||
/** the index of the item that will be returned on the next call to [next]`()` */
|
||||
protected var index = 0
|
||||
/** the index of the item that was returned on the previous call to [next]`()`
|
||||
@@ -83,7 +83,7 @@ public abstract class AbstractList<out E> : AbstractCollection<E>(), List<E> {
|
||||
/**
|
||||
* Implementation of `MutableListIterator` for abstract lists.
|
||||
*/
|
||||
internal open inner class ListIteratorImpl(index: Int) : IteratorImpl(), ListIterator<E> {
|
||||
private open inner class ListIteratorImpl(index: Int) : IteratorImpl(), ListIterator<E> {
|
||||
|
||||
init {
|
||||
checkPositionIndex(index, this@AbstractList.size)
|
||||
@@ -104,7 +104,7 @@ public abstract class AbstractList<out E> : AbstractCollection<E>(), List<E> {
|
||||
override fun previousIndex(): Int = index - 1
|
||||
}
|
||||
|
||||
companion object {
|
||||
internal companion object {
|
||||
internal fun checkElementIndex(index: Int, size: Int) {
|
||||
if (index < 0 || index >= size) {
|
||||
throw IndexOutOfBoundsException("index: $index, size: $size")
|
||||
|
||||
@@ -20,16 +20,24 @@ public abstract class AbstractSet<out E> protected constructor() : AbstractColle
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other === this) return true
|
||||
if (other !is Set<*>) return false
|
||||
if (other.size != size) return false
|
||||
return containsAll(other)
|
||||
return setEquals(this, other)
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var hashCode = 0
|
||||
for (element in this) {
|
||||
hashCode = (hashCode + (element?.hashCode() ?: 0)) or 0
|
||||
override fun hashCode(): Int = unorderedHashCode(this)
|
||||
|
||||
internal companion object {
|
||||
internal fun unorderedHashCode(c: Collection<*>): Int {
|
||||
var hashCode = 0
|
||||
for (element in c) {
|
||||
hashCode = (hashCode + (element?.hashCode() ?: 0)) or 0
|
||||
}
|
||||
return hashCode
|
||||
}
|
||||
|
||||
internal fun setEquals(c: Set<*>, other: Set<*>): Boolean {
|
||||
if (c.size != other.size) return false
|
||||
return c.containsAll(other)
|
||||
}
|
||||
return hashCode
|
||||
}
|
||||
|
||||
}
|
||||
+3
-5
@@ -67,7 +67,7 @@ public final class kotlin/_Assertions {
|
||||
}
|
||||
|
||||
public abstract class kotlin/collections/AbstractCollection : java/util/Collection, kotlin/jvm/internal/markers/KMappedMarker {
|
||||
public fun <init> ()V
|
||||
protected fun <init> ()V
|
||||
public fun add (Ljava/lang/Object;)Z
|
||||
public fun addAll (Ljava/util/Collection;)Z
|
||||
public fun clear ()V
|
||||
@@ -99,7 +99,7 @@ public abstract class kotlin/collections/AbstractIterator : java/util/Iterator,
|
||||
|
||||
public abstract class kotlin/collections/AbstractList : kotlin/collections/AbstractCollection, java/util/List, kotlin/jvm/internal/markers/KMappedMarker {
|
||||
public static final field Companion Lkotlin/collections/AbstractList$Companion;
|
||||
public fun <init> ()V
|
||||
protected fun <init> ()V
|
||||
public fun add (ILjava/lang/Object;)V
|
||||
public fun add (Ljava/lang/Object;)Z
|
||||
public fun addAll (ILjava/util/Collection;)Z
|
||||
@@ -125,10 +125,8 @@ public abstract class kotlin/collections/AbstractList : kotlin/collections/Abstr
|
||||
public fun toArray ([Ljava/lang/Object;)[Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public final class kotlin/collections/AbstractList$Companion {
|
||||
}
|
||||
|
||||
public abstract class kotlin/collections/AbstractSet : kotlin/collections/AbstractCollection, java/util/Set, kotlin/jvm/internal/markers/KMappedMarker {
|
||||
public static final field Companion Lkotlin/collections/AbstractSet$Companion;
|
||||
protected fun <init> ()V
|
||||
public fun add (Ljava/lang/Object;)Z
|
||||
public fun addAll (Ljava/util/Collection;)Z
|
||||
|
||||
Reference in New Issue
Block a user