Remove deprecated declarations from project code, cleanup usages
This commit is contained in:
@@ -20,15 +20,6 @@ import java.lang.reflect.Modifier
|
||||
import java.util.*
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
@Deprecated("Use listOfNotNull(this) or this.let(::listOfNotNull) instead", ReplaceWith("listOfNotNull(this)"))
|
||||
fun <T: Any> T?.singletonOrEmptyList(): List<T> = if (this != null) Collections.singletonList(this) else Collections.emptyList()
|
||||
|
||||
@Deprecated("Use listOf(this) or this.let(::listOf) instead", ReplaceWith("listOf(this)"))
|
||||
fun <T> T.singletonList(): List<T> = Collections.singletonList(this)
|
||||
|
||||
@Deprecated("Use this?.let(::setOf).orEmpty() instead", ReplaceWith("this?.let(::setOf).orEmpty()"))
|
||||
fun <T: Any> T?.singletonOrEmptySet(): Set<T> = if (this != null) Collections.singleton(this) else Collections.emptySet()
|
||||
|
||||
inline fun <reified T : Any> Sequence<*>.firstIsInstanceOrNull(): T? {
|
||||
for (element in this) if (element is T) return element
|
||||
return null
|
||||
@@ -79,9 +70,6 @@ fun <T> sequenceOfLazyValues(vararg elements: () -> T): Sequence<T> = elements.a
|
||||
|
||||
fun <T1, T2> Pair<T1, T2>.swap(): Pair<T2, T1> = Pair(second, first)
|
||||
|
||||
@Deprecated("Use takeIf() instead.", ReplaceWith("this.takeIf(predicate)"))
|
||||
fun <T: Any> T.check(predicate: (T) -> Boolean): T? = if (predicate(this)) this else null
|
||||
|
||||
inline fun <reified T : Any> Any?.safeAs(): T? = this as? T
|
||||
inline fun <reified T : Any> Any?.cast(): T = this as T
|
||||
inline fun <reified T : Any> Any?.assertedCast(message: () -> String): T = this as? T ?: throw AssertionError(message())
|
||||
|
||||
@@ -57,14 +57,11 @@ inline fun <T, C: Collection<T>> C.ifEmpty(body: () -> C): C = if (isEmpty()) bo
|
||||
|
||||
inline fun <T> Array<out T>.ifEmpty(body: () -> Array<out T>): Array<out T> = if (isEmpty()) body() else this
|
||||
|
||||
@Deprecated("Use listOfNotNull instead", ReplaceWith("listOfNotNull(item)"))
|
||||
fun <T: Any> emptyOrSingletonList(item: T?): List<T> = listOfNotNull(item)
|
||||
|
||||
fun <T: Any> MutableCollection<T>.addIfNotNull(t: T?) {
|
||||
if (t != null) add(t)
|
||||
}
|
||||
|
||||
suspend fun <T: Any> SequenceBuilder<in T>.yieldIfNotNull(t: T?) = if (t != null) yield(t) else Unit
|
||||
suspend fun <T: Any> SequenceBuilder<T>.yieldIfNotNull(t: T?) = if (t != null) yield(t) else Unit
|
||||
|
||||
fun <K, V> newHashMapWithExpectedSize(expectedSize: Int): HashMap<K, V> =
|
||||
HashMap(capacity(expectedSize))
|
||||
@@ -81,14 +78,6 @@ fun <E> newLinkedHashSetWithExpectedSize(expectedSize: Int): LinkedHashSet<E> =
|
||||
private fun capacity(expectedSize: Int): Int =
|
||||
if (expectedSize < 3) 3 else expectedSize + expectedSize / 3 + 1
|
||||
|
||||
@Deprecated("Use toList(), it provides the same behavior for Collection", ReplaceWith("this.toList()"))
|
||||
fun <T> Collection<T>.toReadOnlyList(): List<T> =
|
||||
when (size) {
|
||||
0 -> emptyList()
|
||||
1 -> listOf(first())
|
||||
else -> ArrayList(this)
|
||||
}
|
||||
|
||||
fun <T> ArrayList<T>.compactIfPossible(): List<T> =
|
||||
when (size) {
|
||||
0 -> emptyList()
|
||||
@@ -96,10 +85,6 @@ fun <T> ArrayList<T>.compactIfPossible(): List<T> =
|
||||
else -> apply { trimToSize() }
|
||||
}
|
||||
|
||||
@Deprecated("Use listOfNotNull(this) or this.let(::listOfNotNull) instead", ReplaceWith("listOfNotNull(this)"))
|
||||
fun <T: Any> T?.singletonOrEmptyList(): List<T> =
|
||||
if (this != null) listOf(this) else emptyList()
|
||||
|
||||
fun <T> List<T>.indexOfFirst(startFrom: Int, predicate: (T) -> Boolean): Int {
|
||||
for (index in startFrom..lastIndex) {
|
||||
if (predicate(this[index])) return index
|
||||
|
||||
Reference in New Issue
Block a user