Make mutation methods in AbstractMutable-collections abstract rather than implement them unsupported.
This commit is contained in:
@@ -19,7 +19,7 @@ package kotlin.collections
|
||||
|
||||
public abstract class AbstractMutableCollection<E> protected constructor() : AbstractCollection<E>(), MutableCollection<E> {
|
||||
|
||||
override fun add(element: E): Boolean = throw UnsupportedOperationException("Add not supported on this collection")
|
||||
abstract override fun add(element: E): Boolean
|
||||
|
||||
override fun remove(element: E): Boolean {
|
||||
val iterator = iterator()
|
||||
|
||||
@@ -24,9 +24,9 @@ package kotlin.collections
|
||||
public abstract class AbstractMutableList<E> protected constructor() : AbstractMutableCollection<E>(), MutableList<E> {
|
||||
protected var modCount: Int = 0
|
||||
|
||||
override fun add(index: Int, element: E): Unit = throw UnsupportedOperationException("Add not supported on this list")
|
||||
override fun removeAt(index: Int): E = throw UnsupportedOperationException("Remove not supported on this list")
|
||||
override fun set(index: Int, element: E): E = throw UnsupportedOperationException("Set not supported on this list")
|
||||
abstract override fun add(index: Int, element: E): Unit
|
||||
abstract override fun removeAt(index: Int): E
|
||||
abstract override fun set(index: Int, element: E): E
|
||||
|
||||
override fun add(element: E): Boolean {
|
||||
add(size, element)
|
||||
|
||||
@@ -52,6 +52,7 @@ public abstract class AbstractMutableMap<K, V> protected constructor() : Abstrac
|
||||
override val keys: MutableSet<K> get() {
|
||||
if (_keys == null) {
|
||||
_keys = object : AbstractMutableSet<K>() {
|
||||
override fun add(element: K): Boolean = throw UnsupportedOperationException("Add is not supported on keys")
|
||||
override fun clear() {
|
||||
this@AbstractMutableMap.clear()
|
||||
}
|
||||
@@ -81,9 +82,7 @@ public abstract class AbstractMutableMap<K, V> protected constructor() : Abstrac
|
||||
return _keys!!
|
||||
}
|
||||
|
||||
override fun put(key: K, value: V): V? {
|
||||
throw UnsupportedOperationException("Put not supported on this map")
|
||||
}
|
||||
abstract override fun put(key: K, value: V): V?
|
||||
|
||||
override fun putAll(from: Map<out K, V>) {
|
||||
for ((key, value) in from) {
|
||||
@@ -95,6 +94,7 @@ public abstract class AbstractMutableMap<K, V> protected constructor() : Abstrac
|
||||
override val values: MutableCollection<V> get() {
|
||||
if (_values == null) {
|
||||
_values = object : AbstractMutableCollection<V>() {
|
||||
override fun add(element: V): Boolean = throw UnsupportedOperationException("Add is not supported on values")
|
||||
override fun clear() = this@AbstractMutableMap.clear()
|
||||
|
||||
override operator fun contains(element: V): Boolean = containsValue(element)
|
||||
|
||||
@@ -27,6 +27,7 @@ public open class HashMap<K, V> : AbstractMutableMap<K, V> {
|
||||
|
||||
private inner class EntrySet : AbstractMutableSet<MutableEntry<K, V>>() {
|
||||
|
||||
override fun add(element: MutableEntry<K, V>): Boolean = throw UnsupportedOperationException("Add is not supported on entries")
|
||||
override fun clear() {
|
||||
this@HashMap.clear()
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ public open class LinkedHashMap<K, V> : HashMap<K, V>, Map<K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
override fun add(element: MutableEntry<K, V>): Boolean = throw UnsupportedOperationException("Add is not supported on entries")
|
||||
override fun clear() {
|
||||
this@LinkedHashMap.clear()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user