extract simplify forEach inspection: IDEA-CR-24052

This commit is contained in:
Roman Ivanov
2017-09-01 17:26:19 +07:00
parent 0f2ac1a485
commit 029b97749b
47 changed files with 958 additions and 287 deletions
@@ -0,0 +1,10 @@
// "Extract intermediate operations" "true"
import java.util.*;
public class Main {
private void test() {
List<String> other = new ArrayList<>();
other.stream().filter(s -> s.length() > 2).forEach(System.out::println);
}
}
@@ -0,0 +1,12 @@
// "Extract intermediate operations" "true"
import java.util.*;
public class Main {
private void test() {
List<String> other = new ArrayList<>();
// c1
//c2
other.stream().filter(s -> s.length() > 2).forEach(System.out::println);
}
}
@@ -0,0 +1,10 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Main {
private void test(List<String> strs) {
List<String> other = strs.stream().filter(s -> s.length() > 2).collect(Collectors.toList());
}
}
@@ -0,0 +1,12 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Main {
private void test() {
List<String> strs;
List<String> other = new ArrayList<>();
strs = other.stream().collect(Collectors.toList());
}
}
@@ -0,0 +1,12 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Main {
private void test() {
List<String> strs;
List<String> other = new ArrayList<>();
strs = other.stream().filter(s -> s.length() > 2).collect(Collectors.toList());
}
}
@@ -0,0 +1,10 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
private void test() {
List<String> other = new ArrayList<>();
String[] arr = other.stream().filter(s -> s.length() > 2).sorted(String.CASE_INSENSITIVE_ORDER).toArray();
}
}
@@ -0,0 +1,12 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Main {
private void test() {
List<String> strs;
List<String> other = new ArrayList<>();
strs = other.stream().filter(s -> s.length() > 2).sorted(String::compareTo).collect(Collectors.toList());
}
}
@@ -0,0 +1,10 @@
// "Extract intermediate operations" "true"
import java.util.*;
public class Main {
private void test() {
List<String> other = new ArrayList<>();
other.stream().filter(s -> s.length() > 2).forEachOrdered(System.out::println);
}
}
@@ -0,0 +1,10 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Main {
private void test(List<String> other) {
List<String> strs = other.stream().collect(Collectors.toList());
}
}
@@ -0,0 +1,12 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Main {
private void test() {
List<String> strs;
List<String> other = new ArrayList<>();
strs = other.stream().collect(Collectors.toList());
}
}
@@ -0,0 +1,10 @@
// "Replace with count()" "true"
import java.util.*;
public class Main {
private void test() {
List<String> strs = new ArrayList<>();
int count = (int) strs.stream().count();
}
}
@@ -0,0 +1,11 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Main {
private void test() {
List<String> strs = new ArrayList<>();
String sb = strs.stream().collect(Collectors.joining());
}
}
@@ -0,0 +1,9 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
private void test(List<String> strs) {
String[] arr = strs.toArray();
}
}
@@ -0,0 +1,11 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Main {
private void test() {
List<String> other = new ArrayList<>();
HashMap<Integer, String> map = other.stream().collect(Collectors.toMap(String::length, s -> s, (a, b) -> a, HashMap::new));
}
}
@@ -0,0 +1,12 @@
// "Extract intermediate operations" "true"
import java.util.*;
public class Main {
private void test() {
List<String> other = new ArrayList<>();
other.stream().forEach<caret>(s -> {
if(s.length() > 2) System.out.println(s);
});
}
}
@@ -0,0 +1,12 @@
// "Extract intermediate operations" "true"
import java.util.*;
public class Main {
private void test() {
List<String> other = new ArrayList<>();
other.stream().forEach<caret>(s -> { // c1
if(s.length() > 2) System.out.println(s); //c2
});
}
}
@@ -0,0 +1,14 @@
// "Replace with collect" "true"
import java.util.*;
public class Main {
private void test(List<String> strs) {
List<String> other = new ArrayList<>();
strs.stream().forEach<caret>(s -> {
if(s.length() > 2) {
other.add(s);
}
});
}
}
@@ -0,0 +1,11 @@
// "Replace with collect" "true"
import java.util.*;
public class Main {
private void test() {
List<String> strs = new ArrayList<>();
List<String> other = new ArrayList<>();
other.stream().forEach<caret>(s -> {strs.add(s)});
}
}
@@ -0,0 +1,13 @@
// "Replace with collect" "true"
import java.util.*;
public class Main {
private void test() {
List<String> strs = new ArrayList<>();
List<String> other = new ArrayList<>();
other.stream().forEach<caret>(s -> {
if(s.length() > 2) strs.add(s);
});
}
}
@@ -0,0 +1,17 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
private void test() {
List<String> strs = new ArrayList<>();
List<String> other = new ArrayList<>();
other.stream().forEach<caret>(s -> {
if(s.length() > 2) {
strs.add(s);
}
});
String[] arr = strs.toArray();
Arrays.sort(arr, String.CASE_INSENSITIVE_ORDER);
}
}
@@ -0,0 +1,16 @@
// "Replace with collect" "true"
import java.util.*;
public class Main {
private void test() {
List<String> strs = new ArrayList<>();
List<String> other = new ArrayList<>();
other.stream().forEach<caret>(s -> {
if(s.length() > 2) {
strs.add(s);
}
});
strs.sort(String::compareTo);
}
}
@@ -0,0 +1,10 @@
// "Extract intermediate operations" "true"
import java.util.*;
public class Main {
private void test() {
List<String> other = new ArrayList<>();
other.stream().forEachOrdered<caret>(s -> {if(s.length() > 2) System.out.println(s);});
}
}
@@ -0,0 +1,10 @@
// "Replace with collect" "true"
import java.util.*;
public class Main {
private void test(List<String> other) {
List<String> strs = new ArrayList<>();
other.stream().forEach<caret>(s -> {strs.add(s)});
}
}
@@ -0,0 +1,11 @@
// "Replace with collect" "true"
import java.util.*;
public class Main {
private void test() {
List<String> strs = new ArrayList<>();
List<String> other = new ArrayList<>();
other.stream().forEach<caret>(s -> strs.add(s));
}
}
@@ -0,0 +1,11 @@
// "Replace with count()" "true"
import java.util.*;
public class Main {
private void test() {
List<String> strs = new ArrayList<>();
int count = 0;
strs.stream().forEach<caret>(x -> count++)
}
}
@@ -0,0 +1,11 @@
// "Replace with collect" "true"
import java.util.*;
public class Main {
private void test() {
List<String> strs = new ArrayList<>();
StringBuilder sb = new StringBuilder();
strs.stream().forEach<caret>(x -> sb.append(x));
}
}
@@ -0,0 +1,11 @@
// "Replace with toArray" "true"
import java.util.*;
public class Main {
private void test(List<String> strs) {
List<String> tmp = new ArrayList<>();
strs.stream().forEach<caret>(x -> tmp.add(x));
String[] arr = tmp.toArray();
}
}
@@ -0,0 +1,11 @@
// "Replace with collect" "true"
import java.util.*;
public class Main {
private void test() {
List<String> other = new ArrayList<>();
HashMap<Integer, String> map = new HashMap<Integer, String>();
other.stream().forEach<caret>(s -> map.putIfAbsent(s.length(), s));
}
}