StreamApiMigrationInspection improvements: expression+break conversion to anyMatch; pull out cast of stream.findFirst().map(x -> (T)x).orElse(null) to (T) stream.findFirst().orElse(null)

This commit is contained in:
Tagir Valeev
2016-09-26 15:52:55 +07:00
parent c52a93044c
commit e69109e521
17 changed files with 281 additions and 40 deletions
@@ -0,0 +1,9 @@
// "Replace with anyMatch()" "true"
import java.util.List;
public class Main {
public void testAssignment(List<String> data) {
String found = data.stream().map(String::trim).anyMatch(trimmed -> !trimmed.isEmpty()) ? "yes" : "no";
}
}
@@ -0,0 +1,9 @@
// "Replace with anyMatch()" "true"
import java.util.List;
public class Main {
public void testAssignment(List<String> data) {
boolean found = data.stream().map(String::trim).anyMatch(trimmed -> !trimmed.isEmpty());
}
}
@@ -0,0 +1,9 @@
// "Replace with anyMatch()" "true"
import java.util.List;
public class Main {
public void testAssignment(List<String> data) {
boolean found = !data.stream().map(String::trim).anyMatch(trimmed -> !trimmed.isEmpty());
}
}
@@ -0,0 +1,16 @@
// "Replace with anyMatch()" "true"
import java.util.List;
public class Main {
public void testAssignment(List<String> data) {
boolean found = false;
if(Math.random() > 0.5) {
found = true;
} else {
if (data.stream().map(String::trim).anyMatch(trimmed -> !trimmed.isEmpty())) {
found = true;
}
}
}
}
@@ -0,0 +1,11 @@
// "Replace with anyMatch()" "true"
import java.util.List;
public class Main {
public void testAssignment(List<String> data) {
if (data.stream().map(String::trim).anyMatch(trimmed -> !trimmed.isEmpty())) {
System.out.println("Found!!!");
}
}
}
@@ -0,0 +1,10 @@
// "Replace with findFirst()" "true"
import java.util.List;
public class Main {
public void testCast(List<Object> data) {
String found = (String) data.stream().filter(obj -> obj instanceof String).findFirst().orElse(null);
System.out.println(found);
}
}
@@ -0,0 +1,9 @@
// "Replace with findFirst()" "true"
import java.util.List;
public class Main {
public String testCast(List<Object> data) {
return (String) data.stream().filter(obj -> obj instanceof String).findFirst().orElse(null);
}
}
@@ -0,0 +1,16 @@
// "Replace with anyMatch()" "true"
import java.util.List;
public class Main {
public void testAssignment(List<String> data) {
String found = "no";
for(String str : da<caret>ta) {
String trimmed = str.trim();
if(!trimmed.isEmpty()) {
found = "yes";
break;
}
}
}
}
@@ -0,0 +1,16 @@
// "Replace with anyMatch()" "true"
import java.util.List;
public class Main {
public void testAssignment(List<String> data) {
boolean found = false;
for(String str : da<caret>ta) {
String trimmed = str.trim();
if(!trimmed.isEmpty()) {
found = true;
break;
}
}
}
}
@@ -0,0 +1,16 @@
// "Replace with anyMatch()" "true"
import java.util.List;
public class Main {
public void testAssignment(List<String> data) {
boolean found = true;
for(String str : da<caret>ta) {
String trimmed = str.trim();
if(!trimmed.isEmpty()) {
found = false;
break;
}
}
}
}
@@ -0,0 +1,20 @@
// "Replace with anyMatch()" "true"
import java.util.List;
public class Main {
public void testAssignment(List<String> data) {
boolean found = false;
if(Math.random() > 0.5) {
found = true;
} else {
for (String str : da<caret>ta) {
String trimmed = str.trim();
if (!trimmed.isEmpty()) {
found = true;
break;
}
}
}
}
}
@@ -0,0 +1,15 @@
// "Replace with anyMatch()" "true"
import java.util.List;
public class Main {
public void testAssignment(List<String> data) {
for (String str : d<caret>ata) {
String trimmed = str.trim();
if (!trimmed.isEmpty()) {
System.out.println("Found!!!");
break;
}
}
}
}
@@ -0,0 +1,16 @@
// "Replace with findFirst()" "true"
import java.util.List;
public class Main {
public void testCast(List<Object> data) {
String found = null;
for (Object obj : da<caret>ta) {
if(obj instanceof String) {
found = (String)obj;
break;
}
}
System.out.println(found);
}
}
@@ -0,0 +1,14 @@
// "Replace with findFirst()" "true"
import java.util.List;
public class Main {
public String testCast(List<Object> data) {
for (Object obj : d<caret>ata) {
if(obj instanceof String) {
return (String)obj;
}
}
return null;
}
}