Introduce Common protected property AbstractMutableList.modCount #KT-57150

This commit is contained in:
Abduqodiri Qurbonzoda
2024-01-12 18:36:17 +05:00
committed by Space Team
parent 1626057f75
commit 5f16fb2e4d
4 changed files with 27 additions and 3 deletions
@@ -11,6 +11,20 @@ package kotlin.collections
* @param E the type of elements contained in the list. The list is invariant in its element type. * @param E the type of elements contained in the list. The list is invariant in its element type.
*/ */
public expect abstract class AbstractMutableList<E> : MutableList<E> { public expect abstract class AbstractMutableList<E> : MutableList<E> {
/**
* The number of times this list is structurally modified.
*
* A modification is considered to be structural if it changes the list size,
* or otherwise changes it in a way that iterations in progress may return incorrect results.
*
* This value can be used by iterators returned by [iterator] and [listIterator]
* to provide fail-fast behavoir when a concurrent modification is detected during iteration.
* [ConcurrentModificationException] will be thrown in this case.
*/
// TODO: Should be @SinceKotlin("2.0"), see KT-64904
@SinceKotlin("1.9")
protected var modCount: Int
protected constructor() protected constructor()
/** /**
@@ -18,7 +18,17 @@ package kotlin.collections
* @param E the type of elements contained in the list. The list is invariant in its element type. * @param E the type of elements contained in the list. The list is invariant in its element type.
*/ */
public actual abstract class AbstractMutableList<E> protected actual constructor() : AbstractMutableCollection<E>(), MutableList<E> { public actual abstract class AbstractMutableList<E> protected actual constructor() : AbstractMutableCollection<E>(), MutableList<E> {
protected var modCount: Int = 0 /**
* The number of times this list is structurally modified.
*
* A modification is considered to be structural if it changes the list size,
* or otherwise changes it in a way that iterations in progress may return incorrect results.
*
* This value can be used by iterators returned by [iterator] and [listIterator]
* to provide fail-fast behavoir when a concurrent modification is detected during iteration.
* [ConcurrentModificationException] will be thrown in this case.
*/
protected actual var modCount: Int = 0
abstract override fun add(index: Int, element: E): Unit abstract override fun add(index: Int, element: E): Unit
abstract override fun removeAt(index: Int): E abstract override fun removeAt(index: Int): E
@@ -13,7 +13,7 @@ import java.util.AbstractList
* @param E the type of elements contained in the list. The list is invariant in its element type. * @param E the type of elements contained in the list. The list is invariant in its element type.
*/ */
@SinceKotlin("1.1") @SinceKotlin("1.1")
// removeRange: Kotlin `protected` visibility is different from Java // removeRange, modCount: Kotlin `protected` visibility is different from Java
@Suppress("NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS") @Suppress("NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS")
public actual abstract class AbstractMutableList<E> protected actual constructor() : MutableList<E>, AbstractList<E>() { public actual abstract class AbstractMutableList<E> protected actual constructor() : MutableList<E>, AbstractList<E>() {
/** /**
@@ -28,7 +28,7 @@ public actual abstract class AbstractMutableList<E> protected actual constructor
* to provide fail-fast behavoir when a concurrent modification is detected during iteration. * to provide fail-fast behavoir when a concurrent modification is detected during iteration.
* [ConcurrentModificationException] will be thrown in this case. * [ConcurrentModificationException] will be thrown in this case.
*/ */
protected var modCount: Int = 0 protected actual var modCount: Int = 0
abstract override fun add(index: Int, element: E): Unit abstract override fun add(index: Int, element: E): Unit
abstract override fun removeAt(index: Int): E abstract override fun removeAt(index: Int): E