StdLib deprecations cleanup: length, size, indices and other collection operations.

This commit is contained in:
Ilya Gorbunov
2015-06-25 18:36:52 +03:00
parent 2c31a1a345
commit f3a19ebe11
11 changed files with 42 additions and 42 deletions
+2 -2
View File
@@ -1064,7 +1064,7 @@ public inline fun <T, C : MutableCollection<in T>> Stream<T>.filterTo(destinatio
* Appends all characters matching the given [predicate] to the given [destination].
*/
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)
}
@@ -1819,7 +1819,7 @@ public fun <T> Stream<T>.takeWhile(predicate: (T) -> Boolean): Stream<T> {
* Returns a string containing the first characters that satisfy the given [predicate].
*/
public inline fun String.takeWhile(predicate: (Char) -> Boolean): String {
for (index in 0..length - 1)
for (index in 0..length() - 1)
if (!predicate(get(index))) {
return substring(0, index)
}
+10 -10
View File
@@ -190,7 +190,7 @@ public fun CharSequence.iterator(): CharIterator = object : CharIterator() {
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. */
@@ -298,7 +298,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())
}
/**
@@ -307,7 +307,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())
}
/**
@@ -334,7 +334,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())
}
/**
@@ -343,7 +343,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())
}
/**
@@ -357,7 +357,7 @@ public fun String.replaceRange(firstIndex: Int, lastIndex: Int, replacement: Str
val sb = StringBuilder()
sb.append(this, 0, firstIndex)
sb.append(replacement)
sb.append(this, lastIndex, length)
sb.append(this, lastIndex, length())
return sb.toString()
}
@@ -460,7 +460,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)
}
/**
@@ -469,7 +469,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)
}
/**
@@ -478,7 +478,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)
}
/**
@@ -487,7 +487,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)
}
/**
@@ -394,7 +394,7 @@ class CollectionTest {
val indices = data.indices
assertEquals(0, indices.start)
assertEquals(1, indices.end)
assertEquals(indices, data.size().indices)
assertEquals(0..data.size() - 1, indices)
}
test fun contains() {
@@ -423,8 +423,8 @@ class CollectionTest {
expect(2000000000000, { listOf(3000000000000, 2000000000000).min() })
expect('a', { listOf('a', 'b').min() })
expect("a", { listOf("a", "b").min() })
expect(null, { listOf<Int>().asSequence().min<Int>() })
expect(2, { listOf(2, 3).asSequence().min<Int>() })
expect(null, { listOf<Int>().asSequence().min() })
expect(2, { listOf(2, 3).asSequence().min() })
}
test fun max() {
@@ -434,8 +434,8 @@ class CollectionTest {
expect(3000000000000, { listOf(3000000000000, 2000000000000).max() })
expect('b', { listOf('a', 'b').max() })
expect("b", { listOf("a", "b").max() })
expect(null, { listOf<Int>().asSequence().max<Int>() })
expect(3, { listOf(2, 3).asSequence().max<Int>() })
expect(null, { listOf<Int>().asSequence().max() })
expect(3, { listOf(2, 3).asSequence().max() })
}
test fun minBy() {
@@ -444,8 +444,8 @@ class CollectionTest {
expect(3, { listOf(2, 3).minBy { -it } })
expect('a', { listOf('a', 'b').minBy { "x$it" } })
expect("b", { listOf("b", "abc").minBy { it.length() } })
expect(null, { listOf<Int>().asSequence().minBy<Int, Int> { it } })
expect(3, { listOf(2, 3).asSequence().minBy<Int, Int> { -it } })
expect(null, { listOf<Int>().asSequence().minBy { it } })
expect(3, { listOf(2, 3).asSequence().minBy { -it } })
}
test fun maxBy() {
@@ -454,8 +454,8 @@ class CollectionTest {
expect(2, { listOf(2, 3).maxBy { -it } })
expect('b', { listOf('a', 'b').maxBy { "x$it" } })
expect("abc", { listOf("b", "abc").maxBy { it.length() } })
expect(null, { listOf<Int>().asSequence().maxBy<Int, Int> { it } })
expect(2, { listOf(2, 3).asSequence().maxBy<Int, Int> { -it } })
expect(null, { listOf<Int>().asSequence().maxBy { it } })
expect(2, { listOf(2, 3).asSequence().maxBy { -it } })
}
test fun minByEvaluateOnce() {
@@ -463,7 +463,7 @@ class CollectionTest {
expect(1, { listOf(5, 4, 3, 2, 1).minBy { c++; it * it } })
assertEquals(5, c)
c = 0
expect(1, { listOf(5, 4, 3, 2, 1).asSequence().minBy<Int, Int> { c++; it * it } })
expect(1, { listOf(5, 4, 3, 2, 1).asSequence().minBy { c++; it * it } })
assertEquals(5, c)
}
@@ -472,7 +472,7 @@ class CollectionTest {
expect(5, { listOf(5, 4, 3, 2, 1).maxBy { c++; it * it } })
assertEquals(5, c)
c = 0
expect(5, { listOf(5, 4, 3, 2, 1).asSequence().maxBy<Int, Int> { c++; it * it } })
expect(5, { listOf(5, 4, 3, 2, 1).asSequence().maxBy { c++; it * it } })
assertEquals(5, c)
}
+3 -3
View File
@@ -262,12 +262,12 @@ abstract class MapJsTest {
test fun setViaIndexOperators() {
val map = HashMap<String, String>()
assertTrue{ map.empty }
assertEquals(map.size, 0)
assertTrue{ map.isEmpty() }
assertEquals(map.size(), 0)
map["name"] = "James"
assertTrue{ !map.empty }
assertTrue{ !map.isEmpty() }
assertEquals(map.size(), 1)
assertEquals("James", map["name"])
}
+2 -2
View File
@@ -272,7 +272,7 @@ class StringJVMTest {
fails {
data.drop(-2)
}
assertEquals("", data.drop(data.length + 5))
assertEquals("", data.drop(data.length() + 5))
}
test fun takeWhile() {
@@ -288,7 +288,7 @@ class StringJVMTest {
fails {
data.take(-7)
}
assertEquals(data, data.take(data.length + 42))
assertEquals(data, data.take(data.length() + 42))
}
test fun formatter() {