Make mutation methods in AbstractMutable-collections abstract rather than implement them unsupported.

This commit is contained in:
Ilya Gorbunov
2016-09-14 22:05:02 +03:00
parent 74e964aabe
commit 7dde8df9ae
11 changed files with 79 additions and 14 deletions
@@ -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()
}
@@ -0,0 +1,8 @@
@file:JvmVersion
package kotlin.collections
import java.util.AbstractCollection
public abstract class AbstractMutableCollection<E> protected constructor() : AbstractCollection<E>() {
abstract override fun add(element: E): Boolean
}
@@ -0,0 +1,10 @@
@file:JvmVersion
package kotlin.collections
import java.util.AbstractList
public abstract class AbstractMutableList<E> protected constructor() : AbstractList<E>() {
abstract override fun set(index: Int, element: E): E
abstract override fun removeAt(index: Int): E
abstract override fun add(index: Int, element: E)
}
@@ -0,0 +1,8 @@
@file:JvmVersion
package kotlin.collections
import java.util.AbstractMap
public abstract class AbstractMutableMap<K, V> protected constructor() : AbstractMap<K, V>() {
abstract override fun put(key: K, value: V): V?
}
@@ -0,0 +1,8 @@
@file:JvmVersion
package kotlin.collections
import java.util.AbstractSet
public abstract class AbstractMutableSet<E> protected constructor() : AbstractSet<E>() {
// nothing to make abstract, maybe leave it typealias then?
}
@@ -1,7 +0,0 @@
@file:JvmVersion
package kotlin.collections
public typealias AbstractMutableCollection<E> = java.util.AbstractCollection<E>
public typealias AbstractMutableList<E> = java.util.AbstractList<E>
public typealias AbstractMutableSet<E> = java.util.AbstractSet<E>
public typealias AbstractMutableMap<K, V> = java.util.AbstractMap<K, V>
@@ -149,6 +149,42 @@ public abstract class kotlin/collections/AbstractMap : java/util/Map, kotlin/jvm
public final fun values ()Ljava/util/Collection;
}
public abstract class kotlin/collections/AbstractMutableCollection : java/util/AbstractCollection {
protected fun <init> ()V
public abstract fun add (Ljava/lang/Object;)Z
public abstract fun getSize ()I
public final fun size ()I
}
public abstract class kotlin/collections/AbstractMutableList : java/util/AbstractList {
protected fun <init> ()V
public abstract fun add (ILjava/lang/Object;)V
public abstract fun getSize ()I
public final fun remove (I)Ljava/lang/Object;
public abstract fun removeAt (I)Ljava/lang/Object;
public abstract fun set (ILjava/lang/Object;)Ljava/lang/Object;
public final fun size ()I
}
public abstract class kotlin/collections/AbstractMutableMap : java/util/AbstractMap {
protected fun <init> ()V
public final fun entrySet ()Ljava/util/Set;
public abstract fun getEntries ()Ljava/util/Set;
public fun getKeys ()Ljava/util/Set;
public fun getSize ()I
public fun getValues ()Ljava/util/Collection;
public final fun keySet ()Ljava/util/Set;
public abstract fun put (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
public final fun size ()I
public final fun values ()Ljava/util/Collection;
}
public abstract class kotlin/collections/AbstractMutableSet : java/util/AbstractSet {
protected fun <init> ()V
public abstract fun getSize ()I
public final fun size ()I
}
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