count() to merge with filterNotNull and filterIsInstance + changed test for KT-14191 to use sum()
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'filterNotNull().sum()'"
|
||||
// INTENTION_TEXT_2: "Replace with 'asSequence().filterNotNull().sum()'"
|
||||
fun f(list: List<Int?>): Int{
|
||||
var r = 0
|
||||
<caret>for (d in list) {
|
||||
if (d != null) {
|
||||
r += d
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'filterNotNull().sum()'"
|
||||
// INTENTION_TEXT_2: "Replace with 'asSequence().filterNotNull().sum()'"
|
||||
fun f(list: List<Int?>): Int{
|
||||
val r = list
|
||||
.filterNotNull()
|
||||
.sum()
|
||||
return r
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'filterNotNull().sum()'"
|
||||
// INTENTION_TEXT_2: "Replace with 'asSequence().filterNotNull().sum()'"
|
||||
fun f(list: List<Int?>): Int{
|
||||
val r = list
|
||||
.asSequence()
|
||||
.filterNotNull()
|
||||
.sum()
|
||||
return r
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'filterNotNull().count()'"
|
||||
// INTENTION_TEXT_2: "Replace with 'asSequence().filterNotNull().count()'"
|
||||
fun f11(list: List<Any?>): Int{
|
||||
var objs = 0
|
||||
<caret>for (d in list) {
|
||||
if (d != null) {
|
||||
objs++
|
||||
}
|
||||
}
|
||||
return objs
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'filterNotNull().count()'"
|
||||
// INTENTION_TEXT_2: "Replace with 'asSequence().filterNotNull().count()'"
|
||||
fun f11(list: List<Any?>): Int{
|
||||
val <caret>objs = list
|
||||
.filterNotNull()
|
||||
.count()
|
||||
return objs
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'filterNotNull().count()'"
|
||||
// INTENTION_TEXT_2: "Replace with 'asSequence().filterNotNull().count()'"
|
||||
fun f11(list: List<Any?>): Int{
|
||||
val <caret>objs = list
|
||||
.asSequence()
|
||||
.filterNotNull()
|
||||
.count()
|
||||
return objs
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'count{}'"
|
||||
// IS_APPLICABLE_2: false
|
||||
fun f11(list: List<Any?>): Int{
|
||||
var c = 0
|
||||
<caret>for (d in list) {
|
||||
if (d is String) {
|
||||
c++
|
||||
}
|
||||
}
|
||||
return c
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'count{}'"
|
||||
// IS_APPLICABLE_2: false
|
||||
fun f11(list: List<Any?>): Int{
|
||||
val <caret>c = list.count { it is String }
|
||||
return c
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'count{}'"
|
||||
// IS_APPLICABLE_2: false
|
||||
fun f11(list: List<Any?>): Int{
|
||||
var c = 0
|
||||
<caret>for (d in list) {
|
||||
if (d != null) {
|
||||
c++
|
||||
}
|
||||
}
|
||||
return c
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'count{}'"
|
||||
// IS_APPLICABLE_2: false
|
||||
fun f11(list: List<Any?>): Int{
|
||||
val <caret>c = list.count { it != null }
|
||||
return c
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'count{}'"
|
||||
// IS_APPLICABLE_2: false
|
||||
fun f(list: List<Any?>): Int{
|
||||
var c = 0
|
||||
<caret>for (d in list) {
|
||||
if (d == "") continue
|
||||
if (d != null) {
|
||||
if (d is Int) continue
|
||||
c++
|
||||
}
|
||||
}
|
||||
return c
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
// INTENTION_TEXT: "Replace with 'count{}'"
|
||||
// IS_APPLICABLE_2: false
|
||||
fun f(list: List<Any?>): Int{
|
||||
val <caret>c = list.count { it != "" && it != null && it !is Int }
|
||||
return c
|
||||
}
|
||||
Reference in New Issue
Block a user