mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-10 18:09:38 +07:00
StreamToLoopInspection: support groupingBy(..., counting()/summingInt()/summingLong()/summingDouble()/mapping(summing...))
This commit is contained in:
@@ -6,7 +6,7 @@ import java.util.Set;
|
||||
|
||||
public class Main {
|
||||
private static long test() {
|
||||
long count = 0;
|
||||
long count = 0L;
|
||||
Set<Integer> uniqueValues = new HashSet<>();
|
||||
long toSkip = 1;
|
||||
for (Integer integer : new Integer[]{1, 2, 3, 2, 3}) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
public static long test(List<String> strings) {
|
||||
long count = 0;
|
||||
long count = 0L;
|
||||
for (String s : strings) {
|
||||
if (!s.isEmpty()) {
|
||||
count++;
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
public static Double test(List<String> strings) {
|
||||
double sum = 0;
|
||||
double sum = 0.0;
|
||||
for (String string : strings) {
|
||||
if (string != null) {
|
||||
sum += string.length();
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public void test(List<String> list) {
|
||||
long x = 0;
|
||||
long x = 0L;
|
||||
for (String s : list) {
|
||||
x++;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ public class Main {
|
||||
}
|
||||
|
||||
public long test(List<Count> count) {
|
||||
long result = 0;
|
||||
long result = 0L;
|
||||
for (Count count1 : count) {
|
||||
result++;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.util.List;
|
||||
public class Main {
|
||||
public long test(List<String> list) {
|
||||
if(!list.isEmpty()) {
|
||||
long count = 0;
|
||||
long count = 0L;
|
||||
for (String s : list) {
|
||||
count++;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public long test(List<String> list) {
|
||||
long count = 0;
|
||||
long count = 0L;
|
||||
for (String s : list) {
|
||||
count++;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.Set;
|
||||
|
||||
public class Main {
|
||||
public long test(List<String> list) {
|
||||
long count = 0;
|
||||
long count = 0L;
|
||||
Set<String> uniqueValues = new HashSet<>();
|
||||
for (String s : list) {
|
||||
if (uniqueValues.add(s)) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.util.Arrays;
|
||||
|
||||
public class Main {
|
||||
private static long countInRange(int... input) {
|
||||
long count = 0;
|
||||
long count = 0L;
|
||||
for (int x : input) {
|
||||
if (x > 0) {
|
||||
if (x < 10) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.util.Arrays;
|
||||
public class Main {
|
||||
private static long countInRange(int... input) {
|
||||
int x = 1;
|
||||
long count = 0;
|
||||
long count = 0L;
|
||||
for (int y : input) {
|
||||
if (y > 0) {
|
||||
if (y < 10) {
|
||||
|
||||
@@ -6,7 +6,7 @@ public class Main {
|
||||
private static long countInRange(int... input) {
|
||||
int x = 1;
|
||||
int y = 2;
|
||||
long count = 0;
|
||||
long count = 0L;
|
||||
for (int i : input) {
|
||||
if (i > 0) {
|
||||
if (i < 10) {
|
||||
|
||||
@@ -7,7 +7,7 @@ public class Main {
|
||||
int x = 1;
|
||||
int y = 2;
|
||||
int i = 3;
|
||||
long count = 0;
|
||||
long count = 0L;
|
||||
for (int x1 : input) {
|
||||
if (x1 > 0) {
|
||||
if (x1 < 10) {
|
||||
|
||||
@@ -6,7 +6,7 @@ public class Main {
|
||||
private static long countInRange(int... input) {
|
||||
int x = 1;
|
||||
int i = 3;
|
||||
long result = 0;
|
||||
long result = 0L;
|
||||
for (int count : input) {
|
||||
if (count > 0) {
|
||||
if (count < 10) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
private static long test(List<? extends String> list) {
|
||||
long count = 0;
|
||||
long count = 0L;
|
||||
for (Object o : Arrays.asList(0, null, "1", list)) {
|
||||
for (Object o1 : Arrays.asList(o)) {
|
||||
for (Object o2 : Arrays.asList(o1)) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
private static long test(List<List<String>> nested) {
|
||||
long count = 0;
|
||||
long count = 0L;
|
||||
for (List<String> names : nested) {
|
||||
Set<String> uniqueValues = new HashSet<>();
|
||||
for (String name : names) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.util.*;
|
||||
public class Main {
|
||||
|
||||
private static long test(Map<String, List<String>> strings) {
|
||||
long count = 0;
|
||||
long count = 0L;
|
||||
for (Map.Entry<String, List<String>> e : strings.entrySet()) {
|
||||
if (!e.getKey().isEmpty()) {
|
||||
String sInner = e.getKey();
|
||||
|
||||
@@ -7,7 +7,7 @@ public class Main {
|
||||
static Predicate<String> nonEmpty = s -> s != null && !s.isEmpty();
|
||||
|
||||
private static long test(List<String> strings) {
|
||||
long count = 0;
|
||||
long count = 0L;
|
||||
for (String string : strings) {
|
||||
if (nonEmpty.test(string)) {
|
||||
count++;
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.function.Predicate;
|
||||
|
||||
public class Main {
|
||||
private static long test(List<Predicate<String>> predicates, List<String> strings) {
|
||||
long count = 0;
|
||||
long count = 0L;
|
||||
for (Predicate<String> pred : predicates) {
|
||||
if (pred != null) {
|
||||
for (String string : strings) {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Test {
|
||||
static void test(List<String> list) {
|
||||
Map<Integer, Long> map = new HashMap<>();
|
||||
for (String s : list) {
|
||||
map.merge(s.length(), 1L, Long::sum);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Test {
|
||||
static void test(List<String> list) {
|
||||
Map<Integer, Integer> map3 = new HashMap<>();
|
||||
for (String s : list) {
|
||||
String trim = s.trim();
|
||||
map3.merge(s.length(), trim.length(), Integer::sum);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Test {
|
||||
static void test(List<String> list) {
|
||||
Map<Integer, Double> map4 = new HashMap<>();
|
||||
for (String s : list) {
|
||||
map4.merge(s.length(), (double) s.length(), Double::sum);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static long countNonEmpty(List<String> input) {
|
||||
long count = 0;
|
||||
long count = 0L;
|
||||
for (String str : input) {
|
||||
String trim = str.trim();
|
||||
if (!trim.isEmpty()) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.stream.Stream;
|
||||
public class Main {
|
||||
|
||||
private static long test(Map<String, List<String>> strings) {
|
||||
long sum = 0;
|
||||
long sum = 0L;
|
||||
for (Map.Entry<String, List<String>> e : strings.entrySet()) {
|
||||
if (!e.getKey().isEmpty()) {
|
||||
long count = e.getValue().stream().filter(new Predicate<String>() {
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.stream.Stream;
|
||||
public class Main {
|
||||
|
||||
private static long test(Map<String, List<String>> strings) {
|
||||
long sum = 0;
|
||||
long sum = 0L;
|
||||
for (Map.Entry<String, List<String>> e : strings.entrySet()) {
|
||||
if (!e.getKey().isEmpty()) {
|
||||
long count = e.getValue().stream().filter(s -> e.getKey().equals(s)).count();
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.stream.Stream;
|
||||
public class Main {
|
||||
|
||||
private static long test(Map<String, List<String>> strings) {
|
||||
long sum = 0;
|
||||
long sum = 0L;
|
||||
for (Map.Entry<String, List<String>> s : strings.entrySet()) {
|
||||
if (!s.getKey().isEmpty()) {
|
||||
long count = s.getValue().stream().filter(sx -> s.getKey().equals(sx)).count();
|
||||
|
||||
@@ -7,7 +7,7 @@ import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static long test(List<String> list) {
|
||||
long count = 0;
|
||||
long count = 0L;
|
||||
for (String l : list) {
|
||||
if (l != null) {
|
||||
(new Consumer<String>() {
|
||||
|
||||
@@ -7,7 +7,7 @@ import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static long test(List<String> list) {
|
||||
long count = 0;
|
||||
long count = 0L;
|
||||
for (String l : list) {
|
||||
if (l != null) {
|
||||
(new Consumer<String>() {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Test {
|
||||
static void test(List<String> list) {
|
||||
Map<Boolean, Long> map2 = new HashMap<>();
|
||||
map2.put(false, 0L);
|
||||
map2.put(true, 0L);
|
||||
for (String s : list) {
|
||||
map2.merge(s.isEmpty(), 1L, Long::sum);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Test {
|
||||
static void test(List<String> list) {
|
||||
Map<Boolean, Double> map1 = new HashMap<>();
|
||||
map1.put(false, 0.0);
|
||||
map1.put(true, 0.0);
|
||||
for (String s : list) {
|
||||
map1.merge(s.isEmpty(), (double) s.length(), Double::sum);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
private static long check(int start, int stop, double v) {
|
||||
long count = 0;
|
||||
long count = 0L;
|
||||
for (int x = start; x < stop; x++) {
|
||||
double x1 = 1.0 / x;
|
||||
if (x1 < v) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
private static long check(int start, double val) {
|
||||
long count = 0;
|
||||
long count = 0L;
|
||||
int bound = start * 200;
|
||||
for (int x = start; x <= bound; x++) {
|
||||
double v = 1.0 / x;
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.function.LongSupplier;
|
||||
public class Main {
|
||||
private static void test(List<String> list) {
|
||||
// and filter!
|
||||
long count1 = 0;
|
||||
long count1 = 0L;
|
||||
for (String s : list) {
|
||||
if (!s/* comment */.isEmpty()) {
|
||||
count1++;
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.util.*;
|
||||
|
||||
public class Main {
|
||||
private static long test(List<?> list) {
|
||||
long count = 0;
|
||||
long count = 0L;
|
||||
Set<Object> uniqueValues = new HashSet<>();
|
||||
long toSkip = list.size() / 2;
|
||||
for (Object o : list) {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Test {
|
||||
static void test(List<String> list) {
|
||||
Map<Integer, Long> map = list.stream().coll<caret>ect(Collectors.groupingBy(String::length, Collectors.counting()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Test {
|
||||
static void test(List<String> list) {
|
||||
Map<Integer, Integer> map3 = list.stream().coll<caret>ect(Collectors.groupingBy(String::length, Collectors.mapping(String::trim, Collectors.summingInt(String::length))));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Test {
|
||||
static void test(List<String> list) {
|
||||
Map<Integer, Double> map4 = list.stream().co<caret>llect(Collectors.groupingBy(String::length, Collectors.summingDouble(String::length)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Test {
|
||||
static void test(List<String> list) {
|
||||
Map<Boolean, Long> map2 = list.stream()
|
||||
.co<caret>llect(Collectors.partitioningBy(String::isEmpty, Collectors.counting()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Test {
|
||||
static void test(List<String> list) {
|
||||
Map<Boolean, Double> map1 = list.stream()
|
||||
.col<caret>lect(Collectors.partitioningBy(String::isEmpty, Collectors.summingDouble(String::length)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user