StdLib cleanup, deprecated symbol usage: size() and length()
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -464,7 +464,7 @@ public inline fun <T> List<T>.lastIndexOfRaw(element: Any?): Int {
|
||||
*/
|
||||
public fun <T> Iterable<T>.lastOrNull(): T? {
|
||||
when (this) {
|
||||
is List -> return if (isEmpty()) null else this[size() - 1]
|
||||
is List -> return if (isEmpty()) null else this[size - 1]
|
||||
else -> {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
@@ -481,7 +481,7 @@ public fun <T> Iterable<T>.lastOrNull(): T? {
|
||||
* Returns the last element, or `null` if the list is empty.
|
||||
*/
|
||||
public fun <T> List<T>.lastOrNull(): T? {
|
||||
return if (isEmpty()) null else this[size() - 1]
|
||||
return if (isEmpty()) null else this[size - 1]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -515,7 +515,7 @@ public inline fun <T> List<T>.lastOrNull(predicate: (T) -> Boolean): T? {
|
||||
*/
|
||||
public fun <T> Iterable<T>.single(): T {
|
||||
when (this) {
|
||||
is List -> return when (size()) {
|
||||
is List -> return when (size) {
|
||||
0 -> throw NoSuchElementException("Collection is empty.")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element.")
|
||||
@@ -536,7 +536,7 @@ public fun <T> Iterable<T>.single(): T {
|
||||
* Returns the single element, or throws an exception if the list is empty or has more than one element.
|
||||
*/
|
||||
public fun <T> List<T>.single(): T {
|
||||
return when (size()) {
|
||||
return when (size) {
|
||||
0 -> throw NoSuchElementException("Collection is empty.")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element.")
|
||||
@@ -565,7 +565,7 @@ public inline fun <T> Iterable<T>.single(predicate: (T) -> Boolean): T {
|
||||
*/
|
||||
public fun <T> Iterable<T>.singleOrNull(): T? {
|
||||
when (this) {
|
||||
is List -> return if (size() == 1) this[0] else null
|
||||
is List -> return if (size == 1) this[0] else null
|
||||
else -> {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
@@ -582,7 +582,7 @@ public fun <T> Iterable<T>.singleOrNull(): T? {
|
||||
* Returns single element, or `null` if the list is empty or has more than one element.
|
||||
*/
|
||||
public fun <T> List<T>.singleOrNull(): T? {
|
||||
return if (size() == 1) this[0] else null
|
||||
return if (size == 1) this[0] else null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -610,12 +610,12 @@ public fun <T> Iterable<T>.drop(n: Int): List<T> {
|
||||
if (n == 0) return toList()
|
||||
val list: ArrayList<T>
|
||||
if (this is Collection<*>) {
|
||||
val resultSize = size() - n
|
||||
val resultSize = size - n
|
||||
if (resultSize <= 0)
|
||||
return emptyList()
|
||||
list = ArrayList<T>(resultSize)
|
||||
if (this is List<T>) {
|
||||
for (index in n..size() - 1) {
|
||||
for (index in n..size - 1) {
|
||||
list.add(this[index])
|
||||
}
|
||||
return list
|
||||
@@ -636,7 +636,7 @@ public fun <T> Iterable<T>.drop(n: Int): List<T> {
|
||||
*/
|
||||
public fun <T> List<T>.dropLast(n: Int): List<T> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
return take((size() - n).coerceAtLeast(0))
|
||||
return take((size - n).coerceAtLeast(0))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -756,7 +756,7 @@ public fun <T> List<T>.slice(indices: Iterable<Int>): List<T> {
|
||||
public fun <T> Iterable<T>.take(n: Int): List<T> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
if (n == 0) return emptyList()
|
||||
if (this is Collection<T> && n >= size()) return toList()
|
||||
if (this is Collection<T> && n >= size) return toList()
|
||||
var count = 0
|
||||
val list = ArrayList<T>(n)
|
||||
for (item in this) {
|
||||
@@ -773,7 +773,7 @@ public fun <T> Iterable<T>.take(n: Int): List<T> {
|
||||
public fun <T> List<T>.takeLast(n: Int): List<T> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
if (n == 0) return emptyList()
|
||||
val size = size()
|
||||
val size = size
|
||||
if (n >= size) return toList()
|
||||
val list = ArrayList<T>(n)
|
||||
for (index in size - n .. size - 1)
|
||||
@@ -891,7 +891,7 @@ public fun <T> Iterable<T>.sortedWith(comparator: Comparator<in T>): List<T> {
|
||||
* Returns an array of Boolean containing all of the elements of this collection.
|
||||
*/
|
||||
public fun Collection<Boolean>.toBooleanArray(): BooleanArray {
|
||||
val result = BooleanArray(size())
|
||||
val result = BooleanArray(size)
|
||||
var index = 0
|
||||
for (element in this)
|
||||
result[index++] = element
|
||||
@@ -902,7 +902,7 @@ public fun Collection<Boolean>.toBooleanArray(): BooleanArray {
|
||||
* Returns an array of Byte containing all of the elements of this collection.
|
||||
*/
|
||||
public fun Collection<Byte>.toByteArray(): ByteArray {
|
||||
val result = ByteArray(size())
|
||||
val result = ByteArray(size)
|
||||
var index = 0
|
||||
for (element in this)
|
||||
result[index++] = element
|
||||
@@ -913,7 +913,7 @@ public fun Collection<Byte>.toByteArray(): ByteArray {
|
||||
* Returns an array of Char containing all of the elements of this collection.
|
||||
*/
|
||||
public fun Collection<Char>.toCharArray(): CharArray {
|
||||
val result = CharArray(size())
|
||||
val result = CharArray(size)
|
||||
var index = 0
|
||||
for (element in this)
|
||||
result[index++] = element
|
||||
@@ -924,7 +924,7 @@ public fun Collection<Char>.toCharArray(): CharArray {
|
||||
* Returns an array of Double containing all of the elements of this collection.
|
||||
*/
|
||||
public fun Collection<Double>.toDoubleArray(): DoubleArray {
|
||||
val result = DoubleArray(size())
|
||||
val result = DoubleArray(size)
|
||||
var index = 0
|
||||
for (element in this)
|
||||
result[index++] = element
|
||||
@@ -935,7 +935,7 @@ public fun Collection<Double>.toDoubleArray(): DoubleArray {
|
||||
* Returns an array of Float containing all of the elements of this collection.
|
||||
*/
|
||||
public fun Collection<Float>.toFloatArray(): FloatArray {
|
||||
val result = FloatArray(size())
|
||||
val result = FloatArray(size)
|
||||
var index = 0
|
||||
for (element in this)
|
||||
result[index++] = element
|
||||
@@ -946,7 +946,7 @@ public fun Collection<Float>.toFloatArray(): FloatArray {
|
||||
* Returns an array of Int containing all of the elements of this collection.
|
||||
*/
|
||||
public fun Collection<Int>.toIntArray(): IntArray {
|
||||
val result = IntArray(size())
|
||||
val result = IntArray(size)
|
||||
var index = 0
|
||||
for (element in this)
|
||||
result[index++] = element
|
||||
@@ -957,7 +957,7 @@ public fun Collection<Int>.toIntArray(): IntArray {
|
||||
* Returns an array of Long containing all of the elements of this collection.
|
||||
*/
|
||||
public fun Collection<Long>.toLongArray(): LongArray {
|
||||
val result = LongArray(size())
|
||||
val result = LongArray(size)
|
||||
var index = 0
|
||||
for (element in this)
|
||||
result[index++] = element
|
||||
@@ -968,7 +968,7 @@ public fun Collection<Long>.toLongArray(): LongArray {
|
||||
* Returns an array of Short containing all of the elements of this collection.
|
||||
*/
|
||||
public fun Collection<Short>.toShortArray(): ShortArray {
|
||||
val result = ShortArray(size())
|
||||
val result = ShortArray(size)
|
||||
var index = 0
|
||||
for (element in this)
|
||||
result[index++] = element
|
||||
@@ -1272,7 +1272,7 @@ public inline fun <T> Iterable<T>.any(predicate: (T) -> Boolean): Boolean {
|
||||
* Returns the number of elements in this collection.
|
||||
*/
|
||||
public fun <T> Collection<T>.count(): Int {
|
||||
return size()
|
||||
return size
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1543,7 +1543,7 @@ public inline fun <T> Iterable<T>.partition(predicate: (T) -> Boolean): Pair<Lis
|
||||
* Returns a list containing all elements of the original collection and then all elements of the given [array].
|
||||
*/
|
||||
public operator fun <T> Collection<T>.plus(array: Array<out T>): List<T> {
|
||||
val result = ArrayList<T>(this.size() + array.size())
|
||||
val result = ArrayList<T>(this.size + array.size)
|
||||
result.addAll(this)
|
||||
result.addAll(array)
|
||||
return result
|
||||
@@ -1565,7 +1565,7 @@ public operator fun <T> Iterable<T>.plus(array: Array<out T>): List<T> {
|
||||
*/
|
||||
public operator fun <T> Collection<T>.plus(collection: Iterable<T>): List<T> {
|
||||
if (collection is Collection) {
|
||||
val result = ArrayList<T>(this.size() + collection.size())
|
||||
val result = ArrayList<T>(this.size + collection.size)
|
||||
result.addAll(this)
|
||||
result.addAll(collection)
|
||||
return result
|
||||
@@ -1591,7 +1591,7 @@ public operator fun <T> Iterable<T>.plus(collection: Iterable<T>): List<T> {
|
||||
* Returns a list containing all elements of the original collection and then the given [element].
|
||||
*/
|
||||
public operator fun <T> Collection<T>.plus(element: T): List<T> {
|
||||
val result = ArrayList<T>(size() + 1)
|
||||
val result = ArrayList<T>(size + 1)
|
||||
result.addAll(this)
|
||||
result.add(element)
|
||||
return result
|
||||
@@ -1612,7 +1612,7 @@ public operator fun <T> Iterable<T>.plus(element: T): List<T> {
|
||||
* Returns a list containing all elements of the original collection and then all elements of the given [sequence].
|
||||
*/
|
||||
public operator fun <T> Collection<T>.plus(sequence: Sequence<T>): List<T> {
|
||||
val result = ArrayList<T>(this.size() + 10)
|
||||
val result = ArrayList<T>(this.size + 10)
|
||||
result.addAll(this)
|
||||
result.addAll(sequence)
|
||||
return result
|
||||
@@ -1639,7 +1639,7 @@ public fun <T, R> Iterable<T>.zip(array: Array<out R>): List<Pair<T, R>> {
|
||||
* Returns a list of values built from elements of both collections with same indexes using provided [transform]. List has length of shortest collection.
|
||||
*/
|
||||
public inline fun <T, R, V> Iterable<T>.zip(array: Array<out R>, transform: (T, R) -> V): List<V> {
|
||||
val arraySize = array.size()
|
||||
val arraySize = array.size
|
||||
val list = ArrayList<V>(Math.min(collectionSizeOrDefault(10), arraySize))
|
||||
var i = 0
|
||||
for (element in this) {
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.util.Collections // TODO: it's temporary while we have java.util.Col
|
||||
* Returns a [List] containing all key-value pairs.
|
||||
*/
|
||||
public fun <K, V> Map<K, V>.toList(): List<Pair<K, V>> {
|
||||
val result = ArrayList<Pair<K, V>>(size())
|
||||
val result = ArrayList<Pair<K, V>>(size)
|
||||
for (item in this)
|
||||
result.add(item.key to item.value)
|
||||
return result
|
||||
@@ -45,7 +45,7 @@ public inline fun <K, V, R, C : MutableCollection<in R>> Map<K, V>.flatMapTo(des
|
||||
* to each entry in the original map.
|
||||
*/
|
||||
public inline fun <K, V, R> Map<K, V>.map(transform: (Map.Entry<K, V>) -> R): List<R> {
|
||||
return mapTo(ArrayList<R>(size()), transform)
|
||||
return mapTo(ArrayList<R>(size), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,7 +115,7 @@ public inline fun <K, V> Map<K, V>.any(predicate: (Map.Entry<K, V>) -> Boolean):
|
||||
* Returns the number of entrys in this map.
|
||||
*/
|
||||
public fun <K, V> Map<K, V>.count(): Int {
|
||||
return size()
|
||||
return size
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,7 +39,7 @@ public operator fun <T> Set<T>.minus(collection: Iterable<T>): Set<T> {
|
||||
* Returns a set containing all elements of the original set except the given [element].
|
||||
*/
|
||||
public operator fun <T> Set<T>.minus(element: T): Set<T> {
|
||||
val result = LinkedHashSet<T>(mapCapacity(size()))
|
||||
val result = LinkedHashSet<T>(mapCapacity(size))
|
||||
var removed = false
|
||||
return this.filterTo(result) { if (!removed && it == element) { removed = true; false } else true }
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public operator fun <T> Set<T>.minus(sequence: Sequence<T>): Set<T> {
|
||||
* Returns a set containing all elements both of the original set and the given [array].
|
||||
*/
|
||||
public operator fun <T> Set<T>.plus(array: Array<out T>): Set<T> {
|
||||
val result = LinkedHashSet<T>(mapCapacity(this.size() + array.size()))
|
||||
val result = LinkedHashSet<T>(mapCapacity(this.size + array.size))
|
||||
result.addAll(this)
|
||||
result.addAll(array)
|
||||
return result
|
||||
@@ -67,7 +67,7 @@ public operator fun <T> Set<T>.plus(array: Array<out T>): Set<T> {
|
||||
* Returns a set containing all elements both of the original set and the given [collection].
|
||||
*/
|
||||
public operator fun <T> Set<T>.plus(collection: Iterable<T>): Set<T> {
|
||||
val result = LinkedHashSet<T>(mapCapacity(collection.collectionSizeOrNull()?.let { this.size() + it } ?: this.size() * 2))
|
||||
val result = LinkedHashSet<T>(mapCapacity(collection.collectionSizeOrNull()?.let { this.size + it } ?: this.size * 2))
|
||||
result.addAll(this)
|
||||
result.addAll(collection)
|
||||
return result
|
||||
@@ -77,7 +77,7 @@ public operator fun <T> Set<T>.plus(collection: Iterable<T>): Set<T> {
|
||||
* Returns a set containing all elements of the original set and then the given [element].
|
||||
*/
|
||||
public operator fun <T> Set<T>.plus(element: T): Set<T> {
|
||||
val result = LinkedHashSet<T>(mapCapacity(size() + 1))
|
||||
val result = LinkedHashSet<T>(mapCapacity(size + 1))
|
||||
result.addAll(this)
|
||||
result.add(element)
|
||||
return result
|
||||
@@ -87,7 +87,7 @@ public operator fun <T> Set<T>.plus(element: T): Set<T> {
|
||||
* Returns a set containing all elements both of the original set and the given [sequence].
|
||||
*/
|
||||
public operator fun <T> Set<T>.plus(sequence: Sequence<T>): Set<T> {
|
||||
val result = LinkedHashSet<T>(mapCapacity(this.size() * 2))
|
||||
val result = LinkedHashSet<T>(mapCapacity(this.size * 2))
|
||||
result.addAll(this)
|
||||
result.addAll(sequence)
|
||||
return result
|
||||
|
||||
@@ -289,7 +289,7 @@ public inline fun String.last(predicate: (Char) -> Boolean): Char {
|
||||
* Returns the last character, or `null` if the char sequence is empty.
|
||||
*/
|
||||
public fun CharSequence.lastOrNull(): Char? {
|
||||
return if (isEmpty()) null else this[length() - 1]
|
||||
return if (isEmpty()) null else this[length - 1]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -297,7 +297,7 @@ public fun CharSequence.lastOrNull(): Char? {
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.lastOrNull(): Char? {
|
||||
return if (isEmpty()) null else this[length() - 1]
|
||||
return if (isEmpty()) null else this[length - 1]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -327,7 +327,7 @@ public inline fun String.lastOrNull(predicate: (Char) -> Boolean): Char? {
|
||||
* Returns the single character, or throws an exception if the char sequence is empty or has more than one character.
|
||||
*/
|
||||
public fun CharSequence.single(): Char {
|
||||
return when (length()) {
|
||||
return when (length) {
|
||||
0 -> throw NoSuchElementException("Collection is empty.")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element.")
|
||||
@@ -339,7 +339,7 @@ public fun CharSequence.single(): Char {
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.single(): Char {
|
||||
return when (length()) {
|
||||
return when (length) {
|
||||
0 -> throw NoSuchElementException("Collection is empty.")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element.")
|
||||
@@ -385,7 +385,7 @@ public inline fun String.single(predicate: (Char) -> Boolean): Char {
|
||||
* Returns single character, or `null` if the char sequence is empty or has more than one character.
|
||||
*/
|
||||
public fun CharSequence.singleOrNull(): Char? {
|
||||
return if (length() == 1) this[0] else null
|
||||
return if (length == 1) this[0] else null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -393,7 +393,7 @@ public fun CharSequence.singleOrNull(): Char? {
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.singleOrNull(): Char? {
|
||||
return if (length() == 1) this[0] else null
|
||||
return if (length == 1) this[0] else null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -576,7 +576,7 @@ public inline fun <C : Appendable> String.filterNotTo(destination: C, predicate:
|
||||
* Appends all characters matching the given [predicate] to the given [destination].
|
||||
*/
|
||||
public inline fun <C : Appendable> CharSequence.filterTo(destination: C, predicate: (Char) -> Boolean): C {
|
||||
for (index in 0..length() - 1) {
|
||||
for (index in 0..length - 1) {
|
||||
val element = get(index)
|
||||
if (predicate(element)) destination.append(element)
|
||||
}
|
||||
@@ -588,7 +588,7 @@ public inline fun <C : Appendable> CharSequence.filterTo(destination: C, predica
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public inline fun <C : Appendable> String.filterTo(destination: C, predicate: (Char) -> Boolean): C {
|
||||
for (index in 0..length() - 1) {
|
||||
for (index in 0..length - 1) {
|
||||
val element = get(index)
|
||||
if (predicate(element)) destination.append(element)
|
||||
}
|
||||
@@ -735,7 +735,7 @@ public fun String.reversed(): String {
|
||||
* Returns an [ArrayList] of all characters.
|
||||
*/
|
||||
public fun CharSequence.toArrayList(): ArrayList<Char> {
|
||||
return toCollection(ArrayList<Char>(length()))
|
||||
return toCollection(ArrayList<Char>(length))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -743,7 +743,7 @@ public fun CharSequence.toArrayList(): ArrayList<Char> {
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.toArrayList(): ArrayList<Char> {
|
||||
return toCollection(ArrayList<Char>(length()))
|
||||
return toCollection(ArrayList<Char>(length))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -771,7 +771,7 @@ public fun <C : MutableCollection<in Char>> String.toCollection(collection: C):
|
||||
* Returns a [HashSet] of all characters.
|
||||
*/
|
||||
public fun CharSequence.toHashSet(): HashSet<Char> {
|
||||
return toCollection(HashSet<Char>(mapCapacity(length())))
|
||||
return toCollection(HashSet<Char>(mapCapacity(length)))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -779,7 +779,7 @@ public fun CharSequence.toHashSet(): HashSet<Char> {
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.toHashSet(): HashSet<Char> {
|
||||
return toCollection(HashSet<Char>(mapCapacity(length())))
|
||||
return toCollection(HashSet<Char>(mapCapacity(length)))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -820,7 +820,7 @@ public inline fun <K> String.toMap(selector: (Char) -> K): Map<K, Char> {
|
||||
* If any two characters would have the same key returned by [selector] the last one gets added to the map.
|
||||
*/
|
||||
public inline fun <K, V> CharSequence.toMap(selector: (Char) -> K, transform: (Char) -> V): Map<K, V> {
|
||||
val capacity = (length()/.75f) + 1
|
||||
val capacity = (length/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
@@ -834,7 +834,7 @@ public inline fun <K, V> CharSequence.toMap(selector: (Char) -> K, transform: (C
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public inline fun <K, V> String.toMap(selector: (Char) -> K, transform: (Char) -> V): Map<K, V> {
|
||||
val capacity = (length()/.75f) + 1
|
||||
val capacity = (length/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
@@ -848,7 +848,7 @@ public inline fun <K, V> String.toMap(selector: (Char) -> K, transform: (Char) -
|
||||
* If any two characters would have the same key returned by [selector] the last one gets added to the map.
|
||||
*/
|
||||
public inline fun <K> CharSequence.toMapBy(selector: (Char) -> K): Map<K, Char> {
|
||||
val capacity = (length()/.75f) + 1
|
||||
val capacity = (length/.75f) + 1
|
||||
val result = LinkedHashMap<K, Char>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), element)
|
||||
@@ -863,7 +863,7 @@ public inline fun <K> CharSequence.toMapBy(selector: (Char) -> K): Map<K, Char>
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public inline fun <K> String.toMapBy(selector: (Char) -> K): Map<K, Char> {
|
||||
val capacity = (length()/.75f) + 1
|
||||
val capacity = (length/.75f) + 1
|
||||
val result = LinkedHashMap<K, Char>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), element)
|
||||
@@ -875,7 +875,7 @@ public inline fun <K> String.toMapBy(selector: (Char) -> K): Map<K, Char> {
|
||||
* Returns a [Set] of all characters.
|
||||
*/
|
||||
public fun CharSequence.toSet(): Set<Char> {
|
||||
return toCollection(LinkedHashSet<Char>(mapCapacity(length())))
|
||||
return toCollection(LinkedHashSet<Char>(mapCapacity(length)))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -883,7 +883,7 @@ public fun CharSequence.toSet(): Set<Char> {
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.toSet(): Set<Char> {
|
||||
return toCollection(LinkedHashSet<Char>(mapCapacity(length())))
|
||||
return toCollection(LinkedHashSet<Char>(mapCapacity(length)))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -984,7 +984,7 @@ public inline fun <K> String.groupByTo(map: MutableMap<K, MutableList<Char>>, to
|
||||
* to each character in the original char sequence.
|
||||
*/
|
||||
public inline fun <R> CharSequence.map(transform: (Char) -> R): List<R> {
|
||||
return mapTo(ArrayList<R>(length()), transform)
|
||||
return mapTo(ArrayList<R>(length), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -993,7 +993,7 @@ public inline fun <R> CharSequence.map(transform: (Char) -> R): List<R> {
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public inline fun <R> String.map(transform: (Char) -> R): List<R> {
|
||||
return mapTo(ArrayList<R>(length()), transform)
|
||||
return mapTo(ArrayList<R>(length), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1001,7 +1001,7 @@ public inline fun <R> String.map(transform: (Char) -> R): List<R> {
|
||||
* to each character and its index in the original char sequence.
|
||||
*/
|
||||
public inline fun <R> CharSequence.mapIndexed(transform: (Int, Char) -> R): List<R> {
|
||||
return mapIndexedTo(ArrayList<R>(length()), transform)
|
||||
return mapIndexedTo(ArrayList<R>(length), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1010,7 +1010,7 @@ public inline fun <R> CharSequence.mapIndexed(transform: (Int, Char) -> R): List
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public inline fun <R> String.mapIndexed(transform: (Int, Char) -> R): List<R> {
|
||||
return mapIndexedTo(ArrayList<R>(length()), transform)
|
||||
return mapIndexedTo(ArrayList<R>(length), transform)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1161,7 +1161,7 @@ public inline fun String.any(predicate: (Char) -> Boolean): Boolean {
|
||||
* Returns the length of this char sequence.
|
||||
*/
|
||||
public fun CharSequence.count(): Int {
|
||||
return length()
|
||||
return length
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1169,7 +1169,7 @@ public fun CharSequence.count(): Int {
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public fun String.count(): Int {
|
||||
return length()
|
||||
return length
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1584,7 +1584,7 @@ public fun String.zip(other: String): List<Pair<Char, Char>> {
|
||||
* Returns a list of values built from characters of both char sequences with same indexes using provided [transform]. List has length of shortest char sequence.
|
||||
*/
|
||||
public inline fun <V> CharSequence.zip(other: String, transform: (Char, Char) -> V): List<V> {
|
||||
val length = Math.min(this.length(), other.length())
|
||||
val length = Math.min(this.length, other.length)
|
||||
val list = ArrayList<V>(length)
|
||||
for (i in 0..length-1) {
|
||||
list.add(transform(this[i], other[i]))
|
||||
@@ -1597,7 +1597,7 @@ public inline fun <V> CharSequence.zip(other: String, transform: (Char, Char) ->
|
||||
*/
|
||||
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
|
||||
public inline fun <V> String.zip(other: String, transform: (Char, Char) -> V): List<V> {
|
||||
val length = Math.min(this.length(), other.length())
|
||||
val length = Math.min(this.length, other.length)
|
||||
val list = ArrayList<V>(length)
|
||||
for (i in 0..length-1) {
|
||||
list.add(transform(this[i], other[i]))
|
||||
|
||||
@@ -29,7 +29,7 @@ public inline fun <reified T> emptyArray(): Array<T> = arrayOfNulls<T>(0) as Arr
|
||||
* Returns a single list of all elements from all arrays in the given array.
|
||||
*/
|
||||
public fun <T> Array<Array<out T>>.flatten(): List<T> {
|
||||
val result = ArrayList<T>(sumBy { it.size() })
|
||||
val result = ArrayList<T>(sumBy { it.size })
|
||||
for (element in this) {
|
||||
result.addAll(element)
|
||||
}
|
||||
@@ -42,8 +42,8 @@ public fun <T> Array<Array<out T>>.flatten(): List<T> {
|
||||
* *second* list is built from the second values of each pair from this array.
|
||||
*/
|
||||
public fun <T, R> Array<out Pair<T, R>>.unzip(): Pair<List<T>, List<R>> {
|
||||
val listT = ArrayList<T>(size())
|
||||
val listR = ArrayList<R>(size())
|
||||
val listT = ArrayList<T>(size)
|
||||
val listR = ArrayList<R>(size)
|
||||
for (pair in this) {
|
||||
listT.add(pair.first)
|
||||
listR.add(pair.second)
|
||||
|
||||
@@ -47,7 +47,7 @@ internal object EmptyList : List<Nothing>, Serializable {
|
||||
internal fun <T> Array<out T>.asCollection(): Collection<T> = ArrayAsCollection(this)
|
||||
|
||||
private class ArrayAsCollection<T>(val values: Array<out T>): Collection<T> {
|
||||
override val size: Int get() = values.size()
|
||||
override val size: Int get() = values.size
|
||||
override fun isEmpty(): Boolean = values.isEmpty()
|
||||
override fun contains(o: T): Boolean = values.contains(o)
|
||||
override fun containsAll(c: Collection<T>): Boolean = c.all { contains(it) }
|
||||
@@ -60,7 +60,7 @@ private class ArrayAsCollection<T>(val values: Array<out T>): Collection<T> {
|
||||
public fun <T> emptyList(): List<T> = EmptyList
|
||||
|
||||
/** Returns a new read-only list of given elements. The returned list is serializable (JVM). */
|
||||
public fun <T> listOf(vararg values: T): List<T> = if (values.size() > 0) values.asList() else emptyList()
|
||||
public fun <T> listOf(vararg values: T): List<T> = if (values.size > 0) values.asList() else emptyList()
|
||||
|
||||
/** Returns an empty read-only list. The returned list is serializable (JVM). */
|
||||
public fun <T> listOf(): List<T> = emptyList()
|
||||
@@ -75,11 +75,11 @@ public fun <T> listOf(value: T): List<T> = Collections.singletonList(value)
|
||||
/** Returns a new [LinkedList] with the given elements. */
|
||||
@JvmVersion
|
||||
public fun <T> linkedListOf(vararg values: T): LinkedList<T>
|
||||
= if (values.size() == 0) LinkedList() else LinkedList(ArrayAsCollection(values))
|
||||
= if (values.size == 0) LinkedList() else LinkedList(ArrayAsCollection(values))
|
||||
|
||||
/** Returns a new [ArrayList] with the given elements. */
|
||||
public fun <T> arrayListOf(vararg values: T): ArrayList<T>
|
||||
= if (values.size() == 0) ArrayList() else ArrayList(ArrayAsCollection(values))
|
||||
= if (values.size == 0) ArrayList() else ArrayList(ArrayAsCollection(values))
|
||||
|
||||
/** Returns a new read-only list either of single given element, if it is not null, or empty list it the element is null. The returned list is serializable (JVM). */
|
||||
public fun <T : Any> listOfNotNull(value: T?): List<T> = if (value != null) listOf(value) else emptyList()
|
||||
@@ -91,7 +91,7 @@ public fun <T : Any> listOfNotNull(vararg values: T?): List<T> = values.filterNo
|
||||
* Returns an [IntRange] of the valid indices for this collection.
|
||||
*/
|
||||
public val Collection<*>.indices: IntRange
|
||||
get() = 0..size() - 1
|
||||
get() = 0..size - 1
|
||||
|
||||
/**
|
||||
* Returns the index of the last item in the list or -1 if the list is empty.
|
||||
@@ -99,7 +99,7 @@ public val Collection<*>.indices: IntRange
|
||||
* @sample test.collections.ListSpecificTest.lastIndex
|
||||
*/
|
||||
public val <T> List<T>.lastIndex: Int
|
||||
get() = this.size() - 1
|
||||
get() = this.size - 1
|
||||
|
||||
/** Returns `true` if the collection is not empty. */
|
||||
public fun <T> Collection<T>.isNotEmpty(): Boolean = !isEmpty()
|
||||
@@ -120,15 +120,15 @@ public fun <T> Enumeration<T>.toList(): List<T> = Collections.list(this)
|
||||
/**
|
||||
* Returns the size of this iterable if it is known, or `null` otherwise.
|
||||
*/
|
||||
public fun <T> Iterable<T>.collectionSizeOrNull(): Int? = if (this is Collection<*>) size() else null
|
||||
public fun <T> Iterable<T>.collectionSizeOrNull(): Int? = if (this is Collection<*>) this.size else null
|
||||
|
||||
/**
|
||||
* Returns the size of this iterable if it is known, or the specified [default] value otherwise.
|
||||
*/
|
||||
public fun <T> Iterable<T>.collectionSizeOrDefault(default: Int): Int = if (this is Collection<*>) size() else default
|
||||
public fun <T> Iterable<T>.collectionSizeOrDefault(default: Int): Int = if (this is Collection<*>) this.size else default
|
||||
|
||||
/** Returns true when it's safe to convert this collection to a set without changing contains method behavior. */
|
||||
private fun <T> Collection<T>.safeToConvertToSet() = size() > 2 && this is ArrayList
|
||||
private fun <T> Collection<T>.safeToConvertToSet() = size > 2 && this is ArrayList
|
||||
|
||||
/** Converts this collection to a set, when it's worth so and it doesn't change contains method behavior. */
|
||||
internal fun <T> Iterable<T>.convertToSetForSetOperationWith(source: Iterable<T>): Collection<T> =
|
||||
@@ -136,7 +136,7 @@ internal fun <T> Iterable<T>.convertToSetForSetOperationWith(source: Iterable<T>
|
||||
is Set -> this
|
||||
is Collection ->
|
||||
when {
|
||||
source is Collection && source.size() < 2 -> this
|
||||
source is Collection && source.size < 2 -> this
|
||||
else -> if (this.safeToConvertToSet()) toHashSet() else this
|
||||
}
|
||||
else -> toHashSet()
|
||||
@@ -153,7 +153,7 @@ internal fun <T> Iterable<T>.convertToSetForSetOperation(): Collection<T> =
|
||||
// copies typed varargs array to array of objects
|
||||
@JvmVersion
|
||||
private fun <T> Array<out T>.varargToArrayOfAny(): Array<Any?>
|
||||
= Arrays.copyOf(this, this.size(), Array<Any?>::class.java)
|
||||
= Arrays.copyOf(this, this.size, Array<Any?>::class.java)
|
||||
|
||||
/**
|
||||
* Searches this list or its range for the provided [element] index using binary search algorithm.
|
||||
@@ -161,8 +161,8 @@ private fun <T> Array<out T>.varargToArrayOfAny(): Array<Any?>
|
||||
*
|
||||
* If the list contains multiple elements equal to the specified object, there is no guarantee which one will be found.
|
||||
*/
|
||||
public fun <T: Comparable<T>> List<T?>.binarySearch(element: T?, fromIndex: Int = 0, toIndex: Int = size()): Int {
|
||||
rangeCheck(size(), fromIndex, toIndex)
|
||||
public fun <T: Comparable<T>> List<T?>.binarySearch(element: T?, fromIndex: Int = 0, toIndex: Int = size): Int {
|
||||
rangeCheck(size, fromIndex, toIndex)
|
||||
|
||||
var low = fromIndex
|
||||
var high = toIndex - 1
|
||||
@@ -188,8 +188,8 @@ public fun <T: Comparable<T>> List<T?>.binarySearch(element: T?, fromIndex: Int
|
||||
*
|
||||
* If the list contains multiple elements equal to the specified object, there is no guarantee which one will be found.
|
||||
*/
|
||||
public fun <T> List<T>.binarySearch(element: T, comparator: Comparator<in T>, fromIndex: Int = 0, toIndex: Int = size()): Int {
|
||||
rangeCheck(size(), fromIndex, toIndex)
|
||||
public fun <T> List<T>.binarySearch(element: T, comparator: Comparator<in T>, fromIndex: Int = 0, toIndex: Int = size): Int {
|
||||
rangeCheck(size, fromIndex, toIndex)
|
||||
|
||||
var low = fromIndex
|
||||
var high = toIndex - 1
|
||||
@@ -215,7 +215,7 @@ public fun <T> List<T>.binarySearch(element: T, comparator: Comparator<in T>, fr
|
||||
*
|
||||
* If the list contains multiple elements with the specified [key], there is no guarantee which one will be found.
|
||||
*/
|
||||
public inline fun <T, K : Comparable<K>> List<T>.binarySearchBy(key: K?, fromIndex: Int = 0, toIndex: Int = size(), crossinline selector: (T) -> K?): Int =
|
||||
public inline fun <T, K : Comparable<K>> List<T>.binarySearchBy(key: K?, fromIndex: Int = 0, toIndex: Int = size, crossinline selector: (T) -> K?): Int =
|
||||
binarySearch(fromIndex, toIndex) { compareValues(selector(it), key) }
|
||||
|
||||
// do not introduce this overload --- too rare
|
||||
@@ -228,8 +228,8 @@ public inline fun <T, K : Comparable<K>> List<T>.binarySearchBy(key: K?, fromInd
|
||||
*
|
||||
* @param comparison function that compares an element of the list with the element being searched.
|
||||
*/
|
||||
public fun <T> List<T>.binarySearch(fromIndex: Int = 0, toIndex: Int = size(), comparison: (T) -> Int): Int {
|
||||
rangeCheck(size(), fromIndex, toIndex)
|
||||
public fun <T> List<T>.binarySearch(fromIndex: Int = 0, toIndex: Int = size, comparison: (T) -> Int): Int {
|
||||
rangeCheck(size, fromIndex, toIndex)
|
||||
|
||||
var low = fromIndex
|
||||
var high = toIndex - 1
|
||||
|
||||
@@ -64,7 +64,7 @@ private class MapWithDefaultImpl<K, out V>(public override val map: Map<K,V>, pr
|
||||
override fun equals(other: Any?): Boolean = map.equals(other)
|
||||
override fun hashCode(): Int = map.hashCode()
|
||||
override fun toString(): String = map.toString()
|
||||
override val size: Int get() = map.size()
|
||||
override val size: Int get() = map.size
|
||||
override fun isEmpty(): Boolean = map.isEmpty()
|
||||
override fun containsKey(key: K): Boolean = map.containsKey(key)
|
||||
override fun containsValue(value: @UnsafeVariance V): Boolean = map.containsValue(value)
|
||||
@@ -80,7 +80,7 @@ private class MutableMapWithDefaultImpl<K, V>(public override val map: MutableMa
|
||||
override fun equals(other: Any?): Boolean = map.equals(other)
|
||||
override fun hashCode(): Int = map.hashCode()
|
||||
override fun toString(): String = map.toString()
|
||||
override val size: Int get() = map.size()
|
||||
override val size: Int get() = map.size
|
||||
override fun isEmpty(): Boolean = map.isEmpty()
|
||||
override fun containsKey(key: K): Boolean = map.containsKey(key)
|
||||
override fun containsValue(value: @UnsafeVariance V): Boolean = map.containsValue(value)
|
||||
|
||||
@@ -34,7 +34,7 @@ public fun <K, V> emptyMap(): Map<K, V> = EmptyMap as Map<K, V>
|
||||
*
|
||||
* The returned map is serializable (JVM).
|
||||
*/
|
||||
public fun <K, V> mapOf(vararg values: Pair<K, V>): Map<K, V> = if (values.size() > 0) linkedMapOf(*values) else emptyMap()
|
||||
public fun <K, V> mapOf(vararg values: Pair<K, V>): Map<K, V> = if (values.size > 0) linkedMapOf(*values) else emptyMap()
|
||||
|
||||
/** Returns an empty read-only map. The returned map is serializable (JVM). */
|
||||
public fun <K, V> mapOf(): Map<K, V> = emptyMap()
|
||||
@@ -53,7 +53,7 @@ public fun <K, V> mapOf(keyValuePair: Pair<K, V>): Map<K, V> = Collections.singl
|
||||
* @sample test.collections.MapTest.createUsingPairs
|
||||
*/
|
||||
public fun <K, V> hashMapOf(vararg values: Pair<K, V>): HashMap<K, V> {
|
||||
val answer = HashMap<K, V>(mapCapacity(values.size()))
|
||||
val answer = HashMap<K, V>(mapCapacity(values.size))
|
||||
answer.putAll(*values)
|
||||
return answer
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public fun <K, V> hashMapOf(vararg values: Pair<K, V>): HashMap<K, V> {
|
||||
* @sample test.collections.MapTest.createLinkedMap
|
||||
*/
|
||||
public fun <K, V> linkedMapOf(vararg values: Pair<K, V>): LinkedHashMap<K, V> {
|
||||
val answer = LinkedHashMap<K, V>(mapCapacity(values.size()))
|
||||
val answer = LinkedHashMap<K, V>(mapCapacity(values.size))
|
||||
answer.putAll(*values)
|
||||
return answer
|
||||
}
|
||||
@@ -350,7 +350,7 @@ public fun <K, V> Iterable<Pair<K, V>>.toMap(): Map<K, V> {
|
||||
* Returns a new map containing all key-value pairs from the given array of pairs.
|
||||
*/
|
||||
public fun <K, V> Array<Pair<K, V>>.toMap(): Map<K, V> {
|
||||
val result = LinkedHashMap<K, V>(mapCapacity(size()))
|
||||
val result = LinkedHashMap<K, V>(mapCapacity(size))
|
||||
for (element in this) {
|
||||
result.put(element.first, element.second)
|
||||
}
|
||||
|
||||
@@ -21,11 +21,11 @@ package kotlin
|
||||
import java.util.AbstractList
|
||||
|
||||
private open class ReversedListReadOnly<T>(protected open val delegate: List<T>) : AbstractList<T>() {
|
||||
override val size: Int get() = delegate.size()
|
||||
override val size: Int get() = delegate.size
|
||||
override fun get(index: Int): T = delegate[index.flipIndex()]
|
||||
|
||||
protected fun Int.flipIndex(): Int = if (this in 0..size() - 1) size() - this - 1 else throw IndexOutOfBoundsException("index $this should be in range [${0..size() - 1}]")
|
||||
protected fun Int.flipIndexForward(): Int = if (this in 0..size()) size() - this else throw IndexOutOfBoundsException("index $this should be in range [${0..size()}]")
|
||||
protected fun Int.flipIndex(): Int = if (this in 0..size - 1) size - this - 1 else throw IndexOutOfBoundsException("index $this should be in range [${0..size - 1}]")
|
||||
protected fun Int.flipIndexForward(): Int = if (this in 0..size) size - this else throw IndexOutOfBoundsException("index $this should be in range [${0..size}]")
|
||||
}
|
||||
|
||||
private class ReversedList<T>(protected override val delegate: MutableList<T>) : ReversedListReadOnly<T>(delegate) {
|
||||
|
||||
@@ -26,17 +26,17 @@ internal object EmptySet : Set<Nothing>, Serializable {
|
||||
/** Returns an empty read-only set. The returned set is serializable (JVM). */
|
||||
public fun emptySet<T>(): Set<T> = EmptySet
|
||||
/** Returns a new read-only ordered set with the given elements. The returned set is serializable (JVM). */
|
||||
public fun setOf<T>(vararg values: T): Set<T> = if (values.size() > 0) values.toSet() else emptySet()
|
||||
public fun setOf<T>(vararg values: T): Set<T> = if (values.size > 0) values.toSet() else emptySet()
|
||||
|
||||
/** Returns an empty read-only set. The returned set is serializable (JVM). */
|
||||
public fun setOf<T>(): Set<T> = emptySet()
|
||||
|
||||
|
||||
/** Returns a new [HashSet] with the given elements. */
|
||||
public fun hashSetOf<T>(vararg values: T): HashSet<T> = values.toCollection(HashSet(mapCapacity(values.size())))
|
||||
public fun hashSetOf<T>(vararg values: T): HashSet<T> = values.toCollection(HashSet(mapCapacity(values.size)))
|
||||
|
||||
/** Returns a new [LinkedHashSet] with the given elements. */
|
||||
public fun linkedSetOf<T>(vararg values: T): LinkedHashSet<T> = values.toCollection(LinkedHashSet(mapCapacity(values.size())))
|
||||
public fun linkedSetOf<T>(vararg values: T): LinkedHashSet<T> = values.toCollection(LinkedHashSet(mapCapacity(values.size)))
|
||||
|
||||
/** Returns this Set if it's not `null` and the empty set otherwise. */
|
||||
public fun <T> Set<T>?.orEmpty(): Set<T> = this ?: emptySet()
|
||||
|
||||
@@ -23,7 +23,7 @@ private fun String.getRootName(): String {
|
||||
// Note: separators should be already replaced to system ones
|
||||
var first = indexOf(File.separatorChar, 0)
|
||||
if (first == 0) {
|
||||
if (length() > 1 && this[1] == File.separatorChar) {
|
||||
if (length > 1 && this[1] == File.separatorChar) {
|
||||
// Network names like //my.host/home/something ? => //my.host/home/ should be root
|
||||
// NB: does not work in Unix because //my.host/home is converted into /my.host/home there
|
||||
// So in Windows we'll have root of //my.host/home but in Unix just /
|
||||
@@ -75,7 +75,7 @@ public val File.rootName: String
|
||||
public val File.root: File?
|
||||
get() {
|
||||
val name = rootName
|
||||
return if (name.length() > 0) File(name) else null
|
||||
return if (name.length > 0) File(name) else null
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,7 +89,7 @@ public data class FilePathComponents(public val rootName: String, public val fil
|
||||
/**
|
||||
* Returns the number of elements in the path to the file.
|
||||
*/
|
||||
public fun size(): Int = fileList.size()
|
||||
public fun size(): Int = fileList.size
|
||||
|
||||
/**
|
||||
* Returns a sub-path of the path, starting with the directory at the specified [beginIndex] and up
|
||||
@@ -110,10 +110,10 @@ public data class FilePathComponents(public val rootName: String, public val fil
|
||||
public fun File.filePathComponents(): FilePathComponents {
|
||||
val path = separatorsToSystem()
|
||||
val rootName = path.getRootName()
|
||||
val subPath = path.substring(rootName.length())
|
||||
val subPath = path.substring(rootName.length)
|
||||
// if: a special case when we have only root component
|
||||
// Split not only by / or \, but also by //, ///, \\, \\\, etc.
|
||||
val list = if (rootName.length() > 0 && subPath.isEmpty()) listOf() else
|
||||
val list = if (rootName.length > 0 && subPath.isEmpty()) listOf() else
|
||||
// Looks awful but we split just by /+ or \+ depending on OS
|
||||
subPath.split(Regex.fromLiteral(File.separatorChar.toString())).toList().map { it -> File(it) }
|
||||
return FilePathComponents(rootName, list)
|
||||
|
||||
@@ -77,7 +77,7 @@ public class FileTreeWalk(private val start: File,
|
||||
failed = true
|
||||
}
|
||||
}
|
||||
if (fileList != null && fileIndex < fileList!!.size()) {
|
||||
if (fileList != null && fileIndex < fileList!!.size) {
|
||||
// First visit all files
|
||||
return fileList!![fileIndex++]
|
||||
} else if (!rootVisited) {
|
||||
@@ -108,14 +108,14 @@ public class FileTreeWalk(private val start: File,
|
||||
enter(rootDir)
|
||||
rootVisited = true
|
||||
return rootDir
|
||||
} else if (fileList == null || fileIndex < fileList!!.size()) {
|
||||
} else if (fileList == null || fileIndex < fileList!!.size) {
|
||||
if (fileList == null) {
|
||||
// Then read an array of files, if any
|
||||
fileList = rootDir.listFiles()
|
||||
if (fileList == null) {
|
||||
fail(rootDir, AccessDeniedException(file = rootDir, reason = "Cannot list files in a directory"))
|
||||
}
|
||||
if (fileList == null || fileList!!.size() == 0) {
|
||||
if (fileList == null || fileList!!.size == 0) {
|
||||
leave(rootDir)
|
||||
return null
|
||||
}
|
||||
@@ -175,7 +175,7 @@ public class FileTreeWalk(private val start: File,
|
||||
// Check that file/directory matches the filter
|
||||
if (!filter(file))
|
||||
return gotoNext()
|
||||
if (file == topState.rootDir || !file.isDirectory() || state.size() >= maxDepth) {
|
||||
if (file == topState.rootDir || !file.isDirectory() || state.size >= maxDepth) {
|
||||
// Proceed to a root directory or a simple file
|
||||
return file
|
||||
} else {
|
||||
|
||||
@@ -159,8 +159,8 @@ public fun File.relativePath(descendant: File): String {
|
||||
val prefix = directory.canonicalPath
|
||||
val answer = descendant.canonicalPath
|
||||
return if (answer.startsWith(prefix)) {
|
||||
val prefixSize = prefix.length()
|
||||
if (answer.length() > prefixSize) {
|
||||
val prefixSize = prefix.length
|
||||
if (answer.length > prefixSize) {
|
||||
answer.substring(prefixSize + 1)
|
||||
} else ""
|
||||
} else {
|
||||
@@ -368,7 +368,7 @@ public fun File.normalize(): File {
|
||||
when (name) {
|
||||
"." -> {
|
||||
}
|
||||
".." -> if (!list.isEmpty() && list.get(list.size() - 1) != "..") list.remove(list.size() - 1) else list.add(name)
|
||||
".." -> if (!list.isEmpty() && list.get(list.size - 1) != "..") list.remove(list.size - 1) else list.add(name)
|
||||
else -> list.add(name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,12 +34,12 @@ public fun String.replaceIndentByMargin(newIndent: String = "", marginPrefix: St
|
||||
require(marginPrefix.isNotBlank()) { "marginPrefix should be non blank string but it is '$marginPrefix'" }
|
||||
val lines = lines()
|
||||
|
||||
return lines.reindent(length() + newIndent.length() * lines.size(), getIndentFunction(newIndent), { line ->
|
||||
return lines.reindent(length + newIndent.length * lines.size, getIndentFunction(newIndent), { line ->
|
||||
val firstNonWhitespaceIndex = line.indexOfFirst { !it.isWhitespace() }
|
||||
|
||||
when {
|
||||
firstNonWhitespaceIndex == -1 -> null
|
||||
line.startsWith(marginPrefix, firstNonWhitespaceIndex) -> line.substring(firstNonWhitespaceIndex + marginPrefix.length())
|
||||
line.startsWith(marginPrefix, firstNonWhitespaceIndex) -> line.substring(firstNonWhitespaceIndex + marginPrefix.length)
|
||||
else -> null
|
||||
}
|
||||
})
|
||||
@@ -80,7 +80,7 @@ public fun String.replaceIndent(newIndent: String = ""): String {
|
||||
.map { it.indentWidth() }
|
||||
.min() ?: 0
|
||||
|
||||
return lines.reindent(length() + newIndent.length() * lines.size(), getIndentFunction(newIndent), { line -> line.drop(minCommonIndent) })
|
||||
return lines.reindent(length + newIndent.length * lines.size, getIndentFunction(newIndent), { line -> line.drop(minCommonIndent) })
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,7 +92,7 @@ public fun String.prependIndent(indent: String = " "): String =
|
||||
when {
|
||||
it.isBlank() -> {
|
||||
when {
|
||||
it.length() < indent.length() -> indent
|
||||
it.length < indent.length -> indent
|
||||
else -> it
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public fun String.prependIndent(indent: String = " "): String =
|
||||
}
|
||||
.joinToString("\n")
|
||||
|
||||
private fun String.indentWidth(): Int = indexOfFirst { !it.isWhitespace() }.let { if (it == -1) length() else it }
|
||||
private fun String.indentWidth(): Int = indexOfFirst { !it.isWhitespace() }.let { if (it == -1) length else it }
|
||||
|
||||
private fun getIndentFunction(indent: String) = when {
|
||||
indent.isEmpty() -> { line: String -> line }
|
||||
|
||||
@@ -13,7 +13,7 @@ import kotlin.text.Regex
|
||||
*/
|
||||
inline public fun CharSequence.trim(predicate: (Char) -> Boolean): CharSequence {
|
||||
var startIndex = 0
|
||||
var endIndex = length() - 1
|
||||
var endIndex = length - 1
|
||||
var startFound = false
|
||||
|
||||
while (startIndex <= endIndex) {
|
||||
@@ -206,17 +206,17 @@ public fun String.padEnd(length: Int, padChar: Char = ' '): String
|
||||
/**
|
||||
* Returns `true` if this nullable char sequence is either `null` or empty.
|
||||
*/
|
||||
public fun CharSequence?.isNullOrEmpty(): Boolean = this == null || this.length() == 0
|
||||
public fun CharSequence?.isNullOrEmpty(): Boolean = this == null || this.length == 0
|
||||
|
||||
/**
|
||||
* Returns `true` if this char sequence is empty (contains no characters).
|
||||
*/
|
||||
public fun CharSequence.isEmpty(): Boolean = length() == 0
|
||||
public fun CharSequence.isEmpty(): Boolean = length == 0
|
||||
|
||||
/**
|
||||
* Returns `true` if this char sequence is not empty.
|
||||
*/
|
||||
public fun CharSequence.isNotEmpty(): Boolean = length() > 0
|
||||
public fun CharSequence.isNotEmpty(): Boolean = length > 0
|
||||
|
||||
// implemented differently in JVM and JS
|
||||
//public fun String.isBlank(): Boolean = length() == 0 || all { it.isWhitespace() }
|
||||
@@ -240,7 +240,7 @@ public operator fun CharSequence.iterator(): CharIterator = object : CharIterato
|
||||
|
||||
public override fun nextChar(): Char = get(index++)
|
||||
|
||||
public override fun hasNext(): Boolean = index < length()
|
||||
public override fun hasNext(): Boolean = index < length
|
||||
}
|
||||
|
||||
/** Returns the string if it is not `null`, or the empty string otherwise. */
|
||||
@@ -250,13 +250,13 @@ public fun String?.orEmpty(): String = this ?: ""
|
||||
* Returns the range of valid character indices for this char sequence.
|
||||
*/
|
||||
public val CharSequence.indices: IntRange
|
||||
get() = 0..length() - 1
|
||||
get() = 0..length - 1
|
||||
|
||||
/**
|
||||
* Returns the index of the last character in the char sequence or -1 if it is empty.
|
||||
*/
|
||||
public val CharSequence.lastIndex: Int
|
||||
get() = this.length() - 1
|
||||
get() = this.length - 1
|
||||
|
||||
/**
|
||||
* Returns a character at the given index in a [CharSequence]. Allows to use the
|
||||
@@ -271,7 +271,7 @@ public operator fun CharSequence.get(index: Int): Char = this.get(index)
|
||||
* Returns `true` if this CharSequence has Unicode surrogate pair at the specified [index].
|
||||
*/
|
||||
public fun CharSequence.hasSurrogatePairAt(index: Int): Boolean {
|
||||
return index in 0..length() - 2
|
||||
return index in 0..length - 2
|
||||
&& this[index].isHighSurrogate()
|
||||
&& this[index + 1].isLowSurrogate()
|
||||
}
|
||||
@@ -320,7 +320,7 @@ public fun String.substringBefore(delimiter: String, missingDelimiterValue: Stri
|
||||
*/
|
||||
public fun String.substringAfter(delimiter: Char, missingDelimiterValue: String = this): String {
|
||||
val index = indexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else substring(index + 1, length())
|
||||
return if (index == -1) missingDelimiterValue else substring(index + 1, length)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -329,7 +329,7 @@ public fun String.substringAfter(delimiter: Char, missingDelimiterValue: String
|
||||
*/
|
||||
public fun String.substringAfter(delimiter: String, missingDelimiterValue: String = this): String {
|
||||
val index = indexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else substring(index + delimiter.length(), length())
|
||||
return if (index == -1) missingDelimiterValue else substring(index + delimiter.length, length)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -356,7 +356,7 @@ public fun String.substringBeforeLast(delimiter: String, missingDelimiterValue:
|
||||
*/
|
||||
public fun String.substringAfterLast(delimiter: Char, missingDelimiterValue: String = this): String {
|
||||
val index = lastIndexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else substring(index + 1, length())
|
||||
return if (index == -1) missingDelimiterValue else substring(index + 1, length)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -365,7 +365,7 @@ public fun String.substringAfterLast(delimiter: Char, missingDelimiterValue: Str
|
||||
*/
|
||||
public fun String.substringAfterLast(delimiter: String, missingDelimiterValue: String = this): String {
|
||||
val index = lastIndexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else substring(index + delimiter.length(), length())
|
||||
return if (index == -1) missingDelimiterValue else substring(index + delimiter.length, length)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -380,7 +380,7 @@ public fun CharSequence.replaceRange(firstIndex: Int, lastIndex: Int, replacemen
|
||||
val sb = StringBuilder()
|
||||
sb.append(this, 0, firstIndex)
|
||||
sb.append(replacement)
|
||||
sb.append(this, lastIndex, length())
|
||||
sb.append(this, lastIndex, length)
|
||||
return sb
|
||||
}
|
||||
|
||||
@@ -424,9 +424,9 @@ public fun CharSequence.removeRange(firstIndex: Int, lastIndex: Int): CharSequen
|
||||
if (lastIndex == firstIndex)
|
||||
return this.subSequence(0, length)
|
||||
|
||||
val sb = StringBuilder(length() - (lastIndex - firstIndex))
|
||||
val sb = StringBuilder(length - (lastIndex - firstIndex))
|
||||
sb.append(this, 0, firstIndex)
|
||||
sb.append(this, lastIndex, length())
|
||||
sb.append(this, lastIndex, length)
|
||||
return sb
|
||||
}
|
||||
|
||||
@@ -560,7 +560,7 @@ public fun String.replaceBefore(delimiter: String, replacement: String, missingD
|
||||
*/
|
||||
public fun String.replaceAfter(delimiter: Char, replacement: String, missingDelimiterValue: String = this): String {
|
||||
val index = indexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else replaceRange(index + 1, length(), replacement)
|
||||
return if (index == -1) missingDelimiterValue else replaceRange(index + 1, length, replacement)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -569,7 +569,7 @@ public fun String.replaceAfter(delimiter: Char, replacement: String, missingDeli
|
||||
*/
|
||||
public fun String.replaceAfter(delimiter: String, replacement: String, missingDelimiterValue: String = this): String {
|
||||
val index = indexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else replaceRange(index + delimiter.length(), length(), replacement)
|
||||
return if (index == -1) missingDelimiterValue else replaceRange(index + delimiter.length, length, replacement)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -578,7 +578,7 @@ public fun String.replaceAfter(delimiter: String, replacement: String, missingDe
|
||||
*/
|
||||
public fun String.replaceAfterLast(delimiter: String, replacement: String, missingDelimiterValue: String = this): String {
|
||||
val index = lastIndexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else replaceRange(index + delimiter.length(), length(), replacement)
|
||||
return if (index == -1) missingDelimiterValue else replaceRange(index + delimiter.length, length, replacement)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -587,7 +587,7 @@ public fun String.replaceAfterLast(delimiter: String, replacement: String, missi
|
||||
*/
|
||||
public fun String.replaceAfterLast(delimiter: Char, replacement: String, missingDelimiterValue: String = this): String {
|
||||
val index = lastIndexOf(delimiter)
|
||||
return if (index == -1) missingDelimiterValue else replaceRange(index + 1, length(), replacement)
|
||||
return if (index == -1) missingDelimiterValue else replaceRange(index + 1, length, replacement)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -662,13 +662,13 @@ internal fun CharSequence.regionMatchesImpl(thisOffset: Int, other: CharSequence
|
||||
* Returns `true` if this char sequence starts with the specified character.
|
||||
*/
|
||||
public fun CharSequence.startsWith(char: Char, ignoreCase: Boolean = false): Boolean =
|
||||
this.length() > 0 && this[0].equals(char, ignoreCase)
|
||||
this.length > 0 && this[0].equals(char, ignoreCase)
|
||||
|
||||
/**
|
||||
* Returns `true` if this char sequence ends with the specified character.
|
||||
*/
|
||||
public fun CharSequence.endsWith(char: Char, ignoreCase: Boolean = false): Boolean =
|
||||
this.length() > 0 && this[lastIndex].equals(char, ignoreCase)
|
||||
this.length > 0 && this[lastIndex].equals(char, ignoreCase)
|
||||
|
||||
/**
|
||||
* Returns `true` if this char sequence starts with the specified prefix.
|
||||
@@ -677,7 +677,7 @@ public fun CharSequence.startsWith(prefix: CharSequence, ignoreCase: Boolean = f
|
||||
if (!ignoreCase && this is String && prefix is String)
|
||||
return this.startsWith(prefix)
|
||||
else
|
||||
return regionMatchesImpl(0, prefix, 0, prefix.length(), ignoreCase)
|
||||
return regionMatchesImpl(0, prefix, 0, prefix.length, ignoreCase)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -687,7 +687,7 @@ public fun CharSequence.startsWith(prefix: CharSequence, thisOffset: Int, ignore
|
||||
if (!ignoreCase && this is String && prefix is String)
|
||||
return this.startsWith(prefix, thisOffset)
|
||||
else
|
||||
return regionMatchesImpl(thisOffset, prefix, 0, prefix.length(), ignoreCase)
|
||||
return regionMatchesImpl(thisOffset, prefix, 0, prefix.length, ignoreCase)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -697,7 +697,7 @@ public fun CharSequence.endsWith(suffix: CharSequence, ignoreCase: Boolean = fal
|
||||
if (!ignoreCase && this is String && suffix is String)
|
||||
return this.endsWith(suffix)
|
||||
else
|
||||
return regionMatchesImpl(length() - suffix.length(), suffix, 0, suffix.length(), ignoreCase)
|
||||
return regionMatchesImpl(length - suffix.length, suffix, 0, suffix.length, ignoreCase)
|
||||
}
|
||||
|
||||
|
||||
@@ -711,7 +711,7 @@ public fun CharSequence.endsWith(suffix: CharSequence, ignoreCase: Boolean = fal
|
||||
* @param ignoreCase `true` to ignore character case when matching a character. By default `false`.
|
||||
*/
|
||||
public fun CharSequence.commonPrefixWith(other: CharSequence, ignoreCase: Boolean = false): String {
|
||||
val shortestLength = Math.min(this.length(), other.length())
|
||||
val shortestLength = Math.min(this.length, other.length)
|
||||
|
||||
var i = 0
|
||||
while (i < shortestLength && this[i].equals(other[i], ignoreCase = ignoreCase)) {
|
||||
@@ -731,8 +731,8 @@ public fun CharSequence.commonPrefixWith(other: CharSequence, ignoreCase: Boolea
|
||||
* @param ignoreCase `true` to ignore character case when matching a character. By default `false`.
|
||||
*/
|
||||
public fun CharSequence.commonSuffixWith(other: CharSequence, ignoreCase: Boolean = false): String {
|
||||
val thisLength = this.length()
|
||||
val otherLength = other.length()
|
||||
val thisLength = this.length
|
||||
val otherLength = other.length
|
||||
val shortestLength = Math.min(thisLength, otherLength)
|
||||
|
||||
var i = 0
|
||||
@@ -749,7 +749,7 @@ public fun CharSequence.commonSuffixWith(other: CharSequence, ignoreCase: Boolea
|
||||
// indexOfAny()
|
||||
|
||||
private fun CharSequence.findAnyOf(chars: CharArray, startIndex: Int, ignoreCase: Boolean, last: Boolean): Pair<Int, Char>? {
|
||||
if (!ignoreCase && chars.size() == 1 && this is String) {
|
||||
if (!ignoreCase && chars.size == 1 && this is String) {
|
||||
val char = chars.single()
|
||||
val index = if (!last) nativeIndexOf(char, startIndex) else nativeLastIndexOf(char, startIndex)
|
||||
return if (index < 0) null else index to char
|
||||
@@ -792,18 +792,18 @@ public fun CharSequence.lastIndexOfAny(chars: CharArray, startIndex: Int = lastI
|
||||
|
||||
private fun CharSequence.indexOf(other: CharSequence, startIndex: Int, endIndex: Int, ignoreCase: Boolean, last: Boolean = false): Int {
|
||||
val indices = if (!last)
|
||||
startIndex.coerceAtLeast(0)..endIndex.coerceAtMost(length())
|
||||
startIndex.coerceAtLeast(0)..endIndex.coerceAtMost(length)
|
||||
else
|
||||
startIndex.coerceAtMost(lastIndex) downTo endIndex.coerceAtLeast(0)
|
||||
|
||||
if (this is String && other is String) { // smart cast
|
||||
for (index in indices) {
|
||||
if (other.regionMatches(0, this, index, other.length(), ignoreCase))
|
||||
if (other.regionMatches(0, this, index, other.length, ignoreCase))
|
||||
return index
|
||||
}
|
||||
} else {
|
||||
for (index in indices) {
|
||||
if (other.regionMatchesImpl(0, this, index, other.length(), ignoreCase))
|
||||
if (other.regionMatchesImpl(0, this, index, other.length, ignoreCase))
|
||||
return index
|
||||
}
|
||||
}
|
||||
@@ -817,17 +817,17 @@ private fun CharSequence.findAnyOf(strings: Collection<String>, startIndex: Int,
|
||||
return if (index < 0) null else index to string
|
||||
}
|
||||
|
||||
val indices = if (!last) startIndex.coerceAtLeast(0)..length() else startIndex.coerceAtMost(lastIndex) downTo 0
|
||||
val indices = if (!last) startIndex.coerceAtLeast(0)..length else startIndex.coerceAtMost(lastIndex) downTo 0
|
||||
|
||||
if (this is String) {
|
||||
for (index in indices) {
|
||||
val matchingString = strings.firstOrNull { it.regionMatches(0, this, index, it.length(), ignoreCase) }
|
||||
val matchingString = strings.firstOrNull { it.regionMatches(0, this, index, it.length, ignoreCase) }
|
||||
if (matchingString != null)
|
||||
return index to matchingString
|
||||
}
|
||||
} else {
|
||||
for (index in indices) {
|
||||
val matchingString = strings.firstOrNull { it.regionMatchesImpl(0, this, index, it.length(), ignoreCase) }
|
||||
val matchingString = strings.firstOrNull { it.regionMatchesImpl(0, this, index, it.length, ignoreCase) }
|
||||
if (matchingString != null)
|
||||
return index to matchingString
|
||||
}
|
||||
@@ -920,7 +920,7 @@ public fun CharSequence.indexOf(char: Char, startIndex: Int = 0, ignoreCase: Boo
|
||||
*/
|
||||
public fun CharSequence.indexOf(string: String, startIndex: Int = 0, ignoreCase: Boolean = false): Int {
|
||||
return if (ignoreCase || this !is String)
|
||||
indexOf(string, startIndex, length(), ignoreCase)
|
||||
indexOf(string, startIndex, length, ignoreCase)
|
||||
else
|
||||
nativeIndexOf(string, startIndex)
|
||||
}
|
||||
@@ -964,7 +964,7 @@ public operator fun CharSequence.contains(other: CharSequence, ignoreCase: Boole
|
||||
if (other is String)
|
||||
indexOf(other, ignoreCase = ignoreCase) >= 0
|
||||
else
|
||||
indexOf(other, 0, length(), ignoreCase) >= 0
|
||||
indexOf(other, 0, length, ignoreCase) >= 0
|
||||
|
||||
|
||||
|
||||
@@ -989,7 +989,7 @@ private class DelimitedRangesSequence(private val input: CharSequence, private v
|
||||
|
||||
override fun iterator(): Iterator<IntRange> = object : Iterator<IntRange> {
|
||||
var nextState: Int = -1 // -1 for unknown, 0 for done, 1 for continue
|
||||
var currentStartIndex: Int = Math.min(Math.max(startIndex, 0), input.length())
|
||||
var currentStartIndex: Int = Math.min(Math.max(startIndex, 0), input.length)
|
||||
var nextSearchIndex: Int = currentStartIndex
|
||||
var nextItem: IntRange? = null
|
||||
var counter: Int = 0
|
||||
@@ -1000,7 +1000,7 @@ private class DelimitedRangesSequence(private val input: CharSequence, private v
|
||||
nextItem = null
|
||||
}
|
||||
else {
|
||||
if (limit > 0 && ++counter >= limit || nextSearchIndex > input.length()) {
|
||||
if (limit > 0 && ++counter >= limit || nextSearchIndex > input.length) {
|
||||
nextItem = currentStartIndex..input.lastIndex
|
||||
nextSearchIndex = -1
|
||||
}
|
||||
@@ -1076,7 +1076,7 @@ private fun CharSequence.rangesDelimitedBy(delimiters: Array<out String>, startI
|
||||
require(limit >= 0, { "Limit must be non-negative, but was $limit" } )
|
||||
val delimitersList = delimiters.asList()
|
||||
|
||||
return DelimitedRangesSequence(this, startIndex, limit, { startIndex -> findAnyOf(delimitersList, startIndex, ignoreCase = ignoreCase, last = false)?.let { it.first to it.second.length ()} })
|
||||
return DelimitedRangesSequence(this, startIndex, limit, { startIndex -> findAnyOf(delimitersList, startIndex, ignoreCase = ignoreCase, last = false)?.let { it.first to it.second.length } })
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ public fun String.replaceFirst(oldChar: Char, newChar: Char, ignoreCase: Boolean
|
||||
*/
|
||||
public fun String.replaceFirst(oldValue: String, newValue: String, ignoreCase: Boolean = false): String {
|
||||
val index = indexOf(oldValue, ignoreCase = ignoreCase)
|
||||
return if (index < 0) this else this.replaceRange(index, index + oldValue.length(), newValue)
|
||||
return if (index < 0) this else this.replaceRange(index, index + oldValue.length, newValue)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,7 +134,7 @@ public fun String.startsWith(prefix: String, ignoreCase: Boolean = false): Boole
|
||||
if (!ignoreCase)
|
||||
return (this as java.lang.String).startsWith(prefix)
|
||||
else
|
||||
return regionMatches(0, prefix, 0, prefix.length(), ignoreCase)
|
||||
return regionMatches(0, prefix, 0, prefix.length, ignoreCase)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,7 +144,7 @@ public fun String.startsWith(prefix: String, thisOffset: Int, ignoreCase: Boolea
|
||||
if (!ignoreCase)
|
||||
return (this as java.lang.String).startsWith(prefix, thisOffset)
|
||||
else
|
||||
return regionMatches(thisOffset, prefix, 0, prefix.length(), ignoreCase)
|
||||
return regionMatches(thisOffset, prefix, 0, prefix.length, ignoreCase)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,7 +154,7 @@ public fun String.endsWith(suffix: String, ignoreCase: Boolean = false): Boolean
|
||||
if (!ignoreCase)
|
||||
return (this as java.lang.String).endsWith(suffix)
|
||||
else
|
||||
return regionMatches(length() - suffix.length(), suffix, 0, suffix.length(), ignoreCase = true)
|
||||
return regionMatches(length - suffix.length, suffix, 0, suffix.length, ignoreCase = true)
|
||||
}
|
||||
|
||||
// "constructors" for String
|
||||
@@ -292,7 +292,7 @@ public fun String.intern(): String = (this as java.lang.String).intern()
|
||||
/**
|
||||
* Returns `true` if this string is empty or consists solely of whitespace characters.
|
||||
*/
|
||||
public fun CharSequence.isBlank(): Boolean = length() == 0 || indices.all { this[it].isWhitespace() }
|
||||
public fun CharSequence.isBlank(): Boolean = length == 0 || indices.all { this[it].isWhitespace() }
|
||||
|
||||
/**
|
||||
* Returns the index within this string that is offset from the given [index] by [codePointOffset] code points.
|
||||
@@ -440,7 +440,7 @@ public fun CharSequence.repeat(n: Int): String {
|
||||
if (n < 0)
|
||||
throw IllegalArgumentException("Value should be non-negative, but was $n")
|
||||
|
||||
val sb = StringBuilder(n * length())
|
||||
val sb = StringBuilder(n * length)
|
||||
for (i in 1..n) {
|
||||
sb.append(this)
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ public class Regex internal constructor(private val nativePattern: Pattern) {
|
||||
var match: MatchResult? = find(input) ?: return input.toString()
|
||||
|
||||
var lastStart = 0
|
||||
val length = input.length()
|
||||
val length = input.length
|
||||
val sb = StringBuilder(length)
|
||||
do {
|
||||
val foundMatch = match!!
|
||||
@@ -256,7 +256,7 @@ private class MatcherMatchResult(private val matcher: Matcher, private val input
|
||||
|
||||
override fun next(): MatchResult? {
|
||||
val nextIndex = matchResult.end() + if (matchResult.end() == matchResult.start()) 1 else 0
|
||||
return if (nextIndex <= input.length()) matcher.findNext(nextIndex, input) else null
|
||||
return if (nextIndex <= input.length) matcher.findNext(nextIndex, input) else null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import java.util.Comparator
|
||||
* compare as equal, the result of that comparison is returned.
|
||||
*/
|
||||
public fun <T> compareValuesBy(a: T, b: T, vararg selectors: (T) -> Comparable<*>?): Int {
|
||||
require(selectors.size() > 0)
|
||||
require(selectors.size > 0)
|
||||
for (fn in selectors) {
|
||||
val v1 = fn(a)
|
||||
val v2 = fn(b)
|
||||
|
||||
@@ -39,6 +39,6 @@ class ExceptionTest {
|
||||
}
|
||||
|
||||
val bytes = assertNotNull(byteBuffer.toByteArray())
|
||||
assertTrue(bytes.size() > 10)
|
||||
assertTrue(bytes.size > 10)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class OldStdlibTest() {
|
||||
|
||||
@test fun testCollectionSize() {
|
||||
assertTrue {
|
||||
listOf(0, 1, 2).size() == 3
|
||||
listOf(0, 1, 2).size == 3
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ class PairTest {
|
||||
|
||||
@test fun pairHashSet() {
|
||||
val s = hashSetOf(Pair(1, "a"), Pair(1, "b"), Pair(1, "a"))
|
||||
assertEquals(2, s.size())
|
||||
assertEquals(2, s.size)
|
||||
assertTrue(s.contains(p))
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ class TripleTest {
|
||||
|
||||
@test fun tripleHashSet() {
|
||||
val s = hashSetOf(Triple(1, "a", 0.07), Triple(1, "b", 0.07), Triple(1, "a", 0.07))
|
||||
assertEquals(2, s.size())
|
||||
assertEquals(2, s.size)
|
||||
assertTrue(s.contains(t))
|
||||
}
|
||||
|
||||
|
||||
@@ -10,14 +10,14 @@ class ArraysJVMTest {
|
||||
val y: Array<out String>? = null
|
||||
val xArray = x.orEmpty()
|
||||
val yArray = y.orEmpty()
|
||||
expect(0) { xArray.size() }
|
||||
expect(0) { yArray.size() }
|
||||
expect(0) { xArray.size }
|
||||
expect(0) { yArray.size }
|
||||
}
|
||||
|
||||
@test fun orEmptyNotNull() {
|
||||
val x: Array<String>? = arrayOf("1", "2")
|
||||
val xArray = x.orEmpty()
|
||||
expect(2) { xArray.size() }
|
||||
expect(2) { xArray.size }
|
||||
expect("1") { xArray[0] }
|
||||
expect("2") { xArray[1] }
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class ArraysTest {
|
||||
val arr = ByteArray(2)
|
||||
|
||||
val expected: Byte = 0
|
||||
assertEquals(arr.size(), 2)
|
||||
assertEquals(arr.size, 2)
|
||||
assertEquals(expected, arr[0])
|
||||
assertEquals(expected, arr[1])
|
||||
}
|
||||
@@ -49,7 +49,7 @@ class ArraysTest {
|
||||
val arr = ShortArray(2)
|
||||
|
||||
val expected: Short = 0
|
||||
assertEquals(arr.size(), 2)
|
||||
assertEquals(arr.size, 2)
|
||||
assertEquals(expected, arr[0])
|
||||
assertEquals(expected, arr[1])
|
||||
}
|
||||
@@ -57,7 +57,7 @@ class ArraysTest {
|
||||
@test fun intArray() {
|
||||
val arr = IntArray(2)
|
||||
|
||||
assertEquals(arr.size(), 2)
|
||||
assertEquals(arr.size, 2)
|
||||
assertEquals(0, arr[0])
|
||||
assertEquals(0, arr[1])
|
||||
}
|
||||
@@ -66,7 +66,7 @@ class ArraysTest {
|
||||
val arr = LongArray(2)
|
||||
|
||||
val expected: Long = 0
|
||||
assertEquals(arr.size(), 2)
|
||||
assertEquals(arr.size, 2)
|
||||
assertEquals(expected, arr[0])
|
||||
assertEquals(expected, arr[1])
|
||||
}
|
||||
@@ -75,7 +75,7 @@ class ArraysTest {
|
||||
val arr = FloatArray(2)
|
||||
|
||||
val expected: Float = 0.0F
|
||||
assertEquals(arr.size(), 2)
|
||||
assertEquals(arr.size, 2)
|
||||
assertEquals(expected, arr[0])
|
||||
assertEquals(expected, arr[1])
|
||||
}
|
||||
@@ -83,7 +83,7 @@ class ArraysTest {
|
||||
@test fun doubleArray() {
|
||||
val arr = DoubleArray(2)
|
||||
|
||||
assertEquals(arr.size(), 2)
|
||||
assertEquals(arr.size, 2)
|
||||
assertEquals(0.0, arr[0])
|
||||
assertEquals(0.0, arr[1])
|
||||
}
|
||||
@@ -92,14 +92,14 @@ class ArraysTest {
|
||||
val arr = CharArray(2)
|
||||
|
||||
val expected: Char = '\u0000'
|
||||
assertEquals(arr.size(), 2)
|
||||
assertEquals(arr.size, 2)
|
||||
assertEquals(expected, arr[0])
|
||||
assertEquals(expected, arr[1])
|
||||
}
|
||||
|
||||
@test fun booleanArray() {
|
||||
val arr = BooleanArray(2)
|
||||
assertEquals(arr.size(), 2)
|
||||
assertEquals(arr.size, 2)
|
||||
assertEquals(false, arr[0])
|
||||
assertEquals(false, arr[1])
|
||||
}
|
||||
@@ -151,7 +151,7 @@ class ArraysTest {
|
||||
expect(1, { arrayOf(1).minBy { it } })
|
||||
expect(3, { arrayOf(2, 3).minBy { -it } })
|
||||
expect('a', { arrayOf('a', 'b').minBy { "x$it" } })
|
||||
expect("b", { arrayOf("b", "abc").minBy { it.length() } })
|
||||
expect("b", { arrayOf("b", "abc").minBy { it.length } })
|
||||
}
|
||||
|
||||
@test fun minByInPrimitiveArrays() {
|
||||
@@ -170,7 +170,7 @@ class ArraysTest {
|
||||
expect(1, { arrayOf(1).maxBy { it } })
|
||||
expect(2, { arrayOf(2, 3).maxBy { -it } })
|
||||
expect('b', { arrayOf('a', 'b').maxBy { "x$it" } })
|
||||
expect("abc", { arrayOf("b", "abc").maxBy { it.length() } })
|
||||
expect("abc", { arrayOf("b", "abc").maxBy { it.length } })
|
||||
}
|
||||
|
||||
@test fun maxByInPrimitiveArrays() {
|
||||
@@ -461,7 +461,7 @@ class ArraysTest {
|
||||
@test fun toPrimitiveArray() {
|
||||
val genericArray: Array<Int> = arrayOf(1, 2, 3)
|
||||
val primitiveArray: IntArray = genericArray.toIntArray()
|
||||
expect(3) { primitiveArray.size() }
|
||||
expect(3) { primitiveArray.size }
|
||||
assertEquals(genericArray.asList(), primitiveArray.asList())
|
||||
|
||||
|
||||
@@ -473,7 +473,7 @@ class ArraysTest {
|
||||
@test fun toTypedArray() {
|
||||
val primitiveArray: LongArray = longArrayOf(1, 2, Long.MAX_VALUE)
|
||||
val genericArray: Array<Long> = primitiveArray.toTypedArray()
|
||||
expect(3) { genericArray.size() }
|
||||
expect(3) { genericArray.size }
|
||||
assertEquals(primitiveArray.asList(), genericArray.asList())
|
||||
}
|
||||
|
||||
|
||||
@@ -25,19 +25,19 @@ public fun <T> CompareContext<List<T>>.listBehavior() {
|
||||
compareProperty( { listIterator(0) }, { listIteratorBehavior() })
|
||||
|
||||
propertyFails { listIterator(-1) }
|
||||
propertyFails { listIterator(size() + 1) }
|
||||
propertyFails { listIterator(size + 1) }
|
||||
|
||||
for (index in expected.indices)
|
||||
propertyEquals { this[index] }
|
||||
|
||||
propertyFails { this[size()] }
|
||||
propertyFails { this[size] }
|
||||
|
||||
propertyEquals { (this as List<T?>).indexOf(elementAtOrNull(0)) }
|
||||
propertyEquals { (this as List<T?>).lastIndexOf(elementAtOrNull(0)) }
|
||||
|
||||
propertyFails { subList(0, size() + 1)}
|
||||
propertyFails { subList(0, size + 1)}
|
||||
propertyFails { subList(-1, 0)}
|
||||
propertyEquals { subList(0, size()) }
|
||||
propertyEquals { subList(0, size) }
|
||||
}
|
||||
|
||||
public fun <T> CompareContext<ListIterator<T>>.listIteratorBehavior() {
|
||||
@@ -81,7 +81,7 @@ public fun <T> CompareContext<Set<T>>.setBehavior(objectName: String = "") {
|
||||
|
||||
public fun <K, V> CompareContext<Map<K, V>>.mapBehavior() {
|
||||
equalityBehavior()
|
||||
propertyEquals { size() }
|
||||
propertyEquals { size }
|
||||
propertyEquals { isEmpty() }
|
||||
|
||||
(object {}).let { propertyEquals { containsKey(it)} }
|
||||
@@ -108,7 +108,7 @@ public fun <T> CompareContext<T>.equalityBehavior(objectName: String = "") {
|
||||
|
||||
public fun <T> CompareContext<Collection<T>>.collectionBehavior(objectName: String = "") {
|
||||
val prefix = objectName + if (objectName.isNotEmpty()) "." else ""
|
||||
propertyEquals (prefix + "size") { size() }
|
||||
propertyEquals (prefix + "size") { size }
|
||||
propertyEquals (prefix + "isEmpty") { isEmpty() }
|
||||
|
||||
(object {}).let { propertyEquals { containsRaw(it)} }
|
||||
|
||||
@@ -39,7 +39,7 @@ class CollectionJVMTest {
|
||||
val data = listOf("", "foo", "bar", "x", "")
|
||||
val characters = data.flatMap { it.toCharList() }
|
||||
println("Got list of characters ${characters}")
|
||||
assertEquals(7, characters.size())
|
||||
assertEquals(7, characters.size)
|
||||
val text = characters.joinToString("")
|
||||
assertEquals("foobarx", text)
|
||||
}
|
||||
@@ -52,7 +52,7 @@ class CollectionJVMTest {
|
||||
assertTrue {
|
||||
foo.all { it.startsWith("f") }
|
||||
}
|
||||
assertEquals(1, foo.size())
|
||||
assertEquals(1, foo.size)
|
||||
assertEquals(linkedListOf("foo"), foo)
|
||||
|
||||
assertTrue {
|
||||
@@ -67,7 +67,7 @@ class CollectionJVMTest {
|
||||
assertTrue {
|
||||
foo.all { !it.startsWith("f") }
|
||||
}
|
||||
assertEquals(1, foo.size())
|
||||
assertEquals(1, foo.size)
|
||||
assertEquals(linkedListOf("bar"), foo)
|
||||
|
||||
assertTrue {
|
||||
@@ -79,7 +79,7 @@ class CollectionJVMTest {
|
||||
val data = listOf(null, "foo", null, "bar")
|
||||
val foo = data.filterNotNullTo(linkedListOf<String>())
|
||||
|
||||
assertEquals(2, foo.size())
|
||||
assertEquals(2, foo.size)
|
||||
assertEquals(linkedListOf("foo", "bar"), foo)
|
||||
|
||||
assertTrue {
|
||||
@@ -89,8 +89,8 @@ class CollectionJVMTest {
|
||||
|
||||
@test fun filterIntoSortedSet() {
|
||||
val data = listOf("foo", "bar")
|
||||
val sorted = data.filterTo(sortedSetOf<String>()) { it.length() == 3 }
|
||||
assertEquals(2, sorted.size())
|
||||
val sorted = data.filterTo(sortedSetOf<String>()) { it.length == 3 }
|
||||
assertEquals(2, sorted.size)
|
||||
assertEquals(sortedSetOf("bar", "foo"), sorted)
|
||||
assertTrue {
|
||||
sorted is TreeSet<String>
|
||||
@@ -120,7 +120,7 @@ class CollectionJVMTest {
|
||||
val data = listOf("foo", "bar")
|
||||
val arr = data.toTypedArray()
|
||||
println("Got array ${arr}")
|
||||
assertEquals(2, arr.size())
|
||||
assertEquals(2, arr.size)
|
||||
todo {
|
||||
assertTrue {
|
||||
arr.isArrayOf<String>()
|
||||
@@ -148,7 +148,7 @@ class CollectionJVMTest {
|
||||
assertEquals(values.toList(), anyValues)
|
||||
|
||||
val charValues: List<Char> = values.filterIsInstance<Char>()
|
||||
assertEquals(0, charValues.size())
|
||||
assertEquals(0, charValues.size)
|
||||
}
|
||||
|
||||
@test fun filterIsInstanceArray() {
|
||||
@@ -167,7 +167,7 @@ class CollectionJVMTest {
|
||||
assertEquals(src.toList(), anyValues)
|
||||
|
||||
val charValues: List<Char> = src.filterIsInstance<Char>()
|
||||
assertEquals(0, charValues.size())
|
||||
assertEquals(0, charValues.size)
|
||||
}
|
||||
|
||||
@test fun emptyListIsSerializable() = testSingletonSerialization(emptyList<Any>())
|
||||
|
||||
@@ -28,7 +28,7 @@ class CollectionTest {
|
||||
val data = listOf(null, "foo", null, "bar")
|
||||
val foo = data.filterNotNull()
|
||||
|
||||
assertEquals(2, foo.size())
|
||||
assertEquals(2, foo.size)
|
||||
assertEquals(listOf("foo", "bar"), foo)
|
||||
|
||||
assertTrue {
|
||||
@@ -68,7 +68,7 @@ class CollectionTest {
|
||||
assertTrue {
|
||||
foo.all { it.startsWith("f") }
|
||||
}
|
||||
assertEquals(1, foo.size())
|
||||
assertEquals(1, foo.size)
|
||||
assertEquals(hashSetOf("foo"), foo)
|
||||
|
||||
assertTrue {
|
||||
@@ -98,7 +98,7 @@ class CollectionTest {
|
||||
@test fun foldWithDifferentTypes() {
|
||||
expect(7) {
|
||||
val numbers = listOf("a", "ab", "abc")
|
||||
numbers.fold(1) { a, b -> a + b.length() }
|
||||
numbers.fold(1) { a, b -> a + b.length }
|
||||
}
|
||||
|
||||
expect("1234") {
|
||||
@@ -151,7 +151,7 @@ class CollectionTest {
|
||||
|
||||
@test fun partition() {
|
||||
val data = listOf("foo", "bar", "something", "xyz")
|
||||
val pair = data.partition { it.length() == 3 }
|
||||
val pair = data.partition { it.length == 3 }
|
||||
|
||||
assertEquals(listOf("foo", "bar", "xyz"), pair.first, "pair.first")
|
||||
assertEquals(listOf("something"), pair.second, "pair.second")
|
||||
@@ -185,8 +185,8 @@ class CollectionTest {
|
||||
|
||||
@test fun groupBy() {
|
||||
val words = listOf("a", "abc", "ab", "def", "abcd")
|
||||
val byLength = words.groupBy { it.length() }
|
||||
assertEquals(4, byLength.size())
|
||||
val byLength = words.groupBy { it.length }
|
||||
assertEquals(4, byLength.size)
|
||||
|
||||
// verify that order of keys is preserved
|
||||
val listOfPairs = byLength.toList()
|
||||
@@ -196,7 +196,7 @@ class CollectionTest {
|
||||
assertEquals(4, listOfPairs[3].first)
|
||||
|
||||
val l3 = byLength.getOrElse(3, { ArrayList<String>() })
|
||||
assertEquals(2, l3.size())
|
||||
assertEquals(2, l3.size)
|
||||
}
|
||||
|
||||
@test fun plusRanges() {
|
||||
@@ -350,8 +350,8 @@ class CollectionTest {
|
||||
@test fun dropLast() {
|
||||
val coll = listOf("foo", "bar", "abc")
|
||||
assertEquals(coll, coll.dropLast(0))
|
||||
assertEquals(emptyList<String>(), coll.dropLast(coll.size()))
|
||||
assertEquals(emptyList<String>(), coll.dropLast(coll.size() + 1))
|
||||
assertEquals(emptyList<String>(), coll.dropLast(coll.size))
|
||||
assertEquals(emptyList<String>(), coll.dropLast(coll.size + 1))
|
||||
assertEquals(listOf("foo", "bar"), coll.dropLast(1))
|
||||
assertEquals(listOf("foo"), coll.dropLast(2))
|
||||
|
||||
@@ -362,7 +362,7 @@ class CollectionTest {
|
||||
val coll = listOf("Foo", "bare", "abc" )
|
||||
assertEquals(coll, coll.dropLastWhile { false })
|
||||
assertEquals(listOf<String>(), coll.dropLastWhile { true })
|
||||
assertEquals(listOf("Foo", "bare"), coll.dropLastWhile { it.length() < 4 })
|
||||
assertEquals(listOf("Foo", "bare"), coll.dropLastWhile { it.length < 4 })
|
||||
assertEquals(listOf("Foo"), coll.dropLastWhile { it.all { it in 'a'..'z' } })
|
||||
}
|
||||
|
||||
@@ -371,8 +371,8 @@ class CollectionTest {
|
||||
assertEquals(emptyList<String>(), coll.take(0))
|
||||
assertEquals(listOf("foo"), coll.take(1))
|
||||
assertEquals(listOf("foo", "bar"), coll.take(2))
|
||||
assertEquals(coll, coll.take(coll.size()))
|
||||
assertEquals(coll, coll.take(coll.size() + 1))
|
||||
assertEquals(coll, coll.take(coll.size))
|
||||
assertEquals(coll, coll.take(coll.size + 1))
|
||||
|
||||
assertFails { coll.take(-1) }
|
||||
}
|
||||
@@ -382,7 +382,7 @@ class CollectionTest {
|
||||
assertEquals(emptyList<String>(), coll.takeWhile { false })
|
||||
assertEquals(coll, coll.takeWhile { true })
|
||||
assertEquals(listOf("foo"), coll.takeWhile { it.startsWith("f") })
|
||||
assertEquals(listOf("foo", "bar", "abc"), coll.takeWhile { it.length() == 3 })
|
||||
assertEquals(listOf("foo", "bar", "abc"), coll.takeWhile { it.length == 3 })
|
||||
}
|
||||
|
||||
@test fun takeLast() {
|
||||
@@ -391,8 +391,8 @@ class CollectionTest {
|
||||
assertEquals(emptyList<String>(), coll.takeLast(0))
|
||||
assertEquals(listOf("abc"), coll.takeLast(1))
|
||||
assertEquals(listOf("bar", "abc"), coll.takeLast(2))
|
||||
assertEquals(coll, coll.takeLast(coll.size()))
|
||||
assertEquals(coll, coll.takeLast(coll.size() + 1))
|
||||
assertEquals(coll, coll.takeLast(coll.size))
|
||||
assertEquals(coll, coll.takeLast(coll.size + 1))
|
||||
|
||||
assertFails { coll.takeLast(-1) }
|
||||
}
|
||||
@@ -409,7 +409,7 @@ class CollectionTest {
|
||||
val data = listOf("foo", "bar")
|
||||
val arr = data.toTypedArray()
|
||||
println("Got array ${arr}")
|
||||
assertEquals(2, arr.size())
|
||||
assertEquals(2, arr.size)
|
||||
}
|
||||
|
||||
@test fun count() {
|
||||
@@ -463,7 +463,7 @@ class CollectionTest {
|
||||
val indices = data.indices
|
||||
assertEquals(0, indices.start)
|
||||
assertEquals(1, indices.end)
|
||||
assertEquals(0..data.size() - 1, indices)
|
||||
assertEquals(0..data.size - 1, indices)
|
||||
}
|
||||
|
||||
@test fun contains() {
|
||||
@@ -500,7 +500,7 @@ class CollectionTest {
|
||||
expect(1, { listOf(1).minBy { it } })
|
||||
expect(3, { listOf(2, 3).minBy { -it } })
|
||||
expect('a', { listOf('a', 'b').minBy { "x$it" } })
|
||||
expect("b", { listOf("b", "abc").minBy { it.length() } })
|
||||
expect("b", { listOf("b", "abc").minBy { it.length } })
|
||||
expect(null, { listOf<Int>().asSequence().minBy { it } })
|
||||
expect(3, { listOf(2, 3).asSequence().minBy { -it } })
|
||||
}
|
||||
@@ -510,7 +510,7 @@ class CollectionTest {
|
||||
expect(1, { listOf(1).maxBy { it } })
|
||||
expect(2, { listOf(2, 3).maxBy { -it } })
|
||||
expect('b', { listOf('a', 'b').maxBy { "x$it" } })
|
||||
expect("abc", { listOf("b", "abc").maxBy { it.length() } })
|
||||
expect("abc", { listOf("b", "abc").maxBy { it.length } })
|
||||
expect(null, { listOf<Int>().asSequence().maxBy { it } })
|
||||
expect(2, { listOf(2, 3).asSequence().maxBy { -it } })
|
||||
}
|
||||
@@ -609,7 +609,7 @@ class CollectionTest {
|
||||
}
|
||||
|
||||
@test fun sortedByNullable() {
|
||||
fun String.nonEmptyLength() = if (isEmpty()) null else length()
|
||||
fun String.nonEmptyLength() = if (isEmpty()) null else length
|
||||
listOf("", "sort", "abc").let {
|
||||
assertEquals(listOf("", "abc", "sort"), it.sortedBy { it.nonEmptyLength() })
|
||||
assertEquals(listOf("sort", "abc", ""), it.sortedByDescending { it.nonEmptyLength() })
|
||||
|
||||
@@ -48,7 +48,7 @@ abstract class OrderedIterableTests<T : Iterable<String>>(data: T, empty: T) : I
|
||||
@Test
|
||||
fun indexOfLast() {
|
||||
expect(-1) { data.indexOfLast { it.contains("p") } }
|
||||
expect(1) { data.indexOfLast { it.length() == 3 } }
|
||||
expect(1) { data.indexOfLast { it.length == 3 } }
|
||||
expect(-1) { empty.indexOfLast { it.startsWith('f') } }
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
|
||||
|
||||
@Test
|
||||
fun all() {
|
||||
expect(true) { data.all { it.length() == 3 } }
|
||||
expect(true) { data.all { it.length == 3 } }
|
||||
expect(false) { data.all { it.startsWith("b") } }
|
||||
expect(true) { empty.all { it.startsWith("b") } }
|
||||
}
|
||||
@@ -131,7 +131,7 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
|
||||
fun none() {
|
||||
expect(false) { data.none() }
|
||||
expect(true) { empty.none() }
|
||||
expect(false) { data.none { it.length() == 3 } }
|
||||
expect(false) { data.none { it.length == 3 } }
|
||||
expect(false) { data.none { it.startsWith("b") } }
|
||||
expect(true) { data.none { it.startsWith("x") } }
|
||||
expect(true) { empty.none { it.startsWith("b") } }
|
||||
@@ -181,7 +181,7 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
|
||||
@Test
|
||||
fun forEach() {
|
||||
var count = 0
|
||||
data.forEach { count += it.length() }
|
||||
data.forEach { count += it.length }
|
||||
assertEquals(6, count)
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
|
||||
expect("foo") { data.single { it.startsWith("f") } }
|
||||
expect("bar") { data.single { it.startsWith("b") } }
|
||||
assertFails {
|
||||
data.single { it.length() == 3 }
|
||||
data.single { it.length == 3 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,13 +211,13 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
|
||||
expect("foo") { data.singleOrNull { it.startsWith("f") } }
|
||||
expect("bar") { data.singleOrNull { it.startsWith("b") } }
|
||||
expect(null) {
|
||||
data.singleOrNull { it.length() == 3 }
|
||||
data.singleOrNull { it.length == 3 }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun map() {
|
||||
val lengths = data.map { it.length() }
|
||||
val lengths = data.map { it.length }
|
||||
assertTrue {
|
||||
lengths.all { it == 3 }
|
||||
}
|
||||
@@ -227,7 +227,7 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
|
||||
|
||||
@Test
|
||||
fun flatten() {
|
||||
assertEquals(listOf(0, 1, 2, 3, 0, 1, 2, 3), data.map { 0..it.length() }.flatten())
|
||||
assertEquals(listOf(0, 1, 2, 3, 0, 1, 2, 3), data.map { 0..it.length }.flatten())
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -280,11 +280,11 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
|
||||
|
||||
@Test
|
||||
fun sumBy() {
|
||||
expect(6) { data.sumBy { it.length() } }
|
||||
expect(0) { empty.sumBy { it.length() } }
|
||||
expect(6) { data.sumBy { it.length } }
|
||||
expect(0) { empty.sumBy { it.length } }
|
||||
|
||||
expect(3.0) { data.sumByDouble { it.length().toDouble() / 2 } }
|
||||
expect(0.0) { empty.sumByDouble { it.length().toDouble() / 2 } }
|
||||
expect(3.0) { data.sumByDouble { it.length.toDouble() / 2 } }
|
||||
expect(0.0) { empty.sumByDouble { it.length.toDouble() / 2 } }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -306,7 +306,7 @@ abstract class IterableTests<T : Iterable<String>>(val data: T, val empty: T) {
|
||||
@Test
|
||||
fun reduce() {
|
||||
val reduced = data.reduce { a, b -> a + b }
|
||||
assertEquals(6, reduced.length())
|
||||
assertEquals(6, reduced.length)
|
||||
assertTrue(reduced == "foobar" || reduced == "barfoo")
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class ListBinarySearchTest {
|
||||
|
||||
if (index > 0) {
|
||||
index.let { from -> assertEquals(notFound(from), list.binarySearch(list.first(), fromIndex = from)) }
|
||||
(list.size() - index).let { to -> assertEquals(notFound(to), list.binarySearch(list.last(), toIndex = to)) }
|
||||
(list.size - index).let { to -> assertEquals(notFound(to), list.binarySearch(list.last(), toIndex = to)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ class ListBinarySearchTest {
|
||||
|
||||
if (index > 0) {
|
||||
index.let { from -> assertEquals(notFound(from), list.binarySearch(list.first(), fromIndex = from)) }
|
||||
(list.size() - index).let { to -> assertEquals(notFound(to), list.binarySearch(list.last(), toIndex = to)) }
|
||||
(list.size - index).let { to -> assertEquals(notFound(to), list.binarySearch(list.last(), toIndex = to)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ class ListBinarySearchTest {
|
||||
|
||||
if (index > 0) {
|
||||
index.let { from -> assertEquals(notFound(from), list.binarySearch(list.first(), comparator, fromIndex = from)) }
|
||||
(list.size() - index).let { to -> assertEquals(notFound(to), list.binarySearch(list.last(), comparator, toIndex = to)) }
|
||||
(list.size - index).let { to -> assertEquals(notFound(to), list.binarySearch(list.last(), comparator, toIndex = to)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ class ListBinarySearchTest {
|
||||
|
||||
if (index > 0) {
|
||||
index.let { from -> assertEquals(notFound(from), list.binarySearchBy(list.first().value, fromIndex = from) { it.value }) }
|
||||
(list.size() - index).let { to -> assertEquals(notFound(to), list.binarySearchBy(list.last().value, toIndex = to) { it.value }) }
|
||||
(list.size - index).let { to -> assertEquals(notFound(to), list.binarySearchBy(list.last().value, toIndex = to) { it.value }) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ class ListBinarySearchTest {
|
||||
index.let { from ->
|
||||
assertEquals(notFound(from), list.binarySearch(fromIndex = from) { comparator.compare(it.value, list.first().value) })
|
||||
}
|
||||
(list.size() - index).let { to ->
|
||||
(list.size - index).let { to ->
|
||||
assertEquals(notFound(to), list.binarySearch(toIndex = to) { comparator.compare(it.value, list.last().value) })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ class ListSpecificTest {
|
||||
list += item
|
||||
}
|
||||
|
||||
assertEquals(3, list.size())
|
||||
assertEquals(3, list.size)
|
||||
assertEquals("beverage,location,name", list.joinToString(","))
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class MapJVMTest {
|
||||
|
||||
@test fun toSortedMapWithComparator() {
|
||||
val map = mapOf(Pair("c", 3), Pair("bc", 2), Pair("bd", 4), Pair("abc", 1))
|
||||
val sorted = map.toSortedMap(compareBy<String> { it.length() } thenBy { it })
|
||||
val sorted = map.toSortedMap(compareBy<String> { it.length } thenBy { it })
|
||||
assertEquals(listOf("c", "bc", "bd", "abc"), sorted.keySet().toList())
|
||||
assertEquals(1, sorted["abc"])
|
||||
assertEquals(2, sorted["bc"])
|
||||
@@ -36,7 +36,7 @@ class MapJVMTest {
|
||||
@test fun toProperties() {
|
||||
val map = mapOf("a" to "A", "b" to "B")
|
||||
val prop = map.toProperties()
|
||||
assertEquals(2, prop.size())
|
||||
assertEquals(2, prop.size)
|
||||
assertEquals("A", prop.getProperty("a", "fail"))
|
||||
assertEquals("B", prop.getProperty("b", "fail"))
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class MapTest {
|
||||
|
||||
val b = data.getOrElse("foo") { 3 }
|
||||
assertEquals(3, b)
|
||||
assertEquals(0, data.size())
|
||||
assertEquals(0, data.size)
|
||||
|
||||
val empty = mapOf<String, Int?>()
|
||||
val c = empty.getOrElse("") { null }
|
||||
@@ -34,7 +34,7 @@ class MapTest {
|
||||
data["bar"] = 3
|
||||
assertEquals(3, mutableWithDefault["bar"])
|
||||
|
||||
val readonlyWithDefault = (data as Map<String, Int>).withDefault { it.length() }
|
||||
val readonlyWithDefault = (data as Map<String, Int>).withDefault { it.length }
|
||||
assertEquals(4, readonlyWithDefault.getOrImplicitDefault("loop"))
|
||||
|
||||
val withReplacedDefault = readonlyWithDefault.withDefault { 42 }
|
||||
@@ -49,7 +49,7 @@ class MapTest {
|
||||
val b = data.getOrPut("foo") { 3 }
|
||||
assertEquals(2, b)
|
||||
|
||||
assertEquals(1, data.size())
|
||||
assertEquals(1, data.size)
|
||||
|
||||
val empty = hashMapOf<String, Int?>()
|
||||
val c = empty.getOrPut("") { null }
|
||||
@@ -59,18 +59,18 @@ class MapTest {
|
||||
@test fun sizeAndEmpty() {
|
||||
val data = hashMapOf<String, Int>()
|
||||
assertTrue { data.none() }
|
||||
assertEquals(data.size(), 0)
|
||||
assertEquals(data.size, 0)
|
||||
}
|
||||
|
||||
@test fun setViaIndexOperators() {
|
||||
val map = hashMapOf<String, String>()
|
||||
assertTrue { map.none() }
|
||||
assertEquals(map.size(), 0)
|
||||
assertEquals(map.size, 0)
|
||||
|
||||
map["name"] = "James"
|
||||
|
||||
assertTrue { map.any() }
|
||||
assertEquals(map.size(), 1)
|
||||
assertEquals(map.size, 1)
|
||||
assertEquals("James", map["name"])
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ class MapTest {
|
||||
list.add(e.getValue())
|
||||
}
|
||||
|
||||
assertEquals(6, list.size())
|
||||
assertEquals(6, list.size)
|
||||
assertEquals("beverage,beer,location,Mells,name,James", list.joinToString(","))
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ class MapTest {
|
||||
list.add(e.value)
|
||||
}
|
||||
|
||||
assertEquals(6, list.size())
|
||||
assertEquals(6, list.size)
|
||||
assertEquals("beverage,beer,location,Mells,name,James", list.joinToString(","))
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ class MapTest {
|
||||
list.add(value)
|
||||
}
|
||||
|
||||
assertEquals(6, list.size())
|
||||
assertEquals(6, list.size)
|
||||
assertEquals("beverage,beer,location,Mells,name,James", list.joinToString(","))
|
||||
}
|
||||
|
||||
@@ -154,36 +154,36 @@ class MapTest {
|
||||
|
||||
@test fun createUsingPairs() {
|
||||
val map = mapOf(Pair("a", 1), Pair("b", 2))
|
||||
assertEquals(2, map.size())
|
||||
assertEquals(2, map.size)
|
||||
assertEquals(1, map["a"])
|
||||
assertEquals(2, map["b"])
|
||||
}
|
||||
|
||||
@test fun createFromIterable() {
|
||||
val map = listOf(Pair("a", 1), Pair("b", 2)).toMap()
|
||||
assertEquals(2, map.size())
|
||||
assertEquals(2, map.size)
|
||||
assertEquals(1, map.get("a"))
|
||||
assertEquals(2, map.get("b"))
|
||||
}
|
||||
|
||||
@test fun createWithSelector() {
|
||||
val map = listOf("a", "bb", "ccc").toMapBy { it.length() }
|
||||
assertEquals(3, map.size())
|
||||
val map = listOf("a", "bb", "ccc").toMapBy { it.length }
|
||||
assertEquals(3, map.size)
|
||||
assertEquals("a", map.get(1))
|
||||
assertEquals("bb", map.get(2))
|
||||
assertEquals("ccc", map.get(3))
|
||||
}
|
||||
|
||||
@test fun createWithSelectorAndOverwrite() {
|
||||
val map = listOf("aa", "bb", "ccc").toMapBy { it.length() }
|
||||
assertEquals(2, map.size())
|
||||
val map = listOf("aa", "bb", "ccc").toMapBy { it.length }
|
||||
assertEquals(2, map.size)
|
||||
assertEquals("bb", map.get(2))
|
||||
assertEquals("ccc", map.get(3))
|
||||
}
|
||||
|
||||
@test fun createWithSelectorForKeyAndValue() {
|
||||
val map = listOf("a", "bb", "ccc").toMap({ it.length() }, { it.toUpperCase() })
|
||||
assertEquals(3, map.size())
|
||||
val map = listOf("a", "bb", "ccc").toMap({ it.length }, { it.toUpperCase() })
|
||||
assertEquals(3, map.size)
|
||||
assertEquals("A", map.get(1))
|
||||
assertEquals("BB", map.get(2))
|
||||
assertEquals("CCC", map.get(3))
|
||||
@@ -191,7 +191,7 @@ class MapTest {
|
||||
|
||||
@test fun createUsingTo() {
|
||||
val map = mapOf("a" to 1, "b" to 2)
|
||||
assertEquals(2, map.size())
|
||||
assertEquals(2, map.size)
|
||||
assertEquals(1, map["a"])
|
||||
assertEquals(2, map["b"])
|
||||
}
|
||||
@@ -207,21 +207,21 @@ class MapTest {
|
||||
@test fun filter() {
|
||||
val map = mapOf(Pair("b", 3), Pair("c", 2), Pair("a", 2))
|
||||
val filteredByKey = map.filter { it.key == "b" }
|
||||
assertEquals(1, filteredByKey.size())
|
||||
assertEquals(1, filteredByKey.size)
|
||||
assertEquals(3, filteredByKey["b"])
|
||||
|
||||
val filteredByKey2 = map.filterKeys { it == "b" }
|
||||
assertEquals(1, filteredByKey2.size())
|
||||
assertEquals(1, filteredByKey2.size)
|
||||
assertEquals(3, filteredByKey2["b"])
|
||||
|
||||
val filteredByValue = map.filter { it.value == 2 }
|
||||
assertEquals(2, filteredByValue.size())
|
||||
assertEquals(2, filteredByValue.size)
|
||||
assertEquals(null, filteredByValue["b"])
|
||||
assertEquals(2, filteredByValue["c"])
|
||||
assertEquals(2, filteredByValue["a"])
|
||||
|
||||
val filteredByValue2 = map.filterValues { it == 2 }
|
||||
assertEquals(2, filteredByValue2.size())
|
||||
assertEquals(2, filteredByValue2.size)
|
||||
assertEquals(null, filteredByValue2["b"])
|
||||
assertEquals(2, filteredByValue2["c"])
|
||||
assertEquals(2, filteredByValue2["a"])
|
||||
@@ -262,20 +262,20 @@ class MapTest {
|
||||
@test fun filterNot() {
|
||||
val map = mapOf(Pair("b", 3), Pair("c", 2), Pair("a", 2))
|
||||
val filteredByKey = map.filterNot { it.key == "b" }
|
||||
assertEquals(2, filteredByKey.size())
|
||||
assertEquals(2, filteredByKey.size)
|
||||
assertEquals(null, filteredByKey["b"])
|
||||
assertEquals(2, filteredByKey["c"])
|
||||
assertEquals(2, filteredByKey["a"])
|
||||
|
||||
val filteredByValue = map.filterNot { it.value == 2 }
|
||||
assertEquals(1, filteredByValue.size())
|
||||
assertEquals(1, filteredByValue.size)
|
||||
assertEquals(3, filteredByValue["b"])
|
||||
}
|
||||
|
||||
fun testPlusAssign(doPlusAssign: (MutableMap<String, Int>) -> Unit) {
|
||||
val map = hashMapOf("a" to 1, "b" to 2)
|
||||
doPlusAssign(map)
|
||||
assertEquals(3, map.size())
|
||||
assertEquals(3, map.size)
|
||||
assertEquals(1, map["a"])
|
||||
assertEquals(4, map["b"])
|
||||
assertEquals(3, map["c"])
|
||||
@@ -297,7 +297,7 @@ class MapTest {
|
||||
fun testPlus(doPlus: (Map<String, Int>) -> Map<String, Int>) {
|
||||
val original = mapOf("A" to 1, "B" to 2)
|
||||
val extended = doPlus(original)
|
||||
assertEquals(3, extended.size())
|
||||
assertEquals(3, extended.size)
|
||||
assertEquals(1, extended["A"])
|
||||
assertEquals(4, extended["B"])
|
||||
assertEquals(3, extended["C"])
|
||||
|
||||
@@ -21,6 +21,6 @@ class SequenceJVMTest {
|
||||
assertEquals(src.toList(), anyValues.toArrayList())
|
||||
|
||||
val charValues: Sequence<Char> = src.filterIsInstance<Char>()
|
||||
assertEquals(0, charValues.toArrayList().size())
|
||||
assertEquals(0, charValues.toArrayList().size)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,7 +267,7 @@ public class SequenceTest {
|
||||
@test fun sequenceExtensions() {
|
||||
val d = ArrayList<Int>()
|
||||
sequenceOf(0, 1, 2, 3, 4, 5).takeWhileTo(d, { i -> i < 4 })
|
||||
assertEquals(4, d.size())
|
||||
assertEquals(4, d.size)
|
||||
}
|
||||
|
||||
@test fun flatMapAndTakeExtractTheTransformedElements() {
|
||||
@@ -330,8 +330,8 @@ public class SequenceTest {
|
||||
|
||||
@test fun sortedBy() {
|
||||
sequenceOf("it", "greater", "less").let {
|
||||
it.sortedBy { it.length() }.iterator().assertSorted { a, b -> compareValuesBy(a, b) { it.length() } <= 0 }
|
||||
it.sortedByDescending { it.length() }.iterator().assertSorted { a, b -> compareValuesBy(a, b) { it.length() } >= 0 }
|
||||
it.sortedBy { it.length }.iterator().assertSorted { a, b -> compareValuesBy(a, b) { it.length } <= 0 }
|
||||
it.sortedByDescending { it.length }.iterator().assertSorted { a, b -> compareValuesBy(a, b) { it.length } >= 0 }
|
||||
}
|
||||
|
||||
sequenceOf('a', 'd', 'c', null).let {
|
||||
|
||||
@@ -10,7 +10,7 @@ class SetOperationsTest {
|
||||
}
|
||||
|
||||
@test fun distinctBy() {
|
||||
assertEquals(listOf("some", "cat", "do"), arrayOf("some", "case", "cat", "do", "dog", "it").distinctBy { it.length() })
|
||||
assertEquals(listOf("some", "cat", "do"), arrayOf("some", "case", "cat", "do", "dog", "it").distinctBy { it.length })
|
||||
assertTrue(charArrayOf().distinctBy { it }.isEmpty())
|
||||
}
|
||||
|
||||
|
||||
@@ -359,7 +359,7 @@ class FilesTest {
|
||||
basedir.walkTopDown().enter(::beforeVisitDirectory).leave(::afterVisitDirectory).maxDepth(1).
|
||||
forEach { it -> if (it != basedir) visitFile(it) }
|
||||
assert(stack.isEmpty())
|
||||
assert(dirs.size() == 1 && dirs.contains("")) { dirs.size() }
|
||||
assert(dirs.size == 1 && dirs.contains("")) { dirs.size }
|
||||
for (file in arrayOf("1", "6", "7.txt", "8")) {
|
||||
assert(files.contains(file)) { file }
|
||||
}
|
||||
@@ -372,12 +372,12 @@ class FilesTest {
|
||||
basedir.walkTopDown().enter(::beforeVisitDirectory).leave(::afterVisitDirectory).
|
||||
fail(::visitDirectoryFailed).forEach { it -> if (!it.isDirectory()) visitFile(it) }
|
||||
assert(stack.isEmpty())
|
||||
assert(failed.size() == 1 && failed.contains("1")) { failed.size() }
|
||||
assert(dirs.size() == 4) { dirs.size() }
|
||||
assert(failed.size == 1 && failed.contains("1")) { failed.size }
|
||||
assert(dirs.size == 4) { dirs.size }
|
||||
for (dir in arrayOf("", "1", "6", "8")) {
|
||||
assert(dirs.contains(dir)) { dir }
|
||||
}
|
||||
assert(files.size() == 2) { files.size() }
|
||||
assert(files.size == 2) { files.size }
|
||||
for (file in arrayOf("7.txt", "8${sep}9.txt")) {
|
||||
assert(files.contains(file)) { file }
|
||||
}
|
||||
@@ -402,7 +402,7 @@ class FilesTest {
|
||||
visited.add(it)
|
||||
}
|
||||
basedir.walkTopDown().forEach(block)
|
||||
assert(visited.size() == 10) { visited.size() }
|
||||
assert(visited.size == 10) { visited.size }
|
||||
|
||||
} finally {
|
||||
basedir.deleteRecursively()
|
||||
@@ -421,7 +421,7 @@ class FilesTest {
|
||||
visited.add(it)
|
||||
}
|
||||
basedir.walkTopDown().forEach(block)
|
||||
assert(visited.size() == 6) { visited.size() }
|
||||
assert(visited.size == 6) { visited.size }
|
||||
}
|
||||
} finally {
|
||||
restricted.setReadable(true)
|
||||
@@ -491,7 +491,7 @@ class FilesTest {
|
||||
found.add(file.getParentFile())
|
||||
}
|
||||
}
|
||||
assert(found.size() == 3)
|
||||
assert(found.size == 3)
|
||||
} finally {
|
||||
basedir.deleteRecursively()
|
||||
}
|
||||
@@ -532,10 +532,10 @@ class FilesTest {
|
||||
|
||||
// This line works only with Kotlin File.listFiles(filter)
|
||||
val result = dir.listFiles { it.getName().endsWith(".kt") }
|
||||
assertEquals(2, result!!.size())
|
||||
assertEquals(2, result!!.size)
|
||||
// This line works both with Kotlin File.listFiles(filter) and the same Java function because of SAM
|
||||
val result2 = dir.listFiles { it -> it.getName().endsWith(".kt") }
|
||||
assertEquals(2, result2!!.size())
|
||||
assertEquals(2, result2!!.size)
|
||||
}
|
||||
|
||||
@test fun relativeToTest() {
|
||||
@@ -602,10 +602,10 @@ class FilesTest {
|
||||
var i = 0
|
||||
assertEquals(root, f.root)
|
||||
for (elem in f.filePathComponents().fileList) {
|
||||
assertTrue(i < elements.size(), i.toString())
|
||||
assertTrue(i < elements.size, i.toString())
|
||||
assertEquals(elements[i++], elem.toString())
|
||||
}
|
||||
assertEquals(elements.size(), i)
|
||||
assertEquals(elements.size, i)
|
||||
}
|
||||
|
||||
@test fun fileIterator() {
|
||||
|
||||
@@ -6,7 +6,7 @@ fun testSize(): Int {
|
||||
val a2 = arrayOf("foo")
|
||||
val a3 = arrayOf("foo", "bar")
|
||||
|
||||
return a1.size() + a2.size() + a3.size()
|
||||
return a1.size + a2.size + a3.size
|
||||
}
|
||||
|
||||
fun testToListToString(): String {
|
||||
|
||||
@@ -11,9 +11,9 @@ class JsArrayTest {
|
||||
val a2 = arrayOf("foo")
|
||||
val a3 = arrayOf("foo", "bar")
|
||||
|
||||
assertEquals(0, a1.size())
|
||||
assertEquals(1, a2.size())
|
||||
assertEquals(2, a3.size())
|
||||
assertEquals(0, a1.size)
|
||||
assertEquals(1, a2.size)
|
||||
assertEquals(2, a3.size)
|
||||
|
||||
assertEquals("[]", a1.toList().toString())
|
||||
assertEquals("[foo]", a2.toList().toString())
|
||||
@@ -25,7 +25,7 @@ class JsArrayTest {
|
||||
var c: Collection<String> = arrayOf("A", "B", "C").toList()
|
||||
var a = ArrayList(c)
|
||||
|
||||
assertEquals(3, a.size())
|
||||
assertEquals(3, a.size)
|
||||
assertEquals("A", a[0])
|
||||
assertEquals("B", a[1])
|
||||
assertEquals("C", a[2])
|
||||
|
||||
@@ -85,7 +85,7 @@ abstract class MapJsTest {
|
||||
|
||||
val b = data.getOrElse("foo"){3}
|
||||
assertEquals(3, b)
|
||||
assertEquals(0, data.size())
|
||||
assertEquals(0, data.size)
|
||||
}
|
||||
|
||||
@test fun getOrPut() {
|
||||
@@ -96,7 +96,7 @@ abstract class MapJsTest {
|
||||
val b = data.getOrPut("foo"){3}
|
||||
assertEquals(2, b)
|
||||
|
||||
assertEquals(1, data.size())
|
||||
assertEquals(1, data.size)
|
||||
}
|
||||
|
||||
@test fun emptyMapGet() {
|
||||
@@ -137,8 +137,8 @@ abstract class MapJsTest {
|
||||
assertTrue(data.isEmpty())
|
||||
assertTrue(data.none())
|
||||
|
||||
assertEquals(0, data.size())
|
||||
assertEquals(0, data.size())
|
||||
assertEquals(0, data.size)
|
||||
assertEquals(0, data.size)
|
||||
}
|
||||
|
||||
@test fun sizeAndEmpty() {
|
||||
@@ -147,7 +147,7 @@ abstract class MapJsTest {
|
||||
assertFalse(data.isEmpty())
|
||||
assertFalse(data.none())
|
||||
|
||||
assertEquals(KEYS.size(), data.size())
|
||||
assertEquals(KEYS.size, data.size)
|
||||
}
|
||||
|
||||
// #KT-3035
|
||||
@@ -208,16 +208,16 @@ abstract class MapJsTest {
|
||||
val map = createTestMap()
|
||||
val newMap = emptyMutableMap()
|
||||
newMap.putAll(map)
|
||||
assertEquals(KEYS.size(), newMap.size())
|
||||
assertEquals(KEYS.size, newMap.size)
|
||||
}
|
||||
|
||||
@test fun mapRemove() {
|
||||
val map = createTestMutableMap()
|
||||
val last = KEYS.size() - 1
|
||||
val last = KEYS.size - 1
|
||||
val first = 0
|
||||
val mid = KEYS.size() / 2
|
||||
val mid = KEYS.size / 2
|
||||
|
||||
assertEquals(KEYS.size(), map.size())
|
||||
assertEquals(KEYS.size, map.size)
|
||||
|
||||
assertEquals(null, map.remove("foo"))
|
||||
assertEquals(VALUES[mid], map.remove(KEYS[mid]))
|
||||
@@ -225,7 +225,7 @@ abstract class MapJsTest {
|
||||
assertEquals(VALUES[last], map.remove(KEYS[last]))
|
||||
assertEquals(VALUES[first], map.remove(KEYS[first]))
|
||||
|
||||
assertEquals(KEYS.size() - 3, map.size())
|
||||
assertEquals(KEYS.size - 3, map.size)
|
||||
}
|
||||
|
||||
@test fun mapClear() {
|
||||
@@ -264,25 +264,25 @@ abstract class MapJsTest {
|
||||
@test fun setViaIndexOperators() {
|
||||
val map = HashMap<String, String>()
|
||||
assertTrue{ map.isEmpty() }
|
||||
assertEquals(map.size(), 0)
|
||||
assertEquals(map.size, 0)
|
||||
|
||||
map["name"] = "James"
|
||||
|
||||
assertTrue{ !map.isEmpty() }
|
||||
assertEquals(map.size(), 1)
|
||||
assertEquals(map.size, 1)
|
||||
assertEquals("James", map["name"])
|
||||
}
|
||||
|
||||
@test fun createUsingPairs() {
|
||||
val map = mapOf(Pair("a", 1), Pair("b", 2))
|
||||
assertEquals(2, map.size())
|
||||
assertEquals(2, map.size)
|
||||
assertEquals(1, map.get("a"))
|
||||
assertEquals(2, map.get("b"))
|
||||
}
|
||||
|
||||
@test fun createUsingTo() {
|
||||
val map = mapOf("a" to 1, "b" to 2)
|
||||
assertEquals(2, map.size())
|
||||
assertEquals(2, map.size)
|
||||
assertEquals(1, map.get("a"))
|
||||
assertEquals(2, map.get("b"))
|
||||
}
|
||||
|
||||
@@ -80,8 +80,8 @@ abstract class SetJsTest {
|
||||
|
||||
@Test
|
||||
fun size() {
|
||||
assertEquals(2, data.size())
|
||||
assertEquals(0, empty.size())
|
||||
assertEquals(2, data.size)
|
||||
assertEquals(0, empty.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -132,9 +132,9 @@ abstract class SetJsTest {
|
||||
fun add() {
|
||||
val data = createTestMutableSet()
|
||||
assertTrue(data.add("baz"))
|
||||
assertEquals(3, data.size())
|
||||
assertEquals(3, data.size)
|
||||
assertFalse(data.add("baz"))
|
||||
assertEquals(3, data.size())
|
||||
assertEquals(3, data.size)
|
||||
assertTrue(data.containsAll(arrayListOf("foo", "bar", "baz")))
|
||||
}
|
||||
|
||||
@@ -142,9 +142,9 @@ abstract class SetJsTest {
|
||||
fun remove() {
|
||||
val data = createTestMutableSet()
|
||||
assertTrue(data.remove("foo"))
|
||||
assertEquals(1, data.size())
|
||||
assertEquals(1, data.size)
|
||||
assertFalse(data.remove("foo"))
|
||||
assertEquals(1, data.size())
|
||||
assertEquals(1, data.size)
|
||||
assertTrue(data.contains("bar"))
|
||||
}
|
||||
|
||||
@@ -152,9 +152,9 @@ abstract class SetJsTest {
|
||||
fun addAll() {
|
||||
val data = createTestMutableSet()
|
||||
assertTrue(data.addAll(arrayListOf("foo", "bar", "baz", "boo")))
|
||||
assertEquals(4, data.size())
|
||||
assertEquals(4, data.size)
|
||||
assertFalse(data.addAll(arrayListOf("foo", "bar", "baz", "boo")))
|
||||
assertEquals(4, data.size())
|
||||
assertEquals(4, data.size)
|
||||
assertTrue(data.containsAll(arrayListOf("foo", "bar", "baz", "boo")))
|
||||
}
|
||||
|
||||
@@ -163,12 +163,12 @@ abstract class SetJsTest {
|
||||
val data = createTestMutableSet()
|
||||
assertFalse(data.removeAll(arrayListOf("baz")))
|
||||
assertTrue(data.containsAll(arrayListOf("foo", "bar")))
|
||||
assertEquals(2, data.size())
|
||||
assertEquals(2, data.size)
|
||||
assertTrue(data.removeAll(arrayListOf("foo")))
|
||||
assertTrue(data.contains("bar"))
|
||||
assertEquals(1, data.size())
|
||||
assertEquals(1, data.size)
|
||||
assertTrue(data.removeAll(arrayListOf("foo", "bar")))
|
||||
assertEquals(0, data.size())
|
||||
assertEquals(0, data.size)
|
||||
|
||||
val data2 = createTestMutableSet()
|
||||
assertFalse(data.removeAll(arrayListOf("foo", "bar", "baz")))
|
||||
@@ -184,7 +184,7 @@ abstract class SetJsTest {
|
||||
val data2 = createTestMutableSet()
|
||||
assertTrue(data2.retainAll(arrayListOf("foo")))
|
||||
assertTrue(data2.contains("foo"))
|
||||
assertEquals(1, data2.size())
|
||||
assertEquals(1, data2.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -137,7 +137,7 @@ class RegexTest {
|
||||
@test fun replaceEvaluator() {
|
||||
val input = "/12/456/7890/"
|
||||
val pattern = "\\d+".toRegex()
|
||||
assertEquals("/2/3/4/", pattern.replace(input, { it.value.length().toString() } ))
|
||||
assertEquals("/2/3/4/", pattern.replace(input, { it.value.length.toString() } ))
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ class StringBuilderTest {
|
||||
val result = sb.toString()
|
||||
val cs = sb as CharSequence
|
||||
|
||||
assertEquals(result.length(), cs.length())
|
||||
assertEquals(result.length(), sb.length())
|
||||
assertEquals(result.length, cs.length)
|
||||
assertEquals(result.length, sb.length)
|
||||
for (index in result.indices) {
|
||||
assertEquals(result[index], sb[index])
|
||||
assertEquals(result[index], cs[index])
|
||||
@@ -43,22 +43,22 @@ class StringBuilderTest {
|
||||
|
||||
@test fun constructors() {
|
||||
StringBuilder().let { sb ->
|
||||
assertEquals(0, sb.length())
|
||||
assertEquals(0, sb.length)
|
||||
assertEquals("", sb.toString())
|
||||
}
|
||||
|
||||
StringBuilder(16).let { sb ->
|
||||
assertEquals(0, sb.length())
|
||||
assertEquals(0, sb.length)
|
||||
assertEquals("", sb.toString())
|
||||
}
|
||||
|
||||
StringBuilder("content").let { sb ->
|
||||
assertEquals(7, sb.length())
|
||||
assertEquals(7, sb.length)
|
||||
assertEquals("content", sb.toString())
|
||||
}
|
||||
|
||||
StringBuilder(StringBuilder("content")).let { sb ->
|
||||
assertEquals(7, sb.length())
|
||||
assertEquals(7, sb.length)
|
||||
assertEquals("content", sb.toString())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -927,7 +927,7 @@ class StringTest {
|
||||
assertFails {
|
||||
data.drop(-2)
|
||||
}
|
||||
assertEquals("", data.drop(data.length() + 5))
|
||||
assertEquals("", data.drop(data.length + 5))
|
||||
}
|
||||
|
||||
@test fun dropCharSequence() = withOneCharSequenceArg("abcd1234") { data ->
|
||||
@@ -935,7 +935,7 @@ class StringTest {
|
||||
assertFails {
|
||||
data.drop(-2)
|
||||
}
|
||||
assertContentEquals("", data.drop(data.length() + 5))
|
||||
assertContentEquals("", data.drop(data.length + 5))
|
||||
}
|
||||
|
||||
@test fun takeWhile() {
|
||||
@@ -957,7 +957,7 @@ class StringTest {
|
||||
assertFails {
|
||||
data.take(-7)
|
||||
}
|
||||
assertEquals(data, data.take(data.length() + 42))
|
||||
assertEquals(data, data.take(data.length + 42))
|
||||
}
|
||||
|
||||
@test fun takeCharSequence() = withOneCharSequenceArg("abcd1234") { data ->
|
||||
@@ -1102,7 +1102,7 @@ ${" "}
|
||||
`XP ' '''''' YPXXXXXX' ''''''`''YPPP
|
||||
""".trimIndent()
|
||||
|
||||
assertEquals(23, deindented.lines().size())
|
||||
assertEquals(23, deindented.lines().size)
|
||||
val indents = deindented.lines().map { "^\\s*".toRegex().find(it)!!.value.length }
|
||||
assertEquals(0, indents.min())
|
||||
assertEquals(42, indents.max())
|
||||
|
||||
@@ -13,7 +13,7 @@ private class PartiallyImplementedClass {
|
||||
if (!switch)
|
||||
TODO("what if false")
|
||||
else {
|
||||
if (value.length() < 3)
|
||||
if (value.length < 3)
|
||||
throw TODO("write message")
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -60,7 +60,7 @@ public abstract class KotlinAnnotationProvider {
|
||||
val shortenedValue = shortenedPackageNameCache.get(id) ?:
|
||||
throw RuntimeException("Value for $id couldn't be found in shrink cache")
|
||||
|
||||
return shortenedValue + '.' + s.substring(id.length() + 1)
|
||||
return shortenedValue + '.' + s.substring(id.length + 1)
|
||||
}
|
||||
|
||||
val annotatedKotlinElements: MutableMap<String, MutableSet<AnnotatedElementDescriptor>> = hashMapOf()
|
||||
@@ -82,7 +82,7 @@ public abstract class KotlinAnnotationProvider {
|
||||
ANNOTATED_CLASS, ANNOTATED_FIELD, ANNOTATED_METHOD -> {
|
||||
val annotationName = expandAnnotation(lineParts[1])
|
||||
val classFqName = expandClassName(lineParts[2]).replace('$', '.')
|
||||
val elementName = if (lineParts.size() == 4) lineParts[3] else null
|
||||
val elementName = if (lineParts.size == 4) lineParts[3] else null
|
||||
|
||||
val set = annotatedKotlinElements.getOrPut(annotationName) { hashSetOf() }
|
||||
set.add(when (type) {
|
||||
|
||||
+2
-2
@@ -271,7 +271,7 @@ public class AnnotationProcessingManager(
|
||||
modifyCompilerArguments { args ->
|
||||
val argIndex = args.indexOfFirst { name == it }
|
||||
|
||||
if (argIndex >= 0 && args.size() > (argIndex + 1)) {
|
||||
if (argIndex >= 0 && args.size > (argIndex + 1)) {
|
||||
args[argIndex + 1] = value(args[argIndex + 1])
|
||||
}
|
||||
else {
|
||||
@@ -334,7 +334,7 @@ public class AnnotationProcessingManager(
|
||||
}
|
||||
|
||||
private fun invokeCoreKaptMethod(methodName: String, vararg args: Any): Any {
|
||||
val array = arrayOfNulls<Class<*>>(args.size())
|
||||
val array = arrayOfNulls<Class<*>>(args.size)
|
||||
args.forEachIndexed { i, arg -> array[i] = arg.javaClass }
|
||||
val method = getCoreKaptPackageClass().getMethod(methodName, *array)
|
||||
return method.invoke(null, *args)
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ private fun comparableVersionStr(version: String) =
|
||||
?.groups
|
||||
?.drop(1)?.take(2)
|
||||
// checking if two subexpression groups are found and length of each is >0 and <4
|
||||
?.let { if (it.all { (it?.value?.length() ?: 0).let { it > 0 && it < 4 }}) it else null }
|
||||
?.let { if (it.all { (it?.value?.length ?: 0).let { it > 0 && it < 4 }}) it else null }
|
||||
?.joinToString(".", transform = { it!!.value.padStart(3, '0') })
|
||||
|
||||
|
||||
|
||||
+6
-6
@@ -157,7 +157,7 @@ class Kotlin2JvmSourceSetProcessor(
|
||||
val subpluginEnvironment = loadSubplugins(project)
|
||||
subpluginEnvironment.addSubpluginArguments(project, kotlinTask)
|
||||
|
||||
if (aptConfiguration.getDependencies().size() > 1 && javaTask is JavaCompile) {
|
||||
if (aptConfiguration.getDependencies().size > 1 && javaTask is JavaCompile) {
|
||||
val (aptOutputDir, aptWorkingDir) = project.getAptDirsForSourceSet(sourceSetName)
|
||||
|
||||
val kaptManager = AnnotationProcessingManager(kotlinTask, javaTask, sourceSetName,
|
||||
@@ -389,7 +389,7 @@ open class KotlinAndroidPlugin @Inject constructor(val scriptHandler: ScriptHand
|
||||
|
||||
val aptConfiguration = aptConfigurations[(provider as AndroidSourceSet).getName()]
|
||||
// Ignore if there's only an annotation processor wrapper in dependencies (added by default)
|
||||
if (aptConfiguration != null && aptConfiguration.getDependencies().size() > 1) {
|
||||
if (aptConfiguration != null && aptConfiguration.getDependencies().size > 1) {
|
||||
aptFiles.addAll(aptConfiguration.resolve())
|
||||
}
|
||||
}
|
||||
@@ -598,7 +598,7 @@ private fun compareVersionNumbers(v1: String?, v2: String?): Int {
|
||||
val part2 = v2.split(pattern)
|
||||
|
||||
var idx = 0
|
||||
while (idx < part1.size() && idx < part2.size()) {
|
||||
while (idx < part1.size && idx < part2.size) {
|
||||
val p1 = part1[idx]
|
||||
val p2 = part2[idx]
|
||||
|
||||
@@ -612,13 +612,13 @@ private fun compareVersionNumbers(v1: String?, v2: String?): Int {
|
||||
idx++
|
||||
}
|
||||
|
||||
if (part1.size() == part2.size()) {
|
||||
if (part1.size == part2.size) {
|
||||
return 0
|
||||
} else {
|
||||
val left = part1.size() > idx
|
||||
val left = part1.size > idx
|
||||
val parts = if (left) part1 else part2
|
||||
|
||||
while (idx < parts.size()) {
|
||||
while (idx < parts.size) {
|
||||
val p = parts[idx]
|
||||
val cmp: Int
|
||||
if (p.matches(digitsPattern)) {
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ class KotlinGradleIT: BaseGradleIT() {
|
||||
project.build(userVariantArg, "build", options = BaseGradleIT.BuildOptions(withDaemon = true)) {
|
||||
assertSuccessful()
|
||||
val matches = "\\[PERF\\] Used memory after build: (\\d+) kb \\(([+-]?\\d+) kb\\)".toRegex().find(output)
|
||||
assert(matches != null && matches.groups.size() == 3) { "Used memory after build is not reported by plugin" }
|
||||
assert(matches != null && matches.groups.size == 3) { "Used memory after build is not reported by plugin" }
|
||||
val reportedGrowth = matches!!.groups.get(2)!!.value.removePrefix("+").toInt()
|
||||
assert(reportedGrowth <= 700) { "Used memory growth $reportedGrowth > 700" }
|
||||
}
|
||||
|
||||
@@ -106,10 +106,10 @@ fun aggregates(): List<GenericFunction> {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
doc(CharSequences) { "Returns the length of this char sequence."}
|
||||
body(CharSequences, Strings) {
|
||||
"return length()"
|
||||
"return length"
|
||||
}
|
||||
body(Maps, Collections, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"return size()"
|
||||
"return size"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ fun arrays(): List<GenericFunction> {
|
||||
doc { "Returns `true` if the array is empty." }
|
||||
returns("Boolean")
|
||||
body {
|
||||
"return size() == 0"
|
||||
"return size == 0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ fun arrays(): List<GenericFunction> {
|
||||
doc { "Returns the last valid index for the array." }
|
||||
returns("Int")
|
||||
body {
|
||||
"get() = size() - 1"
|
||||
"get() = size - 1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ fun arrays(): List<GenericFunction> {
|
||||
// TODO: Use different implementations for JS
|
||||
body {
|
||||
"""
|
||||
val result = $arrayType(size())
|
||||
val result = $arrayType(size)
|
||||
for (index in indices)
|
||||
result[index] = this[index]
|
||||
return result
|
||||
@@ -73,7 +73,7 @@ fun arrays(): List<GenericFunction> {
|
||||
}
|
||||
body(Collections) {
|
||||
"""
|
||||
val result = $arrayType(size())
|
||||
val result = $arrayType(size)
|
||||
var index = 0
|
||||
for (element in this)
|
||||
result[index++] = element
|
||||
|
||||
@@ -577,7 +577,7 @@ fun elements(): List<GenericFunction> {
|
||||
body {
|
||||
"""
|
||||
when (this) {
|
||||
is List -> return if (isEmpty()) null else this[size() - 1]
|
||||
is List -> return if (isEmpty()) null else this[size - 1]
|
||||
else -> {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
@@ -604,12 +604,12 @@ fun elements(): List<GenericFunction> {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) {
|
||||
"""
|
||||
return if (isEmpty()) null else this[length() - 1]
|
||||
return if (isEmpty()) null else this[length - 1]
|
||||
"""
|
||||
}
|
||||
body(Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
return if (isEmpty()) null else this[size() - 1]
|
||||
return if (isEmpty()) null else this[size - 1]
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -704,7 +704,7 @@ fun elements(): List<GenericFunction> {
|
||||
body {
|
||||
"""
|
||||
when (this) {
|
||||
is List -> return when (size()) {
|
||||
is List -> return when (size) {
|
||||
0 -> throw NoSuchElementException("Collection is empty.")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element.")
|
||||
@@ -735,7 +735,7 @@ fun elements(): List<GenericFunction> {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) {
|
||||
"""
|
||||
return when (length()) {
|
||||
return when (length) {
|
||||
0 -> throw NoSuchElementException("Collection is empty.")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element.")
|
||||
@@ -744,7 +744,7 @@ fun elements(): List<GenericFunction> {
|
||||
}
|
||||
body(Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
return when (size()) {
|
||||
return when (size) {
|
||||
0 -> throw NoSuchElementException("Collection is empty.")
|
||||
1 -> this[0]
|
||||
else -> throw IllegalArgumentException("Collection has more than one element.")
|
||||
@@ -759,7 +759,7 @@ fun elements(): List<GenericFunction> {
|
||||
body {
|
||||
"""
|
||||
when (this) {
|
||||
is List -> return if (size() == 1) this[0] else null
|
||||
is List -> return if (size == 1) this[0] else null
|
||||
else -> {
|
||||
val iterator = iterator()
|
||||
if (!iterator.hasNext())
|
||||
@@ -786,12 +786,12 @@ fun elements(): List<GenericFunction> {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) {
|
||||
"""
|
||||
return if (length() == 1) this[0] else null
|
||||
return if (length == 1) this[0] else null
|
||||
"""
|
||||
}
|
||||
body(Lists, ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
return if (size() == 1) this[0] else null
|
||||
return if (size == 1) this[0] else null
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,13 +30,13 @@ fun filtering(): List<GenericFunction> {
|
||||
if (n == 0) return toList()
|
||||
val list: ArrayList<T>
|
||||
if (this is Collection<*>) {
|
||||
val resultSize = size() - n
|
||||
val resultSize = size - n
|
||||
if (resultSize <= 0)
|
||||
return emptyList()
|
||||
|
||||
list = ArrayList<T>(resultSize)
|
||||
if (this is List<T>) {
|
||||
for (index in n..size() - 1) {
|
||||
for (index in n..size - 1) {
|
||||
list.add(this[index])
|
||||
}
|
||||
return list
|
||||
@@ -77,11 +77,11 @@ fun filtering(): List<GenericFunction> {
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
if (n == 0)
|
||||
return toList()
|
||||
if (n >= size())
|
||||
if (n >= size)
|
||||
return emptyList()
|
||||
|
||||
val list = ArrayList<T>(size() - n)
|
||||
for (index in n..size() - 1) {
|
||||
val list = ArrayList<T>(size - n)
|
||||
for (index in n..size - 1) {
|
||||
list.add(this[index])
|
||||
}
|
||||
return list
|
||||
@@ -97,7 +97,7 @@ fun filtering(): List<GenericFunction> {
|
||||
"""
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
if (n == 0) return emptyList()
|
||||
if (this is Collection<T> && n >= size()) return toList()
|
||||
if (this is Collection<T> && n >= size) return toList()
|
||||
var count = 0
|
||||
val list = ArrayList<T>(n)
|
||||
for (item in this) {
|
||||
@@ -132,7 +132,7 @@ fun filtering(): List<GenericFunction> {
|
||||
"""
|
||||
require(n >= 0) { "Requested element count $n is less than zero." }
|
||||
if (n == 0) return emptyList()
|
||||
if (n >= size()) return toList()
|
||||
if (n >= size) return toList()
|
||||
var count = 0
|
||||
val list = ArrayList<T>(n)
|
||||
for (item in this) {
|
||||
@@ -154,7 +154,7 @@ fun filtering(): List<GenericFunction> {
|
||||
body {
|
||||
"""
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
return take((size() - n).coerceAtLeast(0))
|
||||
return take((size - n).coerceAtLeast(0))
|
||||
"""
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ fun filtering(): List<GenericFunction> {
|
||||
"""
|
||||
require(n >= 0, { "Requested element count $n is less than zero." })
|
||||
if (n == 0) return emptyList()
|
||||
val size = size()
|
||||
val size = size
|
||||
if (n >= size) return toList()
|
||||
val list = ArrayList<T>(n)
|
||||
for (index in size - n .. size - 1)
|
||||
@@ -390,7 +390,7 @@ fun filtering(): List<GenericFunction> {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) {
|
||||
"""
|
||||
for (index in 0..length() - 1) {
|
||||
for (index in 0..length - 1) {
|
||||
val element = get(index)
|
||||
if (predicate(element)) destination.append(element)
|
||||
}
|
||||
@@ -593,7 +593,7 @@ fun filtering(): List<GenericFunction> {
|
||||
returns("SELF")
|
||||
body(ArraysOfObjects) {
|
||||
"""
|
||||
val result = arrayOfNulls(this, indices.size()) as Array<T>
|
||||
val result = arrayOfNulls(this, indices.size) as Array<T>
|
||||
var targetIndex = 0
|
||||
for (sourceIndex in indices) {
|
||||
result[targetIndex++] = this[sourceIndex]
|
||||
@@ -603,7 +603,7 @@ fun filtering(): List<GenericFunction> {
|
||||
}
|
||||
body(ArraysOfPrimitives) {
|
||||
"""
|
||||
val result = SELF(indices.size())
|
||||
val result = SELF(indices.size)
|
||||
var targetIndex = 0
|
||||
for (sourceIndex in indices) {
|
||||
result[targetIndex++] = this[sourceIndex]
|
||||
|
||||
@@ -23,7 +23,7 @@ fun generators(): List<GenericFunction> {
|
||||
}
|
||||
body(Collections) {
|
||||
"""
|
||||
val result = ArrayList<T>(size() + 1)
|
||||
val result = ArrayList<T>(size + 1)
|
||||
result.addAll(this)
|
||||
result.add(element)
|
||||
return result
|
||||
@@ -36,7 +36,7 @@ fun generators(): List<GenericFunction> {
|
||||
doc(Sets) { "Returns a set containing all elements of the original set and then the given [element]." }
|
||||
body(Sets) {
|
||||
"""
|
||||
val result = LinkedHashSet<T>(mapCapacity(size() + 1))
|
||||
val result = LinkedHashSet<T>(mapCapacity(size + 1))
|
||||
result.addAll(this)
|
||||
result.add(element)
|
||||
return result
|
||||
@@ -70,7 +70,7 @@ fun generators(): List<GenericFunction> {
|
||||
body(Collections) {
|
||||
"""
|
||||
if (collection is Collection) {
|
||||
val result = ArrayList<T>(this.size() + collection.size())
|
||||
val result = ArrayList<T>(this.size + collection.size)
|
||||
result.addAll(this)
|
||||
result.addAll(collection)
|
||||
return result
|
||||
@@ -86,7 +86,7 @@ fun generators(): List<GenericFunction> {
|
||||
doc(Sets) { "Returns a set containing all elements both of the original set and the given [collection]." }
|
||||
body(Sets) {
|
||||
"""
|
||||
val result = LinkedHashSet<T>(mapCapacity(collection.collectionSizeOrNull()?.let { this.size() + it } ?: this.size() * 2))
|
||||
val result = LinkedHashSet<T>(mapCapacity(collection.collectionSizeOrNull()?.let { this.size + it } ?: this.size * 2))
|
||||
result.addAll(this)
|
||||
result.addAll(collection)
|
||||
return result
|
||||
@@ -126,7 +126,7 @@ fun generators(): List<GenericFunction> {
|
||||
}
|
||||
body(Collections) {
|
||||
"""
|
||||
val result = ArrayList<T>(this.size() + array.size())
|
||||
val result = ArrayList<T>(this.size + array.size)
|
||||
result.addAll(this)
|
||||
result.addAll(array)
|
||||
return result
|
||||
@@ -135,7 +135,7 @@ fun generators(): List<GenericFunction> {
|
||||
doc(Sets) { "Returns a set containing all elements both of the original set and the given [array]." }
|
||||
body(Sets) {
|
||||
"""
|
||||
val result = LinkedHashSet<T>(mapCapacity(this.size() + array.size()))
|
||||
val result = LinkedHashSet<T>(mapCapacity(this.size + array.size))
|
||||
result.addAll(this)
|
||||
result.addAll(array)
|
||||
return result
|
||||
@@ -174,7 +174,7 @@ fun generators(): List<GenericFunction> {
|
||||
}
|
||||
body(Collections) {
|
||||
"""
|
||||
val result = ArrayList<T>(this.size() + 10)
|
||||
val result = ArrayList<T>(this.size + 10)
|
||||
result.addAll(this)
|
||||
result.addAll(sequence)
|
||||
return result
|
||||
@@ -185,7 +185,7 @@ fun generators(): List<GenericFunction> {
|
||||
doc(Sets) { "Returns a set containing all elements both of the original set and the given [sequence]." }
|
||||
body(Sets) {
|
||||
"""
|
||||
val result = LinkedHashSet<T>(mapCapacity(this.size() * 2))
|
||||
val result = LinkedHashSet<T>(mapCapacity(this.size * 2))
|
||||
result.addAll(this)
|
||||
result.addAll(sequence)
|
||||
return result
|
||||
@@ -225,7 +225,7 @@ fun generators(): List<GenericFunction> {
|
||||
doc(Sets) { "Returns a set containing all elements of the original set except the given [element]." }
|
||||
body(Sets) {
|
||||
"""
|
||||
val result = LinkedHashSet<T>(mapCapacity(size()))
|
||||
val result = LinkedHashSet<T>(mapCapacity(size))
|
||||
var removed = false
|
||||
return this.filterTo(result) { if (!removed && it == element) { removed = true; false } else true }
|
||||
"""
|
||||
@@ -469,7 +469,7 @@ fun generators(): List<GenericFunction> {
|
||||
}
|
||||
body(ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
val arraySize = size()
|
||||
val arraySize = size
|
||||
val list = ArrayList<V>(Math.min(other.collectionSizeOrDefault(10), arraySize))
|
||||
var i = 0
|
||||
for (element in other) {
|
||||
@@ -494,7 +494,7 @@ fun generators(): List<GenericFunction> {
|
||||
inline(true)
|
||||
body {
|
||||
"""
|
||||
val arraySize = array.size()
|
||||
val arraySize = array.size
|
||||
val list = ArrayList<V>(Math.min(collectionSizeOrDefault(10), arraySize))
|
||||
var i = 0
|
||||
for (element in this) {
|
||||
@@ -506,7 +506,7 @@ fun generators(): List<GenericFunction> {
|
||||
}
|
||||
body(ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
val size = Math.min(size(), array.size())
|
||||
val size = Math.min(size, array.size)
|
||||
val list = ArrayList<V>(size)
|
||||
for (i in 0..size-1) {
|
||||
list.add(transform(this[i], array[i]))
|
||||
@@ -529,7 +529,7 @@ fun generators(): List<GenericFunction> {
|
||||
inline(true)
|
||||
body() {
|
||||
"""
|
||||
val size = Math.min(size(), array.size())
|
||||
val size = Math.min(size, array.size)
|
||||
val list = ArrayList<V>(size)
|
||||
for (i in 0..size-1) {
|
||||
list.add(transform(this[i], array[i]))
|
||||
@@ -569,7 +569,7 @@ fun generators(): List<GenericFunction> {
|
||||
inline(true)
|
||||
body {
|
||||
"""
|
||||
val length = Math.min(this.length(), other.length())
|
||||
val length = Math.min(this.length, other.length)
|
||||
|
||||
val list = ArrayList<V>(length)
|
||||
for (i in 0..length-1) {
|
||||
|
||||
@@ -42,11 +42,11 @@ fun mapping(): List<GenericFunction> {
|
||||
"return mapIndexedTo(ArrayList<R>(collectionSizeOrDefault(10)), transform)"
|
||||
}
|
||||
body(ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"return mapIndexedTo(ArrayList<R>(size()), transform)"
|
||||
"return mapIndexedTo(ArrayList<R>(size), transform)"
|
||||
}
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) {
|
||||
"return mapIndexedTo(ArrayList<R>(length()), transform)"
|
||||
"return mapIndexedTo(ArrayList<R>(length), transform)"
|
||||
}
|
||||
inline(false, Sequences)
|
||||
returns(Sequences) { "Sequence<R>" }
|
||||
@@ -70,11 +70,11 @@ fun mapping(): List<GenericFunction> {
|
||||
"return mapTo(ArrayList<R>(collectionSizeOrDefault(10)), transform)"
|
||||
}
|
||||
body(ArraysOfObjects, ArraysOfPrimitives, Maps) {
|
||||
"return mapTo(ArrayList<R>(size()), transform)"
|
||||
"return mapTo(ArrayList<R>(size), transform)"
|
||||
}
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) {
|
||||
"return mapTo(ArrayList<R>(length()), transform)"
|
||||
"return mapTo(ArrayList<R>(length), transform)"
|
||||
}
|
||||
|
||||
inline(false, Sequences)
|
||||
|
||||
@@ -68,7 +68,7 @@ fun ordering(): List<GenericFunction> {
|
||||
body(ArraysOfObjects) {
|
||||
"""
|
||||
if (isEmpty()) return this
|
||||
val result = arrayOfNulls(this, size()) as Array<T>
|
||||
val result = arrayOfNulls(this, size) as Array<T>
|
||||
val lastIndex = lastIndex
|
||||
for (i in 0..lastIndex)
|
||||
result[lastIndex - i] = this[i]
|
||||
@@ -78,7 +78,7 @@ fun ordering(): List<GenericFunction> {
|
||||
body(ArraysOfPrimitives) {
|
||||
"""
|
||||
if (isEmpty()) return this
|
||||
val result = SELF(size())
|
||||
val result = SELF(size)
|
||||
val lastIndex = lastIndex
|
||||
for (i in 0..lastIndex)
|
||||
result[lastIndex - i] = this[i]
|
||||
|
||||
@@ -22,7 +22,7 @@ fun sets(): List<GenericFunction> {
|
||||
}
|
||||
body(ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
val set = LinkedHashSet<T>(mapCapacity(size()))
|
||||
val set = LinkedHashSet<T>(mapCapacity(size))
|
||||
for (item in this) set.add(item)
|
||||
return set
|
||||
"""
|
||||
|
||||
@@ -29,8 +29,8 @@ fun snapshots(): List<GenericFunction> {
|
||||
body { "return toCollection(LinkedHashSet<T>(mapCapacity(collectionSizeOrDefault(12))))" }
|
||||
body(Sequences) { "return toCollection(LinkedHashSet<T>())" }
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) { "return toCollection(LinkedHashSet<T>(mapCapacity(length())))" }
|
||||
body(ArraysOfObjects, ArraysOfPrimitives) { "return toCollection(LinkedHashSet<T>(mapCapacity(size())))" }
|
||||
body(CharSequences, Strings) { "return toCollection(LinkedHashSet<T>(mapCapacity(length)))" }
|
||||
body(ArraysOfObjects, ArraysOfPrimitives) { "return toCollection(LinkedHashSet<T>(mapCapacity(size)))" }
|
||||
}
|
||||
|
||||
templates add f("toHashSet()") {
|
||||
@@ -39,8 +39,8 @@ fun snapshots(): List<GenericFunction> {
|
||||
body { "return toCollection(HashSet<T>(mapCapacity(collectionSizeOrDefault(12))))" }
|
||||
body(Sequences) { "return toCollection(HashSet<T>())" }
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) { "return toCollection(HashSet<T>(mapCapacity(length())))" }
|
||||
body(ArraysOfObjects, ArraysOfPrimitives) { "return toCollection(HashSet<T>(mapCapacity(size())))" }
|
||||
body(CharSequences, Strings) { "return toCollection(HashSet<T>(mapCapacity(length)))" }
|
||||
body(ArraysOfObjects, ArraysOfPrimitives) { "return toCollection(HashSet<T>(mapCapacity(size)))" }
|
||||
}
|
||||
|
||||
templates add f("toSortedSet()") {
|
||||
@@ -64,11 +64,11 @@ fun snapshots(): List<GenericFunction> {
|
||||
}
|
||||
body(Collections) { "return ArrayList(this)" }
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) { "return toCollection(ArrayList<T>(length()))" }
|
||||
body(CharSequences, Strings) { "return toCollection(ArrayList<T>(length))" }
|
||||
body(ArraysOfObjects) { "return ArrayList(this.asCollection())" }
|
||||
body(ArraysOfPrimitives) {
|
||||
"""
|
||||
val list = ArrayList<T>(size())
|
||||
val list = ArrayList<T>(size)
|
||||
for (item in this) list.add(item)
|
||||
return list
|
||||
"""
|
||||
@@ -81,7 +81,7 @@ fun snapshots(): List<GenericFunction> {
|
||||
returns("List<Pair<K, V>>")
|
||||
body {
|
||||
"""
|
||||
val result = ArrayList<Pair<K, V>>(size())
|
||||
val result = ArrayList<Pair<K, V>>(size)
|
||||
for (item in this)
|
||||
result.add(item.key to item.value)
|
||||
return result
|
||||
@@ -153,7 +153,7 @@ fun snapshots(): List<GenericFunction> {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) {
|
||||
"""
|
||||
val capacity = (length()/.75f) + 1
|
||||
val capacity = (length/.75f) + 1
|
||||
val result = LinkedHashMap<K, T>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), element)
|
||||
@@ -163,7 +163,7 @@ fun snapshots(): List<GenericFunction> {
|
||||
}
|
||||
body(ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
val capacity = (size()/.75f) + 1
|
||||
val capacity = (size/.75f) + 1
|
||||
val result = LinkedHashMap<K, T>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), element)
|
||||
@@ -212,7 +212,7 @@ fun snapshots(): List<GenericFunction> {
|
||||
deprecate(Strings) { forBinaryCompatibility }
|
||||
body(CharSequences, Strings) {
|
||||
"""
|
||||
val capacity = (length()/.75f) + 1
|
||||
val capacity = (length/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
@@ -222,7 +222,7 @@ fun snapshots(): List<GenericFunction> {
|
||||
}
|
||||
body(ArraysOfObjects, ArraysOfPrimitives) {
|
||||
"""
|
||||
val capacity = (size()/.75f) + 1
|
||||
val capacity = (size/.75f) + 1
|
||||
val result = LinkedHashMap<K, V>(Math.max(capacity.toInt(), 16))
|
||||
for (element in this) {
|
||||
result.put(selector(element), transform(element))
|
||||
|
||||
@@ -13,7 +13,7 @@ fun specialJVM(): List<GenericFunction> {
|
||||
doc { "Returns an array containing all elements of the original array and then the given [element]." }
|
||||
body() {
|
||||
"""
|
||||
val index = size()
|
||||
val index = size
|
||||
val result = Arrays.copyOf(this, index + 1)
|
||||
result[index] = element
|
||||
return result
|
||||
@@ -29,8 +29,8 @@ fun specialJVM(): List<GenericFunction> {
|
||||
doc { "Returns an array containing all elements of the original array and then all elements of the given [collection]." }
|
||||
body {
|
||||
"""
|
||||
var index = size()
|
||||
val result = Arrays.copyOf(this, index + collection.size())
|
||||
var index = size
|
||||
val result = Arrays.copyOf(this, index + collection.size)
|
||||
for (element in collection) result[index++] = element
|
||||
return result
|
||||
"""
|
||||
@@ -46,8 +46,8 @@ fun specialJVM(): List<GenericFunction> {
|
||||
returns("SELF")
|
||||
body {
|
||||
"""
|
||||
val thisSize = size()
|
||||
val arraySize = array.size()
|
||||
val thisSize = size
|
||||
val arraySize = array.size
|
||||
val result = Arrays.copyOf(this, thisSize + arraySize)
|
||||
System.arraycopy(array, 0, result, thisSize, arraySize)
|
||||
return result
|
||||
@@ -72,7 +72,7 @@ fun specialJVM(): List<GenericFunction> {
|
||||
returns("SELF")
|
||||
annotations(InvariantArraysOfObjects) { """@JvmName("mutableCopyOf")"""}
|
||||
body {
|
||||
"return Arrays.copyOf(this, size())"
|
||||
"return Arrays.copyOf(this, size)"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ fun specialJVM(): List<GenericFunction> {
|
||||
annotations(InvariantArraysOfObjects) { """@JvmName("mutableCopyOf")"""}
|
||||
}
|
||||
|
||||
templates add f("fill(element: T, fromIndex: Int = 0, toIndex: Int = size())") {
|
||||
templates add f("fill(element: T, fromIndex: Int = 0, toIndex: Int = size)") {
|
||||
only(InvariantArraysOfObjects, ArraysOfPrimitives)
|
||||
doc { "Fills original array with the provided value." }
|
||||
returns { "Unit" }
|
||||
@@ -100,7 +100,7 @@ fun specialJVM(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("binarySearch(element: T, fromIndex: Int = 0, toIndex: Int = size())") {
|
||||
templates add f("binarySearch(element: T, fromIndex: Int = 0, toIndex: Int = size)") {
|
||||
only(ArraysOfObjects, ArraysOfPrimitives)
|
||||
exclude(PrimitiveType.Boolean)
|
||||
doc { "Searches array or range of array for provided element index using binary search algorithm. Array is expected to be sorted." }
|
||||
@@ -110,7 +110,7 @@ fun specialJVM(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("binarySearch(element: T, comparator: Comparator<in T>, fromIndex: Int = 0, toIndex: Int = size())") {
|
||||
templates add f("binarySearch(element: T, comparator: Comparator<in T>, fromIndex: Int = 0, toIndex: Int = size)") {
|
||||
only(ArraysOfObjects)
|
||||
doc { "Searches array or range of array for provided element index using binary search algorithm. Array is expected to be sorted according to the specified [comparator]." }
|
||||
returns("Int")
|
||||
@@ -130,7 +130,7 @@ fun specialJVM(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("sort(fromIndex: Int = 0, toIndex: Int = size())") {
|
||||
templates add f("sort(fromIndex: Int = 0, toIndex: Int = size)") {
|
||||
only(ArraysOfObjects, ArraysOfPrimitives)
|
||||
exclude(PrimitiveType.Boolean)
|
||||
doc { "Sorts a range in the array in-place." }
|
||||
@@ -149,7 +149,7 @@ fun specialJVM(): List<GenericFunction> {
|
||||
}
|
||||
}
|
||||
|
||||
templates add f("sortWith(comparator: Comparator<in T>, fromIndex: Int = 0, toIndex: Int = size())") {
|
||||
templates add f("sortWith(comparator: Comparator<in T>, fromIndex: Int = 0, toIndex: Int = size)") {
|
||||
only(ArraysOfObjects)
|
||||
doc { "Sorts a range in the array in-place with the given [comparator]." }
|
||||
returns("Unit")
|
||||
@@ -247,7 +247,7 @@ fun specialJVM(): List<GenericFunction> {
|
||||
body(ArraysOfPrimitives) {
|
||||
"""
|
||||
return object : AbstractList<T>(), RandomAccess {
|
||||
override val size: Int get() = this@asList.size()
|
||||
override val size: Int get() = this@asList.size
|
||||
override fun isEmpty(): Boolean = this@asList.isEmpty()
|
||||
override fun contains(o: T): Boolean = this@asList.contains(o)
|
||||
override fun get(index: Int): T = this@asList[index]
|
||||
@@ -268,7 +268,7 @@ fun specialJVM(): List<GenericFunction> {
|
||||
}
|
||||
body {
|
||||
"""
|
||||
val result = arrayOfNulls<T>(size())
|
||||
val result = arrayOfNulls<T>(size)
|
||||
for (index in indices)
|
||||
result[index] = this[index]
|
||||
return result as Array<T>
|
||||
|
||||
Reference in New Issue
Block a user