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
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user