Drop previously deprecated API.

This commit is contained in:
Ilya Gorbunov
2016-02-05 16:14:16 +03:00
parent 434bd0707d
commit b4ebaad8f5
24 changed files with 7 additions and 1090 deletions
-313
View File
@@ -6115,94 +6115,6 @@ public inline fun <K, V, M : MutableMap<in K, in V>> CharArray.associateTo(desti
return destination
}
/**
* Returns an [ArrayList] of all elements.
*/
@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR)
public fun <T> Array<out T>.toArrayList(): ArrayList<T> {
return ArrayList(this.asCollection())
}
/**
* Returns an [ArrayList] of all elements.
*/
@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR)
public fun ByteArray.toArrayList(): ArrayList<Byte> {
val list = ArrayList<Byte>(size)
for (item in this) list.add(item)
return list
}
/**
* Returns an [ArrayList] of all elements.
*/
@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR)
public fun ShortArray.toArrayList(): ArrayList<Short> {
val list = ArrayList<Short>(size)
for (item in this) list.add(item)
return list
}
/**
* Returns an [ArrayList] of all elements.
*/
@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR)
public fun IntArray.toArrayList(): ArrayList<Int> {
val list = ArrayList<Int>(size)
for (item in this) list.add(item)
return list
}
/**
* Returns an [ArrayList] of all elements.
*/
@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR)
public fun LongArray.toArrayList(): ArrayList<Long> {
val list = ArrayList<Long>(size)
for (item in this) list.add(item)
return list
}
/**
* Returns an [ArrayList] of all elements.
*/
@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR)
public fun FloatArray.toArrayList(): ArrayList<Float> {
val list = ArrayList<Float>(size)
for (item in this) list.add(item)
return list
}
/**
* Returns an [ArrayList] of all elements.
*/
@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR)
public fun DoubleArray.toArrayList(): ArrayList<Double> {
val list = ArrayList<Double>(size)
for (item in this) list.add(item)
return list
}
/**
* Returns an [ArrayList] of all elements.
*/
@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR)
public fun BooleanArray.toArrayList(): ArrayList<Boolean> {
val list = ArrayList<Boolean>(size)
for (item in this) list.add(item)
return list
}
/**
* Returns an [ArrayList] of all elements.
*/
@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR)
public fun CharArray.toArrayList(): ArrayList<Char> {
val list = ArrayList<Char>(size)
for (item in this) list.add(item)
return list
}
/**
* Appends all elements to the given [destination] collection.
*/
@@ -6419,231 +6331,6 @@ public fun CharArray.toList(): List<Char> {
return this.toMutableList()
}
/**
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <T, K, V> Array<out T>.toMap(selector: (T) -> K, transform: (T) -> V): Map<K, V> {
return associateBy(selector, transform)
}
/**
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <K, V> ByteArray.toMap(selector: (Byte) -> K, transform: (Byte) -> V): Map<K, V> {
return associateBy(selector, transform)
}
/**
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <K, V> ShortArray.toMap(selector: (Short) -> K, transform: (Short) -> V): Map<K, V> {
return associateBy(selector, transform)
}
/**
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <K, V> IntArray.toMap(selector: (Int) -> K, transform: (Int) -> V): Map<K, V> {
return associateBy(selector, transform)
}
/**
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <K, V> LongArray.toMap(selector: (Long) -> K, transform: (Long) -> V): Map<K, V> {
return associateBy(selector, transform)
}
/**
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <K, V> FloatArray.toMap(selector: (Float) -> K, transform: (Float) -> V): Map<K, V> {
return associateBy(selector, transform)
}
/**
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <K, V> DoubleArray.toMap(selector: (Double) -> K, transform: (Double) -> V): Map<K, V> {
return associateBy(selector, transform)
}
/**
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <K, V> BooleanArray.toMap(selector: (Boolean) -> K, transform: (Boolean) -> V): Map<K, V> {
return associateBy(selector, transform)
}
/**
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given array.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <K, V> CharArray.toMap(selector: (Char) -> K, transform: (Char) -> V): Map<K, V> {
return associateBy(selector, transform)
}
@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("toMapOfPairs")
public inline fun <T, K, V> Array<out T>.toMap(transform: (T) -> Pair<K, V>): Map<K, V> {
return associate(transform)
}
@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("toMapOfPairs")
public inline fun <K, V> ByteArray.toMap(transform: (Byte) -> Pair<K, V>): Map<K, V> {
return associate(transform)
}
@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("toMapOfPairs")
public inline fun <K, V> ShortArray.toMap(transform: (Short) -> Pair<K, V>): Map<K, V> {
return associate(transform)
}
@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("toMapOfPairs")
public inline fun <K, V> IntArray.toMap(transform: (Int) -> Pair<K, V>): Map<K, V> {
return associate(transform)
}
@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("toMapOfPairs")
public inline fun <K, V> LongArray.toMap(transform: (Long) -> Pair<K, V>): Map<K, V> {
return associate(transform)
}
@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("toMapOfPairs")
public inline fun <K, V> FloatArray.toMap(transform: (Float) -> Pair<K, V>): Map<K, V> {
return associate(transform)
}
@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("toMapOfPairs")
public inline fun <K, V> DoubleArray.toMap(transform: (Double) -> Pair<K, V>): Map<K, V> {
return associate(transform)
}
@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("toMapOfPairs")
public inline fun <K, V> BooleanArray.toMap(transform: (Boolean) -> Pair<K, V>): Map<K, V> {
return associate(transform)
}
@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("toMapOfPairs")
public inline fun <K, V> CharArray.toMap(transform: (Char) -> Pair<K, V>): Map<K, V> {
return associate(transform)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR)
public inline fun <T, K> Array<out T>.toMapBy(selector: (T) -> K): Map<K, T> {
return associateBy(selector)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR)
public inline fun <K> ByteArray.toMapBy(selector: (Byte) -> K): Map<K, Byte> {
return associateBy(selector)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR)
public inline fun <K> ShortArray.toMapBy(selector: (Short) -> K): Map<K, Short> {
return associateBy(selector)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR)
public inline fun <K> IntArray.toMapBy(selector: (Int) -> K): Map<K, Int> {
return associateBy(selector)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR)
public inline fun <K> LongArray.toMapBy(selector: (Long) -> K): Map<K, Long> {
return associateBy(selector)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR)
public inline fun <K> FloatArray.toMapBy(selector: (Float) -> K): Map<K, Float> {
return associateBy(selector)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR)
public inline fun <K> DoubleArray.toMapBy(selector: (Double) -> K): Map<K, Double> {
return associateBy(selector)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR)
public inline fun <K> BooleanArray.toMapBy(selector: (Boolean) -> K): Map<K, Boolean> {
return associateBy(selector)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR)
public inline fun <K> CharArray.toMapBy(selector: (Char) -> K): Map<K, Char> {
return associateBy(selector)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <T, K, V> Array<out T>.toMapBy(selector: (T) -> K, transform: (T) -> V): Map<K, V> {
return associateBy(selector, transform)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <K, V> ByteArray.toMapBy(selector: (Byte) -> K, transform: (Byte) -> V): Map<K, V> {
return associateBy(selector, transform)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <K, V> ShortArray.toMapBy(selector: (Short) -> K, transform: (Short) -> V): Map<K, V> {
return associateBy(selector, transform)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <K, V> IntArray.toMapBy(selector: (Int) -> K, transform: (Int) -> V): Map<K, V> {
return associateBy(selector, transform)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <K, V> LongArray.toMapBy(selector: (Long) -> K, transform: (Long) -> V): Map<K, V> {
return associateBy(selector, transform)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <K, V> FloatArray.toMapBy(selector: (Float) -> K, transform: (Float) -> V): Map<K, V> {
return associateBy(selector, transform)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <K, V> DoubleArray.toMapBy(selector: (Double) -> K, transform: (Double) -> V): Map<K, V> {
return associateBy(selector, transform)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <K, V> BooleanArray.toMapBy(selector: (Boolean) -> K, transform: (Boolean) -> V): Map<K, V> {
return associateBy(selector, transform)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <K, V> CharArray.toMapBy(selector: (Char) -> K, transform: (Char) -> V): Map<K, V> {
return associateBy(selector, transform)
}
/**
* Returns a [MutableList] filled with all elements of this array.
*/
@@ -990,24 +990,6 @@ public inline fun <T, K, V, M : MutableMap<in K, in V>> Iterable<T>.associateTo(
return destination
}
/**
* Returns an [ArrayList] of all elements.
*/
@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR)
public fun <T> Iterable<T>.toArrayList(): ArrayList<T> {
if (this is Collection<T>)
return ArrayList(this)
return toCollection(ArrayList<T>())
}
/**
* Returns an [ArrayList] of all elements.
*/
@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR)
public fun <T> Collection<T>.toArrayList(): ArrayList<T> {
return ArrayList(this)
}
/**
* Appends all elements to the given [destination] collection.
*/
@@ -1032,31 +1014,6 @@ public fun <T> Iterable<T>.toList(): List<T> {
return this.toMutableList()
}
/**
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given collection.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <T, K, V> Iterable<T>.toMap(selector: (T) -> K, transform: (T) -> V): Map<K, V> {
return associateBy(selector, transform)
}
@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("toMapOfPairs")
public inline fun <T, K, V> Iterable<T>.toMap(transform: (T) -> Pair<K, V>): Map<K, V> {
return associate(transform)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR)
public inline fun <T, K> Iterable<T>.toMapBy(selector: (T) -> K): Map<K, T> {
return associateBy(selector)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <T, K, V> Iterable<T>.toMapBy(selector: (T) -> K, transform: (T) -> V): Map<K, V> {
return associateBy(selector, transform)
}
/**
* Returns a [MutableList] filled with all elements of this collection.
*/
@@ -488,14 +488,6 @@ public inline fun <T, K, V, M : MutableMap<in K, in V>> Sequence<T>.associateTo(
return destination
}
/**
* Returns an [ArrayList] of all elements.
*/
@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR)
public fun <T> Sequence<T>.toArrayList(): ArrayList<T> {
return toCollection(ArrayList<T>())
}
/**
* Appends all elements to the given [destination] collection.
*/
@@ -520,31 +512,6 @@ public fun <T> Sequence<T>.toList(): List<T> {
return this.toMutableList()
}
/**
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to elements of the given sequence.
* If any two elements would have the same key returned by [selector] the last one gets added to the map.
*/
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <T, K, V> Sequence<T>.toMap(selector: (T) -> K, transform: (T) -> V): Map<K, V> {
return associateBy(selector, transform)
}
@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("toMapOfPairs")
public inline fun <T, K, V> Sequence<T>.toMap(transform: (T) -> Pair<K, V>): Map<K, V> {
return associate(transform)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR)
public inline fun <T, K> Sequence<T>.toMapBy(selector: (T) -> K): Map<K, T> {
return associateBy(selector)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <T, K, V> Sequence<T>.toMapBy(selector: (T) -> K, transform: (T) -> V): Map<K, V> {
return associateBy(selector, transform)
}
/**
* Returns a [MutableList] filled with all elements of this sequence.
*/
@@ -563,14 +563,6 @@ public inline fun <K, V, M : MutableMap<in K, in V>> CharSequence.associateTo(de
return destination
}
/**
* Returns an [ArrayList] of all characters.
*/
@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR)
public fun CharSequence.toArrayList(): ArrayList<Char> {
return toCollection(ArrayList<Char>(length))
}
/**
* Appends all characters to the given [destination] collection.
*/
@@ -595,31 +587,6 @@ public fun CharSequence.toList(): List<Char> {
return this.toMutableList()
}
/**
* Returns a [Map] containing the values provided by [transform] and indexed by [selector] functions applied to characters of the given char sequence.
* If any two characters would have the same key returned by [selector] the last one gets added to the map.
*/
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <K, V> CharSequence.toMap(selector: (Char) -> K, transform: (Char) -> V): Map<K, V> {
return associateBy(selector, transform)
}
@Deprecated("Use associate instead.", ReplaceWith("associate(transform)"), level = DeprecationLevel.ERROR)
@kotlin.jvm.JvmName("toMapOfPairs")
public inline fun <K, V> CharSequence.toMap(transform: (Char) -> Pair<K, V>): Map<K, V> {
return associate(transform)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector)"), level = DeprecationLevel.ERROR)
public inline fun <K> CharSequence.toMapBy(selector: (Char) -> K): Map<K, Char> {
return associateBy(selector)
}
@Deprecated("Use associateBy instead.", ReplaceWith("associateBy(selector, transform)"), level = DeprecationLevel.ERROR)
public inline fun <K, V> CharSequence.toMapBy(selector: (Char) -> K, transform: (Char) -> V): Map<K, V> {
return associateBy(selector, transform)
}
/**
* Returns a [MutableList] filled with all characters of this char sequence.
*/
@@ -5,11 +5,6 @@ package kotlin.collections
import java.nio.charset.Charset
/**
* Converts the contents of this byte array to a string using the specified [charset].
*/
@Deprecated("Use ByteArray.toString(Charset) instead.", ReplaceWith("this.toString(charset(charset))"), level = DeprecationLevel.ERROR)
public fun ByteArray.toString(charset: String): String = String(this, charset(charset))
/**
* Converts the contents of this byte array to a string using the specified [charset].
@@ -74,16 +74,6 @@ public inline fun <T> listOf(): List<T> = emptyList()
@JvmVersion
public fun <T> listOf(element: T): List<T> = Collections.singletonList(element)
/** Returns a new [LinkedList] with the given elements. */
@JvmVersion
@Deprecated("Use LinkedList constructor.", ReplaceWith("LinkedList(listOf(*elements))", "java.util.LinkedList"), level = DeprecationLevel.ERROR)
public fun <T> linkedListOf(vararg elements: T): LinkedList<T>
= if (elements.size == 0) LinkedList() else LinkedList(ArrayAsCollection(elements))
@Deprecated("Use LinkedList constructor.", ReplaceWith("LinkedList<T>()", "java.util.LinkedList"), level = DeprecationLevel.ERROR)
public fun <T> linkedListOf() = LinkedList<T>()
/** Returns a new [MutableList] with the given elements. */
public fun <T> mutableListOf(vararg elements: T): MutableList<T>
= if (elements.size == 0) ArrayList() else ArrayList(ArrayAsCollection(elements))
@@ -398,12 +398,6 @@ public fun <K, V> Sequence<Pair<K, V>>.toMap(): Map<K, V> = toMap(LinkedHashMap<
public fun <K, V, M : MutableMap<in K, in V>> Sequence<Pair<K, V>>.toMap(destination: M): M
= destination.apply { putAll(this@toMap) }
/**
* Converts this [Map] to a [LinkedHashMap], maintaining the insertion order of elements added to that map afterwards.
*/
@Deprecated("It may be too late to convert map this map to linked map, if you care about the order use the ordered map from the beginning.", ReplaceWith("LinkedHashMap(this)", "java.util.LinkedHashMap"), level = DeprecationLevel.ERROR)
public fun <K, V> Map<K, V>.toLinkedMap(): MutableMap<K, V> = LinkedHashMap(this)
/**
* Creates a new read-only map by replacing or adding an entry to this map from a given key-value [pair].
*/
@@ -474,63 +468,3 @@ public inline operator fun <K, V> MutableMap<in K, in V>.plusAssign(pairs: Seque
public inline operator fun <K, V> MutableMap<in K, in V>.plusAssign(map: Map<K, V>) {
putAll(map)
}
/**
* Creates a new read-only map by removing a [key] from this map.
*/
@Deprecated("This operation is going to be removed. Copy this map to mutable map and then do result.keys -= key.", level = DeprecationLevel.ERROR)
public operator fun <K, V> Map<K, V>.minus(key: K): Map<K, V>
= LinkedHashMap(this).apply { keys.remove(key) }
/**
* Creates a new read-only map by removing a collection of [keys] from this map.
*/
@Deprecated("This operation is going to be removed. Copy this map to mutable map and then do result.keys -= keys.", level = DeprecationLevel.ERROR)
public operator fun <K, V> Map<K, V>.minus(keys: Iterable<K>): Map<K, V>
= LinkedHashMap(this).apply { for (key in keys) remove(key) }
/**
* Creates a new read-only map by removing a array of [keys] from this map.
*/
@Deprecated("This operation is going to be removed. Copy this map to mutable map and then do result.keys -= keys.", level = DeprecationLevel.ERROR)
public operator fun <K, V> Map<K, V>.minus(keys: Array<K>): Map<K, V>
= LinkedHashMap(this).apply { for (key in keys) remove(key) }
/**
* Creates a new read-only map by removing a sequence of [keys] from this map.
*/
@Deprecated("This operation is going to be removed. Copy this map to mutable map and then do result.keys -= keys.", level = DeprecationLevel.ERROR)
public operator fun <K, V> Map<K, V>.minus(keys: Sequence<K>): Map<K, V>
= LinkedHashMap(this).apply { for (key in keys) remove(key) }
/**
* Removes the given [key] from this mutable map.
*/
@Deprecated("This operation will be removed soon, use remove(key) instead.", ReplaceWith("this.keys -= key"), level = DeprecationLevel.ERROR)
public operator fun <K, V> MutableMap<K, V>.minusAssign(key: K) {
remove(key)
}
/**
* Removes all the given [keys] from this mutable map.
*/
@Deprecated("This operation will be removed soon.", ReplaceWith("this.keys -= keys"), level = DeprecationLevel.ERROR)
public operator fun <K, V> MutableMap<K, V>.minusAssign(keys: Iterable<K>) {
for (key in keys) remove(key)
}
/**
* Removes all the given [keys] from this mutable map.
*/
@Deprecated("This operation will be removed soon.", ReplaceWith("this.keys -= keys"), level = DeprecationLevel.ERROR)
public operator fun <K, V> MutableMap<K, V>.minusAssign(keys: Array<K>) {
for (key in keys) remove(key)
}
/**
* Removes all the given [keys] from this mutable map.
*/
@Deprecated("This operation will be removed soon.", ReplaceWith("this.keys -= keys"), level = DeprecationLevel.ERROR)
public operator fun <K, V> MutableMap<K, V>.minusAssign(keys: Sequence<K>) {
for (key in keys) remove(key)
}
@@ -35,12 +35,6 @@ public inline fun <K, V> ConcurrentMap<K, V>.getOrPut(key: K, defaultValue: () -
}
@Deprecated("Use getOrPut instead", ReplaceWith("getOrPut(key, defaultValue)"), level = DeprecationLevel.ERROR)
public inline fun <K, V: Any> ConcurrentMap<K, V>.concurrentGetOrPut(key: K, defaultValue: () -> V): V {
// Do not use computeIfAbsent on JVM8 as it would change locking behavior
return this.get(key) ?:
defaultValue().let { default -> this.putIfAbsent(key, default) ?: default }
}
/**
* Converts this [Map] to a [SortedMap] so iteration order will be in key order.
@@ -492,9 +492,6 @@ public fun <T : Any> generateSequence(nextFunction: () -> T?): Sequence<T> {
return GeneratorSequence(nextFunction, { nextFunction() }).constrainOnce()
}
@Deprecated("Use generateSequence instead.", ReplaceWith("generateSequence(nextFunction)"), level = DeprecationLevel.ERROR)
public fun <T : Any> sequence(nextFunction: () -> T?): Sequence<T> = generateSequence(nextFunction)
/**
* Returns a sequence which invokes the function to calculate the next value based on the previous one on each iteration
* until the function returns `null`. The sequence starts with the specified [seed].
@@ -508,10 +505,6 @@ public fun <T : Any> generateSequence(seed: T?, nextFunction: (T) -> T?): Sequen
else
GeneratorSequence({ seed }, nextFunction)
@Deprecated("Use generateSequence instead.", ReplaceWith("generateSequence(initialValue, nextFunction)"), level = DeprecationLevel.ERROR)
@kotlin.internal.LowPriorityInOverloadResolution
public fun <T : Any> sequence(initialValue: T?, nextFunction: (T) -> T?): Sequence<T> = generateSequence(initialValue, nextFunction)
/**
* Returns a sequence which invokes the function [seedFunction] to get the first item and then
* [nextFunction] to calculate the next value based on the previous one on each iteration
@@ -520,6 +513,3 @@ public fun <T : Any> sequence(initialValue: T?, nextFunction: (T) -> T?): Sequen
public fun <T: Any> generateSequence(seedFunction: () -> T?, nextFunction: (T) -> T?): Sequence<T> =
GeneratorSequence(seedFunction, nextFunction)
@Deprecated("Use generateSequence instead.", ReplaceWith("generateSequence(initialValueFunction, nextFunction)"), level = DeprecationLevel.ERROR)
public fun <T: Any> sequence(initialValueFunction: () -> T?, nextFunction: (T) -> T?): Sequence<T> = generateSequence(initialValueFunction, nextFunction)
@@ -2,13 +2,6 @@
@file:JvmName("ThreadsKt")
package kotlin.concurrent
/**
* Returns the current thread.
*/
@Deprecated("Use Thread.currentThread()", ReplaceWith("Thread.currentThread()"), level = DeprecationLevel.ERROR)
public val currentThread: Thread
get() = Thread.currentThread()
/**
* Creates a thread that runs the specified [block] of code.
*
@@ -8,9 +8,6 @@ package kotlin.io
public const val DEFAULT_BUFFER_SIZE: Int = 64 * 1024
@Deprecated("Use DEFAULT_BUFFER_SIZE constant instead.", ReplaceWith("kotlin.io.DEFAULT_BUFFER_SIZE"), level = DeprecationLevel.ERROR)
public val defaultBufferSize: Int = DEFAULT_BUFFER_SIZE
/**
* Returns the default block size for forEachBlock().
*/
@@ -66,17 +66,6 @@ public fun File.writeBytes(array: ByteArray): Unit = FileOutputStream(this).use
*/
public fun File.appendBytes(array: ByteArray): Unit = FileOutputStream(this, true).use { it.write(array) }
/**
* Gets the entire content of this file as a String using specified [charset].
*
* This method is not recommended on huge files. It has an internal limitation of 2 GB file size.
*
* @param charset character set to use.
* @return the entire content of this file as a String.
*/
@Deprecated("Use File.readText(Charset) instead.", ReplaceWith("this.readText(charset(charset))"), level = DeprecationLevel.ERROR)
public fun File.readText(charset: String): String = readBytes().toString(charset(charset))
/**
* Gets the entire content of this file as a String using UTF-8 or specified [charset].
*
@@ -87,16 +76,6 @@ public fun File.readText(charset: String): String = readBytes().toString(charset
*/
public fun File.readText(charset: Charset = Charsets.UTF_8): String = readBytes().toString(charset)
/**
* Sets the content of this file as [text] encoded using the specified [charset].
* If this file exists, it becomes overwritten.
*
* @param text text to write into file.
* @param charset character set to use.
*/
@Deprecated("Use File.writeText(String, Charset) instead.", ReplaceWith("this.writeText(text, charset(charset))"), level = DeprecationLevel.ERROR)
public fun File.writeText(text: String, charset: String): Unit = writeBytes(text.toByteArray(charset(charset)))
/**
* Sets the content of this file as [text] encoded using UTF-8 or specified [charset].
* If this file exists, it becomes overwritten.
@@ -114,15 +93,6 @@ public fun File.writeText(text: String, charset: Charset = Charsets.UTF_8): Unit
*/
public fun File.appendText(text: String, charset: Charset = Charsets.UTF_8): Unit = appendBytes(text.toByteArray(charset))
/**
* Appends [text] to the content of the file using the specified [charset].
*
* @param text text to append to file.
* @param charset character set to use.
*/
@Deprecated("Use File.appendText(String, Charset) instead.", ReplaceWith("this.appendText(text, charset(charset))"), level = DeprecationLevel.ERROR)
public fun File.appendText(text: String, charset: String): Unit = appendBytes(text.toByteArray(charset(charset)))
/**
* Reads file by byte blocks and calls [action] for each block read.
* Block has default size which is implementation-dependent.
@@ -134,9 +104,6 @@ public fun File.appendText(text: String, charset: String): Unit = appendBytes(te
*/
public fun File.forEachBlock(action: (ByteArray, Int) -> Unit): Unit = forEachBlock(defaultBlockSize, action)
@Deprecated("Use forEachBlock with blockSize as a first parameter.", ReplaceWith("forEachBlock(blockSize, action)"), level = DeprecationLevel.ERROR)
public fun File.forEachBlock(action: (ByteArray, Int) -> Unit, blockSize: Int): Unit
= forEachBlock(blockSize, action)
/**
* Reads file by byte blocks and calls [action] for each block read.
* This functions passes the byte array and amount of bytes in the array to the [action] function.
@@ -178,28 +145,6 @@ public fun File.forEachLine(charset: Charset = Charsets.UTF_8, action: (line: St
BufferedReader(InputStreamReader(FileInputStream(this), charset)).forEachLine(action)
}
/**
* Reads this file line by line using the specified [charset] and calls [operation] for each line.
*
* You may use this function on huge files.
*
* @param charset character set to use.
* @param operation function to process file lines.
*/
@Deprecated("Use File.forEachLine(Charset, operation) instead.", ReplaceWith("this.forEachLine(charset(charset), operation)"), level = DeprecationLevel.ERROR)
public fun File.forEachLine(charset: String, operation: (line: String) -> Unit): Unit = forEachLine(Charset.forName(charset), operation)
/**
* Reads the file content as a list of lines, using the specified [charset].
*
* Do not use this function for huge files.
*
* @param charset character set to use.
* @return list of file lines.
*/
@Deprecated("Use File.readLines(Charset) instead.", ReplaceWith("this.readLines(charset(charset))"), level = DeprecationLevel.ERROR)
public fun File.readLines(charset: String): List<String> = readLines(Charset.forName(charset))
/**
* Constructs a new FileInputStream of this file and returns it as a result.
*/
@@ -74,14 +74,6 @@ public inline fun InputStream.reader(charset: Charset = Charsets.UTF_8): InputSt
@kotlin.internal.InlineOnly
public inline fun InputStream.bufferedReader(charset: Charset = Charsets.UTF_8): BufferedReader = reader(charset).buffered()
/** Creates a reader on this input stream using the specified [charset]. */
@Deprecated("Use InputStream.reader(Charset) instead.", ReplaceWith("this.reader(charset(charset))"), level = DeprecationLevel.ERROR)
public fun InputStream.reader(charset: String): InputStreamReader = InputStreamReader(this, charset)
/** Creates a buffered reader on this input stream using the specified [charset]. */
@Deprecated("Use InputStream.bufferedReader(Charset) instead.", ReplaceWith("this.bufferedReader(charset(charset))"), level = DeprecationLevel.ERROR)
public fun InputStream.bufferedReader(charset: String): BufferedReader = reader(charset(charset)).buffered()
/**
* Creates a buffered output stream wrapping this stream.
* @param bufferSize the buffer size to use.
@@ -98,14 +90,6 @@ public inline fun OutputStream.writer(charset: Charset = Charsets.UTF_8): Output
@kotlin.internal.InlineOnly
public inline fun OutputStream.bufferedWriter(charset: Charset = Charsets.UTF_8): BufferedWriter = writer(charset).buffered()
/** Creates a writer on this output stream using the specified [charset]. */
@Deprecated("Use OutputStream.writer(Charset) instead.", ReplaceWith("this.writer(charset(charset))"), level = DeprecationLevel.ERROR)
public fun OutputStream.writer(charset: String): OutputStreamWriter = OutputStreamWriter(this, charset)
/** Creates a buffered writer on this output stream using the specified [charset]. */
@Deprecated("Use OutputStream.bufferedWriter(Charset) instead.", ReplaceWith("this.bufferedWriter(charset(charset))"), level = DeprecationLevel.ERROR)
public fun OutputStream.bufferedWriter(charset: String): BufferedWriter = writer(charset(charset)).buffered()
/**
* Copies this stream to the given output stream, returning the number of bytes copied
*
@@ -122,17 +122,6 @@ public fun Reader.copyTo(out: Writer, bufferSize: Int = DEFAULT_BUFFER_SIZE): Lo
return charsCopied
}
/**
* Reads the entire content of this URL as a String using the specified [charset].
*
* This method is not recommended on huge files.
*
* @param charset a character set to use.
* @return a string with this URL entire content.
*/
@Deprecated("Use URL.readText(Charset) instead.", ReplaceWith("this.readText(charset(charset))"), level = DeprecationLevel.ERROR)
public fun URL.readText(charset: String): String = readBytes().toString(charset(charset))
/**
* Reads the entire content of this URL as a String using UTF-8 or the specified [charset].
*
@@ -87,10 +87,6 @@ public fun File.toRelativeString(base: File): String
*/
public fun File.relativeTo(base: File): File = File(this.toRelativeString(base))
@Deprecated("Use relativeTo instead.", ReplaceWith("this.relativeTo(base)"), level = DeprecationLevel.ERROR)
public fun File.relativeToFile(base: File): File = File(this.toRelativeString(base))
/**
* Calculates the relative path for this file from [base] file.
* Note that the [base] file is treated as a directory.
@@ -19,9 +19,3 @@ public inline fun measureNanoTime(block: () -> Unit) : Long {
block()
return System.nanoTime() - start
}
/**
* Executes the given block and returns elapsed time in nanoseconds.
*/
@Deprecated("Use measureNanoTime.", ReplaceWith("measureNanoTime(block)"), level = DeprecationLevel.ERROR)
public inline fun measureTimeNano(block: () -> Unit) : Long = measureNanoTime(block)
@@ -199,18 +199,6 @@ public fun String.endsWith(suffix: String, ignoreCase: Boolean = false): Boolean
// "constructors" for String
/**
* Converts the data from a portion of the specified array of bytes to characters using the specified character set
* and returns the conversion result as a string.
*
* @param bytes the source array for the conversion.
* @param offset the offset in the array of the data to be converted.
* @param length the number of bytes to be converted.
* @param charsetName the name of the character set to use.
*/
@Deprecated("Use String(bytes, offset, length, Charset) instead.", ReplaceWith("String(bytes, offset, length, charset(charsetName))"), level = DeprecationLevel.ERROR)
public fun String(bytes: ByteArray, offset: Int, length: Int, charsetName: String): String = java.lang.String(bytes, offset, length, charsetName) as String
/**
* Converts the data from a portion of the specified array of bytes to characters using the specified character set
* and returns the conversion result as a string.
@@ -223,13 +211,6 @@ public fun String(bytes: ByteArray, offset: Int, length: Int, charsetName: Strin
@kotlin.internal.InlineOnly
public inline fun String(bytes: ByteArray, offset: Int, length: Int, charset: Charset): String = java.lang.String(bytes, offset, length, charset) as String
/**
* Converts the data from the specified array of bytes to characters using the specified character set
* and returns the conversion result as a string.
*/
@Deprecated("Use String(bytes, Charset) instead.", ReplaceWith("String(bytes, charset(charsetName))"), level = DeprecationLevel.ERROR)
public fun String(bytes: ByteArray, charsetName: String): String = java.lang.String(bytes, charsetName) as String
/**
* Converts the data from the specified array of bytes to characters using the specified character set
* and returns the conversion result as a string.
@@ -313,12 +294,6 @@ public fun String.compareTo(other: String, ignoreCase: Boolean = false): Int {
return (this as java.lang.String).compareTo(other)
}
/**
* Returns a new string obtained by concatenating this string and the specified string.
*/
@Deprecated("Use this + other, eventually it will be optimized as concat.", ReplaceWith("this + other"), level = DeprecationLevel.ERROR)
public fun String.concat(other: String): String = (this as java.lang.String).concat(other)
/**
* Returns `true` if this string is equal to the contents of the specified CharSequence.
*/
@@ -435,12 +410,6 @@ public inline fun String.toFloat(): Float = java.lang.Float.parseFloat(this)
@kotlin.internal.InlineOnly
public inline fun String.toDouble(): Double = java.lang.Double.parseDouble(this)
/**
* Encodes the contents of this string using the specified character set and returns the resulting byte array.
*/
@Deprecated("Use String.toByteArray(Charset) instead.", ReplaceWith("this.toByteArray(charset(charset))"), level = DeprecationLevel.ERROR)
public fun String.toByteArray(charset: String): ByteArray = (this as java.lang.String).getBytes(charset)
/**
* Encodes the contents of this string using the specified character set and returns the resulting byte array.
*/
@@ -495,33 +464,6 @@ public fun CharSequence.repeat(n: Int): String {
return sb.toString()
}
/**
* Appends the contents of this char sequence, excluding the first characters that satisfy the given [predicate],
* to the given Appendable.
*/
@Deprecated("This function will be removed soon.", ReplaceWith("result.append(this.dropWhile(predicate))"), level = DeprecationLevel.ERROR)
public inline fun <T : Appendable> CharSequence.dropWhileTo(result: T, predicate: (Char) -> Boolean): T {
var start = true
for (element in this) {
if (start && predicate(element)) {
// ignore
} else {
start = false
result.append(element)
}
}
return result
}
/**
* Appends the first characters from this char sequence that satisfy the given [predicate] to the given Appendable.
*/
@Deprecated("This function will be removed soon.", ReplaceWith("result.append(this.takeWhile(predicate))"), level = DeprecationLevel.ERROR)
public inline fun <T : Appendable> CharSequence.takeWhileTo(result: T, predicate: (Char) -> Boolean): T {
for (c in this) if (predicate(c)) result.append(c) else break
return result
}
/**
* A Comparator that orders strings ignoring character case.
@@ -1,330 +0,0 @@
/*
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:kotlin.jvm.JvmName("ComparisonsKt")
@file:Suppress("DEPRECATION_ERROR")
package kotlin
import java.util.Comparator
/**
* Compares two values using the specified functions [selectors] to calculate the result of the comparison.
* The functions are called sequentially, receive the given values [a] and [b] and return [Comparable]
* objects. As soon as the [Comparable] instances returned by a function for [a] and [b] values do not
* compare as equal, the result of that comparison is returned.
*/
@Deprecated("Use compareValuesBy from kotlin.comparisons package.", ReplaceWith("compareValuesBy(a, b, *selectors)", "kotlin.comparisons.compareValuesBy"), level = DeprecationLevel.ERROR)
public fun <T> compareValuesBy(a: T, b: T, vararg selectors: (T) -> Comparable<*>?): Int {
require(selectors.size > 0)
for (fn in selectors) {
val v1 = fn(a)
val v2 = fn(b)
val diff = compareValues(v1, v2)
if (diff != 0) return diff
}
return 0
}
/**
* Compares two values using the specified [selector] function to calculate the result of the comparison.
* The function is applied to the given values [a] and [b] and return [Comparable] objects.
* The result of comparison of these [Comparable] instances is returned.
*/
@Deprecated("Use compareValuesBy from kotlin.comparisons package.", ReplaceWith("compareValuesBy(a, b, selector)", "kotlin.comparisons.compareValuesBy"), level = DeprecationLevel.ERROR)
public inline fun <T> compareValuesBy(a: T, b: T, selector: (T) -> Comparable<*>?): Int {
return compareValues(selector(a), selector(b))
}
/**
* Compares two values using the specified [selector] function to calculate the result of the comparison.
* The function is applied to the given values [a] and [b] and return objects of type K which are then being
* compared with the given [comparator].
*/
@Deprecated("Use compareValuesBy from kotlin.comparisons package.", ReplaceWith("compareValuesBy(a, b, comparator, selector)", "kotlin.comparisons.compareValuesBy"), level = DeprecationLevel.ERROR)
public inline fun <T, K> compareValuesBy(a: T, b: T, comparator: Comparator<in K>, selector: (T) -> K): Int {
return comparator.compare(selector(a), selector(b))
}
//// Not so useful without type inference for receiver of expression
//// compareValuesWith(v1, v2, compareBy { it.prop1 } thenByDescending { it.prop2 })
///**
// * Compares two values using the specified [comparator].
// */
//@Suppress("NOTHING_TO_INLINE")
//public inline fun <T> compareValuesWith(a: T, b: T, comparator: Comparator<T>): Int = comparator.compare(a, b)
//
/**
* Compares two nullable [Comparable] values. Null is considered less than any value.
*/
@Deprecated("Use compareValues from kotlin.comparisons package.", ReplaceWith("compareValues(a, b)", "kotlin.comparisons.compareValues"), level = DeprecationLevel.ERROR)
public fun <T : Comparable<*>> compareValues(a: T?, b: T?): Int {
if (a === b) return 0
if (a == null) return -1
if (b == null) return 1
return (a as Comparable<Any>).compareTo(b)
}
/**
* Creates a comparator using the sequence of functions to calculate a result of comparison.
* The functions are called sequentially, receive the given values `a` and `b` and return [Comparable]
* objects. As soon as the [Comparable] instances returned by a function for `a` and `b` values do not
* compare as equal, the result of that comparison is returned from the [Comparator].
*/
@Deprecated("Use compareBy from kotlin.comparisons package.", ReplaceWith("compareBy(*selectors)", "kotlin.comparisons.compareBy"), level = DeprecationLevel.ERROR)
public fun <T> compareBy(vararg selectors: (T) -> Comparable<*>?): Comparator<T> {
return object : Comparator<T> {
public override fun compare(a: T, b: T): Int = compareValuesBy(a, b, *selectors)
}
}
/**
* Creates a comparator using the function to transform value to a [Comparable] instance for comparison.
*/
@Deprecated("Use compareBy from kotlin.comparisons package.", ReplaceWith("compareBy(selector)", "kotlin.comparisons.compareBy"), level = DeprecationLevel.ERROR)
inline public fun <T> compareBy(crossinline selector: (T) -> Comparable<*>?): Comparator<T> {
return object : Comparator<T> {
public override fun compare(a: T, b: T): Int = compareValuesBy(a, b, selector)
}
}
/**
* Creates a comparator using the [selector] function to transform values being compared and then applying
* the specified [comparator] to compare transformed values.
*/
@Deprecated("Use compareBy from kotlin.comparisons package.", ReplaceWith("compareBy(comparator, selector)", "kotlin.comparisons.compareBy"), level = DeprecationLevel.ERROR)
inline public fun <T, K> compareBy(comparator: Comparator<in K>, crossinline selector: (T) -> K): Comparator<T> {
return object : Comparator<T> {
public override fun compare(a: T, b: T): Int = compareValuesBy(a, b, comparator, selector)
}
}
/**
* Creates a descending comparator using the function to transform value to a [Comparable] instance for comparison.
*/
@Deprecated("Use compareByDescending from kotlin.comparisons package.", ReplaceWith("compareByDescending(selector)", "kotlin.comparisons.compareByDescending"), level = DeprecationLevel.ERROR)
inline public fun <T> compareByDescending(crossinline selector: (T) -> Comparable<*>?): Comparator<T> {
return object : Comparator<T> {
public override fun compare(a: T, b: T): Int = compareValuesBy(b, a, selector)
}
}
/**
* Creates a descending comparator using the [selector] function to transform values being compared and then applying
* the specified [comparator] to compare transformed values.
*
* Note that an order of [comparator] is reversed by this wrapper.
*/
@Deprecated("Use compareByDescending from kotlin.comparisons package.", ReplaceWith("compareByDescending(comparator, selector)", "kotlin.comparisons.compareByDescending"), level = DeprecationLevel.ERROR)
inline public fun <T, K> compareByDescending(comparator: Comparator<in K>, crossinline selector: (T) -> K): Comparator<T> {
return object : Comparator<T> {
public override fun compare(a: T, b: T): Int = compareValuesBy(b, a, comparator, selector)
}
}
/**
* Creates a comparator comparing values after the primary comparator defined them equal. It uses
* the function to transform value to a [Comparable] instance for comparison.
*/
@Deprecated("Use thenBy from kotlin.comparisons package.", ReplaceWith("this.thenBy(selector)", "kotlin.comparisons.thenBy"), level = DeprecationLevel.ERROR)
inline public fun <T> Comparator<T>.thenBy(crossinline selector: (T) -> Comparable<*>?): Comparator<T> {
return object : Comparator<T> {
public override fun compare(a: T, b: T): Int {
val previousCompare = this@thenBy.compare(a, b)
return if (previousCompare != 0) previousCompare else compareValuesBy(a, b, selector)
}
}
}
/**
* Creates a comparator comparing values after the primary comparator defined them equal. It uses
* the [selector] function to transform values and then compares them with the given [comparator].
*/
@Deprecated("Use thenBy from kotlin.comparisons package.", ReplaceWith("this.thenBy(comparator, selector)", "kotlin.comparisons.thenBy"), level = DeprecationLevel.ERROR)
inline public fun <T, K> Comparator<T>.thenBy(comparator: Comparator<in K>, crossinline selector: (T) -> K): Comparator<T> {
return object : Comparator<T> {
public override fun compare(a: T, b: T): Int {
val previousCompare = this@thenBy.compare(a, b)
return if (previousCompare != 0) previousCompare else compareValuesBy(a, b, comparator, selector)
}
}
}
/**
* Creates a descending comparator using the primary comparator and
* the function to transform value to a [Comparable] instance for comparison.
*/
@Deprecated("Use thenByDescending from kotlin.comparisons package.", ReplaceWith("this.thenByDescending(selector)", "kotlin.comparisons.thenByDescending"), level = DeprecationLevel.ERROR)
inline public fun <T> Comparator<T>.thenByDescending(crossinline selector: (T) -> Comparable<*>?): Comparator<T> {
return object : Comparator<T> {
public override fun compare(a: T, b: T): Int {
val previousCompare = this@thenByDescending.compare(a, b)
return if (previousCompare != 0) previousCompare else compareValuesBy(b, a, selector)
}
}
}
/**
* Creates a descending comparator comparing values after the primary comparator defined them equal. It uses
* the [selector] function to transform values and then compares them with the given [comparator].
*/
@Deprecated("Use thenByDescending from kotlin.comparisons package.", ReplaceWith("this.thenByDescending(comparator, selector)", "kotlin.comparisons.thenByDescending"), level = DeprecationLevel.ERROR)
inline public fun <T, K> Comparator<T>.thenByDescending(comparator: Comparator<in K>, crossinline selector: (T) -> K): Comparator<T> {
return object : Comparator<T> {
public override fun compare(a: T, b: T): Int {
val previousCompare = this@thenByDescending.compare(a, b)
return if (previousCompare != 0) previousCompare else compareValuesBy(b, a, comparator, selector)
}
}
}
/**
* Creates a comparator using the function to calculate a result of comparison.
*/
@Deprecated("Use Comparator SAM-constructor instead.", ReplaceWith("Comparator(comparison)", "java.util.Comparator"), level = DeprecationLevel.ERROR)
inline public fun <T> comparator(crossinline comparison: (T, T) -> Int) = Comparator<T> { a, b -> comparison(a, b) }
/**
* Creates a comparator using the primary comparator and function to calculate a result of comparison.
*/
@Deprecated("Use thenComparator from kotlin.comparisons package.", ReplaceWith("this.thenComparator(comparison)", "kotlin.comparisons.thenComparator"), level = DeprecationLevel.ERROR)
inline public fun <T> Comparator<T>.thenComparator(crossinline comparison: (T, T) -> Int): Comparator<T> {
return object : Comparator<T> {
public override fun compare(a: T, b: T): Int {
val previousCompare = this@thenComparator.compare(a, b)
return if (previousCompare != 0) previousCompare else comparison(a, b)
}
}
}
/**
* Combines this comparator and the given [comparator] such that the latter is applied only
* when the former considered values equal.
*/
@Deprecated("Use then from kotlin.comparisons package.", ReplaceWith("this.then(comparator)", "kotlin.comparisons.then"), level = DeprecationLevel.ERROR)
public infix fun <T> Comparator<T>.then(comparator: Comparator<in T>): Comparator<T> {
return object : Comparator<T> {
public override fun compare(a: T, b: T): Int {
val previousCompare = this@then.compare(a, b)
return if (previousCompare != 0) previousCompare else comparator.compare(a, b)
}
}
}
/**
* Combines this comparator and the given [comparator] such that the latter is applied only
* when the former considered values equal.
*/
@Deprecated("Use thenDescending from kotlin.comparisons package.", ReplaceWith("this.thenDescending(comparator)", "kotlin.comparisons.thenDescending"), level = DeprecationLevel.ERROR)
public infix fun <T> Comparator<T>.thenDescending(comparator: Comparator<in T>): Comparator<T> {
return object : Comparator<T> {
public override fun compare(a: T, b: T): Int {
val previousCompare = this@thenDescending.compare(a, b)
return if (previousCompare != 0) previousCompare else comparator.compare(b, a)
}
}
}
// Not so useful without type inference for receiver of expression
/**
* Extends the given [comparator] of non-nullable values to a comparator of nullable values
* considering `null` value less than any other value.
*/
@Deprecated("Use nullsFirst from kotlin.comparisons package.", ReplaceWith("nullsFirst(comparator)", "kotlin.comparisons.nullsFirst"), level = DeprecationLevel.ERROR)
public fun <T: Any> nullsFirst(comparator: Comparator<in T>): Comparator<T?> {
return object: Comparator<T?> {
override fun compare(a: T?, b: T?): Int {
if (a === b) return 0
if (a == null) return -1
if (b == null) return 1
return comparator.compare(a, b)
}
}
}
/**
* Provides a comparator of nullable [Comparable] values
* considering `null` value less than any other value.
*/
@Deprecated("Use nullsFirst from kotlin.comparisons package.", ReplaceWith("nullsFirst<T>()", "kotlin.comparisons.nullsFirst"), level = DeprecationLevel.ERROR)
public fun <T: Comparable<T>> nullsFirst(): Comparator<T?> = nullsFirst(naturalOrder())
/**
* Extends the given [comparator] of non-nullable values to a comparator of nullable values
* considering `null` value greater than any other value.
*/
@Deprecated("Use nullsLast from kotlin.comparisons package.", ReplaceWith("nullsLast(comparator)", "kotlin.comparisons.nullsLast"), level = DeprecationLevel.ERROR)
public fun <T: Any> nullsLast(comparator: Comparator<in T>): Comparator<T?> {
return object: Comparator<T?> {
override fun compare(a: T?, b: T?): Int {
if (a === b) return 0
if (a == null) return 1
if (b == null) return -1
return comparator.compare(a, b)
}
}
}
/**
* Provides a comparator of nullable [Comparable] values
* considering `null` value greater than any other value.
*/
@Deprecated("Use nullsLast from kotlin.comparisons package.", ReplaceWith("nullsLast<T>()", "kotlin.comparisons.nullsLast"), level = DeprecationLevel.ERROR)
public fun <T: Comparable<T>> nullsLast(): Comparator<T?> = nullsLast(naturalOrder())
/**
* Returns a comparator that compares [Comparable] objects in natural order.
*/
@Deprecated("Use naturalOrder from kotlin.comparisons package.", ReplaceWith("naturalOrder<T>()", "kotlin.comparisons.naturalOrder"), level = DeprecationLevel.ERROR)
public fun <T: Comparable<T>> naturalOrder(): Comparator<T> = NaturalOrderComparator as Comparator<T>
/**
* Returns a comparator that compares [Comparable] objects in reversed natural order.
*/
@Deprecated("Use reverseOrder from kotlin.comparisons package.", ReplaceWith("reverseOrder<T>()", "kotlin.comparisons.reverseOrder"), level = DeprecationLevel.ERROR)
public fun <T: Comparable<T>> reverseOrder(): Comparator<T> = ReverseOrderComparator as Comparator<T>
/** Returns a comparator that imposes the reverse ordering of this comparator. */
@Deprecated("Use reversed from kotlin.comparisons package.", ReplaceWith("this.reversed()", "kotlin.comparisons.reversed"), level = DeprecationLevel.ERROR)
public fun <T> Comparator<T>.reversed(): Comparator<T> = when (this) {
is ReversedComparator -> this.comparator
NaturalOrderComparator -> ReverseOrderComparator as Comparator<T>
ReverseOrderComparator -> NaturalOrderComparator as Comparator<T>
else -> ReversedComparator(this)
}
private class ReversedComparator<T>(public val comparator: Comparator<T>): Comparator<T> {
override fun compare(a: T, b: T): Int = comparator.compare(b, a)
@Suppress("VIRTUAL_MEMBER_HIDDEN")
fun reversed(): Comparator<T> = comparator
}
private object NaturalOrderComparator : Comparator<Comparable<Any>> {
override fun compare(c1: Comparable<Any>, c2: Comparable<Any>): Int = c1.compareTo(c2)
@Suppress("VIRTUAL_MEMBER_HIDDEN")
fun reversed(): Comparator<Comparable<Any>> = ReverseOrderComparator
}
private object ReverseOrderComparator: Comparator<Comparable<Any>> {
override fun compare(c1: Comparable<Any>, c2: Comparable<Any>): Int = c2.compareTo(c1)
@Suppress("VIRTUAL_MEMBER_HIDDEN")
fun reversed(): Comparator<Comparable<Any>> = NaturalOrderComparator
}