StdLib deprecations cleanup: length, size, indices and other collection operations.
This commit is contained in:
@@ -58,7 +58,7 @@ fun ResultSet.getColumnNames() : Array<String> {
|
||||
* @columnNames you can specify column names to extract otherwise all columns will be extracted
|
||||
*/
|
||||
fun ResultSet.getValues(columnNames : Array<String> = getColumnNames()) : Array<Any?> {
|
||||
return Array<Any?>(columnNames.size, {
|
||||
return Array<Any?>(columnNames.size(), {
|
||||
this[columnNames[it]]
|
||||
})
|
||||
}
|
||||
@@ -68,7 +68,7 @@ fun ResultSet.getValues(columnNames : Array<String> = getColumnNames()) : Array<
|
||||
* @param columnNames you can specify column names to extract otherwise all columns will be extracted
|
||||
*/
|
||||
fun ResultSet.getValuesAsMap(columnNames : Array<String> = getColumnNames()) : Map<String, Any?> {
|
||||
val result = java.util.HashMap<String, Any?>(columnNames.size)
|
||||
val result = java.util.HashMap<String, Any?>(columnNames.size())
|
||||
|
||||
columnNames.forEach {
|
||||
result[it] = this[it]
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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"])
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ class Html2CompilerPlugin(private val compilerArguments: KDocArguments) : Doclet
|
||||
val filePath = file.getPath()
|
||||
for (sourceDirPath in sourceDirPaths) {
|
||||
if (filePath.startsWith(sourceDirPath) && filePath.length() > sourceDirPath.length()) {
|
||||
val relativePath = filePath.substring(sourceDirPath.length + 1)
|
||||
val relativePath = filePath.substring(sourceDirPath.length() + 1)
|
||||
return relativePath
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ class KModel(val context: BindingContext, val config: KDocConfig, val sourceDirs
|
||||
val filePath = file.getPath()
|
||||
for (sourceDirPath in normalizedSourceDirs) {
|
||||
if (filePath.startsWith(sourceDirPath) && filePath.length() > sourceDirPath.length()) {
|
||||
return filePath.substring(sourceDirPath.length + 1)
|
||||
return filePath.substring(sourceDirPath.length() + 1)
|
||||
}
|
||||
}
|
||||
throw Exception("$file is not a child of any source roots $normalizedSourceDirs")
|
||||
@@ -483,7 +483,7 @@ class KModel(val context: BindingContext, val config: KDocConfig, val sourceDirs
|
||||
val lines = nodeText.trim().split('\n')
|
||||
// lets remove the /** ... * ... */ tokens
|
||||
val buffer = StringBuilder()
|
||||
val last = lines.size - 1
|
||||
val last = lines.size() - 1
|
||||
for (i in 0.rangeTo(last)) {
|
||||
var text = lines[i]
|
||||
text = text.trim()
|
||||
@@ -518,7 +518,7 @@ class KModel(val context: BindingContext, val config: KDocConfig, val sourceDirs
|
||||
// TODO we could default the test function name to match that of the
|
||||
// source code function if folks adopted a convention of naming the test method after the
|
||||
// method its acting as a demo/test for
|
||||
if (words.size > 1) {
|
||||
if (words.size() > 1) {
|
||||
val includeFile = words[0]
|
||||
val fnName = words[1]
|
||||
val content = findFunctionInclude(psiElement, includeFile, fnName)
|
||||
@@ -597,7 +597,7 @@ $highlight"""
|
||||
break
|
||||
}
|
||||
var count = 1
|
||||
for (i in 0.rangeTo(remaining.size - 1)) {
|
||||
for (i in 0.rangeTo(remaining.length() - 1)) {
|
||||
val ch = remaining[i]
|
||||
if (ch == '{') count ++
|
||||
else if (ch == '}') {
|
||||
@@ -619,7 +619,7 @@ $highlight"""
|
||||
|
||||
// lets try resolve the include name relative to this file
|
||||
val paths = relativeName.split('/')
|
||||
val size = paths.size
|
||||
val size = paths.size()
|
||||
for (i in 0.rangeTo(size - 2)) {
|
||||
val path = paths[i]
|
||||
if (path == ".") continue
|
||||
@@ -951,7 +951,7 @@ class KPackage(
|
||||
val nameAsRelativePath: String
|
||||
get() {
|
||||
val answer = namePaths.map{ ".." }.makeString("/")
|
||||
return if (answer.length == 0) "" else answer + "/"
|
||||
return if (answer.length() == 0) "" else answer + "/"
|
||||
}
|
||||
|
||||
override fun description(template: KDocTemplate): String {
|
||||
|
||||
+2
-2
@@ -190,10 +190,10 @@ Class ${klass.simpleName}</H2>
|
||||
|
||||
<P>""")
|
||||
println(klass.detailedDescription(this))
|
||||
if (klass.since.size > 0 || klass.authors.size > 0) {
|
||||
if (klass.since.length() > 0 || klass.authors.size() > 0) {
|
||||
println("""<P>
|
||||
<DL>""")
|
||||
if (klass.since.size > 0) {
|
||||
if (klass.since.length() > 0) {
|
||||
println("""<DT><B>Since:</B></DT>
|
||||
<DD>${klass.since}</DD>""")
|
||||
}
|
||||
|
||||
+1
-1
@@ -137,7 +137,7 @@ abstract class KDocTemplate() : TextTemplate() {
|
||||
if (cname.startsWith("kotlin.Function") && arguments.isNotEmpty()) {
|
||||
val rt = arguments.last()
|
||||
// TODO use drop()
|
||||
val rest = arguments.subList(0, arguments.size - 1).orEmpty()
|
||||
val rest = arguments.dropLast(1)
|
||||
"${typeArguments(rest, "(", ")", "()")} <A HREF=\"${href(c)}\" title=\"${c.kind} in ${c.packageName}\">-></a> ${link(rt)}"
|
||||
} else {
|
||||
val name = if (fullName) cname else c.simpleName
|
||||
|
||||
@@ -236,7 +236,7 @@ fun filtering(): List<GenericFunction> {
|
||||
returns(Strings) { "String" }
|
||||
body(Strings) {
|
||||
"""
|
||||
for (index in 0..length - 1)
|
||||
for (index in 0..length() - 1)
|
||||
if (!predicate(get(index))) {
|
||||
return substring(0, index)
|
||||
}
|
||||
@@ -357,7 +357,7 @@ fun filtering(): List<GenericFunction> {
|
||||
doc(Strings) { "Appends all characters matching the given [predicate] to the given [destination]." }
|
||||
body(Strings) {
|
||||
"""
|
||||
for (index in 0..length - 1) {
|
||||
for (index in 0..length() - 1) {
|
||||
val element = get(index)
|
||||
if (predicate(element)) destination.append(element)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user