From 8aed39d9bb43873ecce7d7de785e32a9aa77c638 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Thu, 15 Oct 2015 16:46:43 +0300 Subject: [PATCH] Provide *Raw methods as a replacement. --- .../kotlin/collections/MutableCollections.kt | 70 ++++++++++++++----- 1 file changed, 54 insertions(+), 16 deletions(-) diff --git a/libraries/stdlib/src/kotlin/collections/MutableCollections.kt b/libraries/stdlib/src/kotlin/collections/MutableCollections.kt index 4b1e055f7a7..5de6ae83a97 100644 --- a/libraries/stdlib/src/kotlin/collections/MutableCollections.kt +++ b/libraries/stdlib/src/kotlin/collections/MutableCollections.kt @@ -15,38 +15,76 @@ public inline fun Map<*, *>.size() = size @Deprecated("Use property 'key' instead", ReplaceWith("this.key")) public fun Map.Entry.getKey(): K = key + +@Deprecated("Use containsAllRaw() instead.", ReplaceWith("containsAllRaw(collection)")) +public fun Collection.containsAll(collection: Collection): Boolean = containsAllRaw(collection) + + +/* +@kotlin.jvm.JvmName("containsAny") +@Deprecated("Use containsRaw() instead.", ReplaceWith("containsRaw(element)")) +public operator fun Array.contains(element: Any?): Boolean = containsRaw(element) + + +@kotlin.jvm.JvmName("containsAny") +@Deprecated("Use containsRaw() instead.", ReplaceWith("containsRaw(element)")) +public operator fun Iterable<*>.contains(element: Any?): Boolean = containsRaw(element) + + +@kotlin.jvm.JvmName("containsAny") +@Deprecated("Use containsRaw() instead.", ReplaceWith("containsRaw(element)")) +public operator fun Sequence.contains(element: Any?): Boolean = containsRaw(element) +*/ + +/** + * Checks if all elements in the specified collection are contained in this collection. + */ +public fun Collection<*>.containsAllRaw(collection: Collection): Boolean = (this as Collection).containsAll(collection) + +public fun MutableCollection.removeRaw(element: Any?): Boolean = (this as MutableCollection).remove(element) + +public fun MutableCollection.removeAllRaw(collection: Collection): Boolean = (this as MutableCollection).removeAll(collection) + +public fun MutableCollection.retainAllRaw(collection: Collection): Boolean = (this as MutableCollection).retainAll(collection) + +public fun Map.getRaw(key: Any?): V? = (this as Map).get(key) + +public fun Map.containsKeyRaw(key: Any?): Boolean = (this as Map).containsKey(key) + +public fun Map.containsValueRaw(value: Any?): Boolean = (this as Map).containsValue(value) + @Deprecated("Use property 'value' instead", ReplaceWith("this.value")) public fun Map.Entry.getValue(): V = value @Deprecated("Use 'removeAt' instead", ReplaceWith("this.removeAt(index)")) public fun MutableList.remove(index: Int): E = removeAt(index) -@Deprecated("Use explicit cast to MutableCollection instead", ReplaceWith("(this as MutableCollection).remove(o)")) -public fun MutableCollection.remove(o: Any?): Boolean = remove(o as E) +@Deprecated("Use explicit cast to MutableCollection instead.", ReplaceWith("this.removeRaw(o)")) +public fun MutableCollection.remove(o: Any?): Boolean = removeRaw(o) -@Deprecated("Use explicit cast to MutableCollection instead", ReplaceWith("(this as MutableCollection).removeAll(c)")) -public fun MutableCollection.removeAll(c: Collection): Boolean = removeAll(c as Collection) +@Deprecated("Use explicit cast to MutableCollection instead", ReplaceWith("removeAllRaw(c)")) +public fun MutableCollection.removeAll(c: Collection): Boolean = removeAllRaw(c) -@Deprecated("Use explicit cast to MutableCollection instead", ReplaceWith("(this as MutableCollection).retainAll(c)")) -public fun MutableCollection.retainAll(c: Collection): Boolean = retainAll(c as Collection) +@Deprecated("Use explicit cast to MutableCollection instead", ReplaceWith("retainAllRaw(c)")) +public fun MutableCollection.retainAll(c: Collection): Boolean = retainAllRaw(c) -@Deprecated("Use explicit cast to List instead", ReplaceWith("(this as List).indexOf(o)")) -public fun List.indexOf(o: Any?): Int = indexOf(o as E) +@Deprecated("Use explicit cast to List instead", ReplaceWith("indexOfRaw(o)")) +public fun List.indexOf(o: Any?): Int = indexOfRaw(o) -@Deprecated("Use explicit cast to List instead", ReplaceWith("(this as List).lastIndexOf(o)")) -public fun List.lastIndexOf(o: Any?): Int = lastIndexOf(o as E) +@Deprecated("Use explicit cast to List instead", ReplaceWith("lastIndexOfRaw(o)")) +public fun List.lastIndexOf(o: Any?): Int = lastIndexOfRaw(o) @Deprecated("Use property 'length' instead", ReplaceWith("this.length")) public fun CharSequence.length(): Int = length -@Deprecated("Use explicit cast to Map instead", ReplaceWith("(this as Map).get(o)")) -public inline operator fun Map.get(o: Any?): V? = get(o as K) +@Deprecated("Use explicit cast to Map instead", ReplaceWith("getRaw(key)")) +public inline operator fun Map.get(key: Any?): V? = getRaw(key) -@Deprecated("Use explicit cast to Map instead", ReplaceWith("(this as Map).containsKey(o)")) -public inline fun Map.containsKey(o: Any?): Boolean = containsKey(o as K) +@Deprecated("Use explicit cast to Map instead", ReplaceWith("containsKeyRaw(key)")) +public inline fun Map.containsKey(key: Any?): Boolean = containsKeyRaw(key) -@Deprecated("Use explicit cast to Map instead", ReplaceWith("(this as Map).containsValue(o)")) -public inline fun Map.containsValue(o: Any?): Boolean = containsValue(o as V) +@Deprecated("Use explicit cast to Map instead", ReplaceWith("containsValueRaw(value)")) +public inline fun Map.containsValue(value: Any?): Boolean = containsValueRaw(value) @Deprecated("Use property 'keys' instead", ReplaceWith("this.keys")) public inline fun Map.keySet(): Set = keys