StreamApiMigrationInspection: fix noneMatch()/allMatch() quick-fix name when continue is used; prettier Optional code generated in some cases

This commit is contained in:
Tagir Valeev
2016-09-27 11:21:17 +07:00
parent b1e4351dea
commit b141891dc1
10 changed files with 119 additions and 1 deletions
@@ -0,0 +1,9 @@
// "Replace with allMatch()" "true"
import java.util.Arrays;
public class Main {
boolean find(String[][] data) {
return Arrays.stream(data).flatMap(Arrays::stream).allMatch(str -> str.startsWith("xyz"));
}
}
@@ -0,0 +1,13 @@
// "Replace with findFirst()" "true"
import java.util.Collection;
import java.util.List;
public class Main {
public static boolean find(List<List<String>> list) {
/*
Block comment
*/
return list.stream().flatMap(Collection::stream).filter(string -> string.startsWith("ABC")).findFirst().filter(string -> string.substring(3).equals("xyz")).isPresent();
}
}
@@ -0,0 +1,10 @@
// "Replace with findFirst()" "true"
import java.util.Collection;
import java.util.List;
public class Main {
public static String find(List<List<String>> list) {
return list.stream().flatMap(Collection::stream).filter(string -> string.startsWith("ABC")).findFirst().filter(string -> string.substring(3).equals("xyz")).map(String::trim).orElse(null);
}
}
@@ -0,0 +1,9 @@
// "Replace with noneMatch()" "true"
import java.util.Arrays;
public class Main {
boolean find(String[][] data) {
return Arrays.stream(data).flatMap(Arrays::stream).noneMatch(str -> str.startsWith("xyz"));
}
}
@@ -0,0 +1,13 @@
// "Replace with allMatch()" "true"
public class Main {
boolean find(String[][] data) {
for(String[] arr : da<caret>ta) {
for(String str : arr) {
if(str.startsWith("xyz")) continue;
return false;
}
}
return true;
}
}
@@ -0,0 +1,19 @@
// "Replace with findFirst()" "true"
import java.util.List;
public class Main {
public static boolean find(List<List<String>> list) {
for(List<String> innerList : li<caret>st) {
for(String string : innerList) {
if(string.startsWith("ABC")) {
return string.substring(3).equals("xyz");
/*
Block comment
*/
}
}
}
return false;
}
}
@@ -0,0 +1,16 @@
// "Replace with findFirst()" "true"
import java.util.List;
public class Main {
public static String find(List<List<String>> list) {
for(List<String> innerList : li<caret>st) {
for(String string : innerList) {
if(string.startsWith("ABC")) {
return string.substring(3).equals("xyz") ? string.trim() : null;
}
}
}
return null;
}
}
@@ -0,0 +1,13 @@
// "Replace with noneMatch()" "true"
public class Main {
boolean find(String[][] data) {
for(String[] arr : da<caret>ta) {
for(String str : arr) {
if(!str.startsWith("xyz")) continue;
return false;
}
}
return true;
}
}