mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-25 19:29:30 +07:00
IDEA-161198 Migration from Stream API back to for loops
This commit is contained in:
+25
@@ -0,0 +1,25 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static boolean test(List<List<String>> list) {
|
||||
for (List<String> x : list) {
|
||||
if (x != null) {
|
||||
for (String s : x) {
|
||||
if (!s.startsWith("a")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(asList(asList(), asList("a"), asList("b", "c"))));
|
||||
System.out.println(test(asList(asList(), asList("d"), asList("b", "c"))));
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static void test(List<List<String>> list) {
|
||||
boolean allMatch = true;
|
||||
OUTER:
|
||||
for (List<String> x : list) {
|
||||
if (x != null) {
|
||||
for (String s : x) {
|
||||
if (!s.startsWith("a")) {
|
||||
allMatch = false;
|
||||
break OUTER;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(allMatch) {
|
||||
System.out.println("ok");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(asList(asList(), asList("a"), asList("b", "c"))));
|
||||
System.out.println(test(asList(asList(), asList("d"), asList("b", "c"))));
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static boolean test(List<List<String>> list) {
|
||||
for (List<String> x : list) {
|
||||
if (x != null) {
|
||||
for (String s : x) {
|
||||
if (s.startsWith("a")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(asList(asList(), asList("a"), asList("b", "c"))));
|
||||
System.out.println(test(asList(asList(), asList("d"), asList("b", "c"))));
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class Main {
|
||||
private static long test() {
|
||||
long count = 0;
|
||||
Set<Integer> uniqueValues = new HashSet<>();
|
||||
long toSkip = 1;
|
||||
for (Integer integer : new Integer[]{1, 2, 3, 2, 3}) {
|
||||
if (toSkip > 0) {
|
||||
toSkip--;
|
||||
continue;
|
||||
}
|
||||
if (uniqueValues.add(integer)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.stream.LongStream;
|
||||
|
||||
public class Main {
|
||||
private static OptionalDouble test(long... numbers) {
|
||||
double sum = 0;
|
||||
long count = 0;
|
||||
for (long x : numbers) {
|
||||
if (x > 0) {
|
||||
double v = x;
|
||||
sum += v;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return (count == 0 ? OptionalDouble.empty() : OptionalDouble.of(sum / count));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(-1,-2,-3, Long.MAX_VALUE, Long.MAX_VALUE));
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
private static OptionalDouble test(int... numbers) {
|
||||
long sum = 0;
|
||||
long count = 0;
|
||||
for (int x : numbers) {
|
||||
if (x > 0) {
|
||||
sum += x;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return (count == 0 ? OptionalDouble.empty() : OptionalDouble.of((double) sum / count));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(-1,-2,-3));
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.stream.LongStream;
|
||||
|
||||
public class Main {
|
||||
private static OptionalDouble test(long... numbers) {
|
||||
long sum = 0;
|
||||
long count = 0;
|
||||
for (long x : numbers) {
|
||||
if (x > 0) {
|
||||
sum += x;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return (count == 0 ? OptionalDouble.empty() : OptionalDouble.of((double) sum / count));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(-1,-2,-3, Long.MAX_VALUE, Long.MAX_VALUE));
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
private static List<Integer> test(int[] numbers) {
|
||||
List<Integer> list = new ArrayList<>();
|
||||
for (int number : numbers) {
|
||||
Integer integer = number;
|
||||
list.add(integer);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(new int[] {1,2,3}));
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static Optional<String> test(List<String> list) {
|
||||
boolean seen = false;
|
||||
String acc = null;
|
||||
for (String s : list) {
|
||||
if (!seen) {
|
||||
seen = true;
|
||||
acc = s;
|
||||
} else {
|
||||
acc = acc + s;
|
||||
}
|
||||
}
|
||||
return (seen ? Optional.of(acc) : Optional.empty());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(asList("a", "b", "c")));
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static String test(List<String> list) {
|
||||
String acc = "";
|
||||
for (String s : list) {
|
||||
acc = acc + s;
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(asList("a", "b", "c")));
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public void test(List<String> list) {
|
||||
long count = 0;
|
||||
for (String s : list) {
|
||||
count++;
|
||||
}
|
||||
long x = count;
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
static class Count {
|
||||
}
|
||||
|
||||
public long test(List<Count> count) {
|
||||
long result = 0;
|
||||
for (Count count1 : count) {
|
||||
result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public long test(List<String> list) {
|
||||
if(!list.isEmpty()) {
|
||||
long count = 0;
|
||||
for (String s : list) {
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public long test(List<String> list) {
|
||||
long count = 0;
|
||||
for (String s : list) {
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class Main {
|
||||
public long test(List<String> list) {
|
||||
long count = 0;
|
||||
Set<String> uniqueValues = new HashSet<>();
|
||||
for (String s : list) {
|
||||
if (uniqueValues.add(s)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
private static List<Object> test(List<? extends Number> numbers) {
|
||||
List<Object> list = new ArrayList<>();
|
||||
Set<Number> uniqueValues = new HashSet<>();
|
||||
for (Number number : numbers) {
|
||||
if (uniqueValues.add(number)) {
|
||||
list.add(number);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList(1,2,3,5,3,2,2,2,1,1,4,3)));
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Main {
|
||||
private static long countInRange(int... input) {
|
||||
long count = 0;
|
||||
for (int x : input) {
|
||||
if (x > 0) {
|
||||
if (x < 10) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(countInRange(1, 2, 3, -1, -2));
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Main {
|
||||
private static long countInRange(int... input) {
|
||||
int x = 1;
|
||||
long count = 0;
|
||||
for (int y : input) {
|
||||
if (y > 0) {
|
||||
if (y < 10) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(countInRange(1, 2, 3, -1, -2));
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Main {
|
||||
private static long countInRange(int... input) {
|
||||
int x = 1;
|
||||
int y = 2;
|
||||
long count = 0;
|
||||
for (int i : input) {
|
||||
if (i > 0) {
|
||||
if (i < 10) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(countInRange(1, 2, 3, -1, -2));
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Main {
|
||||
private static long countInRange(int... input) {
|
||||
int x = 1;
|
||||
int y = 2;
|
||||
int i = 3;
|
||||
long count = 0;
|
||||
for (int x1 : input) {
|
||||
if (x1 > 0) {
|
||||
if (x1 < 10) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(countInRange(1, 2, 3, -1, -2));
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Main {
|
||||
private static long countInRange(int... input) {
|
||||
int x = 1;
|
||||
int i = 3;
|
||||
long result = 0;
|
||||
for (int count : input) {
|
||||
if (count > 0) {
|
||||
if (count < 10) {
|
||||
result++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(countInRange(1, 2, 3, -1, -2));
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.LongSummaryStatistics;
|
||||
|
||||
public class Main {
|
||||
public static LongSummaryStatistics test(List<List<String>> list) {
|
||||
LongSummaryStatistics stat = new LongSummaryStatistics();
|
||||
for (List<String> a : list) {
|
||||
if (a != null) {
|
||||
for (String s : a) {
|
||||
long l = s.length();
|
||||
stat.accept(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList(null, Arrays.asList("aaa", "b", "cc", "dddd"), Arrays.asList("gggg"))));
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
private static List<Integer> getPositiveDoubled(int... input) {
|
||||
List<Integer> list = new ArrayList<>();
|
||||
for (int x : input) {
|
||||
if (x > 0) {
|
||||
Integer integer = x * 2;
|
||||
list.add(integer);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(getPositiveDoubled(1, 2, 3, -1, -2));
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static Optional<String> test(List<List<String>> list) {
|
||||
for (List<String> x : list) {
|
||||
if (x != null) {
|
||||
for (String s : x) {
|
||||
return Optional.of(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(asList(asList(), asList("a"), asList("b", "c"))));
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static Optional<String> test(List<List<String>> list) {
|
||||
OUTER:
|
||||
for(int i=0; i<10; i++) {
|
||||
Optional<String> found = Optional.empty();
|
||||
OUTER1:
|
||||
for (List<String> x : list) {
|
||||
if (x != null) {
|
||||
for (String s : x) {
|
||||
found = Optional.of(s);
|
||||
break OUTER1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return found.orElse("");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(asList(asList(), asList("a"), asList("b", "c"))));
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.*;
|
||||
|
||||
public class Main {
|
||||
|
||||
private static OptionalInt test() {
|
||||
for (int x = 0; x < 100; x++) {
|
||||
if (x > 50) {
|
||||
return OptionalInt.of(x);
|
||||
}
|
||||
}
|
||||
return OptionalInt.empty();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.*;
|
||||
|
||||
public class Main {
|
||||
|
||||
private static int test() {
|
||||
OptionalInt found = OptionalInt.empty();
|
||||
for (int x = 0; x < 100; x++) {
|
||||
if (x > 50) {
|
||||
found = OptionalInt.of(x);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found.orElse(0);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static Optional<String> test(List<String> list) {
|
||||
for (String s : list) {
|
||||
return Optional.of(s);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(asList("a", "b", "c")));
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
private static long test(List<List<String>> nested) {
|
||||
long count = 0;
|
||||
for (List<String> names : nested) {
|
||||
Set<String> uniqueValues = new HashSet<>();
|
||||
for (String name : names) {
|
||||
if (uniqueValues.add(name)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(asList(asList("a"), asList(null, "bb", "ccc"))));
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.IntSummaryStatistics;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
public static IntSummaryStatistics test() {
|
||||
IntSummaryStatistics stat = new IntSummaryStatistics();
|
||||
long limit = 50;
|
||||
OUTER:
|
||||
for (int x = 0; x < 100; x++) {
|
||||
long limitInner = x / 2;
|
||||
for (int i = 0; i < x; i++) {
|
||||
if (limitInner-- == 0) break;
|
||||
if (limit-- == 0) break OUTER;
|
||||
stat.accept(i);
|
||||
}
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.IntSummaryStatistics;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
public static IntSummaryStatistics test() {
|
||||
IntSummaryStatistics stat = new IntSummaryStatistics();
|
||||
long limit = 500;
|
||||
OUTER:
|
||||
for (int x = 0; x < 100; x++) {
|
||||
long limitInner = x / 2;
|
||||
INNER:
|
||||
for (int y = 0; y < x; y++) {
|
||||
long limit1 = 10;
|
||||
int bound = y + 100;
|
||||
for (int i = y; i < bound; i++) {
|
||||
if (limit1-- == 0) break;
|
||||
if (limitInner-- == 0) break INNER;
|
||||
if (limit-- == 0) break OUTER;
|
||||
stat.accept(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.IntSummaryStatistics;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
public static IntSummaryStatistics test() {
|
||||
IntSummaryStatistics stat = new IntSummaryStatistics();
|
||||
long limit = 500;
|
||||
OUTER:
|
||||
for (int x = 0; x < 100; x++) {
|
||||
long limitInner = x / 2;
|
||||
INNER:
|
||||
for (int y = 0; y < x; y++) {
|
||||
long limit1 = 10;
|
||||
int boundInner = y + 100;
|
||||
INNER1:
|
||||
for (int z = y; z < boundInner; z++) {
|
||||
int bound = z + 2;
|
||||
for (int i = z; i < bound; i++) {
|
||||
if (limit1-- == 0) break INNER1;
|
||||
if (limitInner-- == 0) break INNER;
|
||||
if (limit-- == 0) break OUTER;
|
||||
stat.accept(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
|
||||
private static long test(Map<String, List<String>> strings) {
|
||||
long count = 0;
|
||||
for (Map.Entry<String, List<String>> e : strings.entrySet()) {
|
||||
if (!e.getKey().isEmpty()) {
|
||||
String sInner = e.getKey();
|
||||
for (String s : e.getValue()) {
|
||||
if (sInner.equals(s)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Map<String, List<String>> map = new HashMap<>();
|
||||
map.put("", Arrays.asList("", "a", "b"));
|
||||
map.put("a", Arrays.asList("", "a", "b", "a"));
|
||||
map.put("b", Arrays.asList("", "a", "b"));
|
||||
map.put("c", Arrays.asList("", "a", "b"));
|
||||
System.out.println(test(map));
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.LongSummaryStatistics;
|
||||
|
||||
public class Main {
|
||||
public static LongSummaryStatistics test(List<List<String>> list) {
|
||||
return list.stream().filter(a -> a != null).flatMapToLong(lst -> lst.stream().distinct().mapToLong(a -> a.length())).summa<caret>ryStatistics();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList(null, Arrays.asList("aaa", "b", "cc", "cc", "dddd"), Arrays.asList("cc", "b", "gggg"))));
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.IntSummaryStatistics;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static IntSummaryStatistics test(List<List<List<String>>> list) {
|
||||
IntSummaryStatistics stat = new IntSummaryStatistics();
|
||||
for (List<List<String>> l : list) {
|
||||
if (l != null) {
|
||||
for (List<String> lst : l) {
|
||||
if (lst != null) {
|
||||
for (String str : lst) {
|
||||
int i = str.length();
|
||||
stat.accept(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(asList(asList(asList("a", "bbb", "ccc")), asList(), null, asList(asList("z")))));
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.LongSummaryStatistics;
|
||||
|
||||
public class Main {
|
||||
public static LongSummaryStatistics test(List<List<String>> list) {
|
||||
LongSummaryStatistics stat = new LongSummaryStatistics();
|
||||
for (List<String> a : list) {
|
||||
if (a != null) {
|
||||
for (String s : a) {
|
||||
long l = s.length();
|
||||
stat.accept(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList(null, Arrays.asList("aaa", "b", "cc", "dddd"), Arrays.asList("gggg"))));
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.IntSummaryStatistics;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
public static IntSummaryStatistics test(int... values) {
|
||||
IntSummaryStatistics stat = new IntSummaryStatistics();
|
||||
long toSkipOuter = 1;
|
||||
for (int x : values) {
|
||||
if (toSkipOuter > 0) {
|
||||
toSkipOuter--;
|
||||
continue;
|
||||
}
|
||||
if (x > 0) {
|
||||
long toSkip = x;
|
||||
for (int i = 0; i < 100; i++) {
|
||||
if (toSkip > 0) {
|
||||
toSkip--;
|
||||
continue;
|
||||
}
|
||||
stat.accept(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(1, 95, -2, 0, 97, 90));
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.IntSummaryStatistics;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
public static IntSummaryStatistics test(int... values) {
|
||||
IntSummaryStatistics stat = new IntSummaryStatistics();
|
||||
long toSkip = 1;
|
||||
for (int x : values) {
|
||||
if (x > 0) {
|
||||
long toSkipInner = x;
|
||||
for (int i = 0; i < 100; i++) {
|
||||
if (toSkipInner > 0) {
|
||||
toSkipInner--;
|
||||
continue;
|
||||
}
|
||||
if (toSkip > 0) {
|
||||
toSkip--;
|
||||
continue;
|
||||
}
|
||||
stat.accept(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(1, 95, -2, 0, 97, 90));
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static void test(List<String> list) {
|
||||
for (String x : list) {
|
||||
if (x != null) {
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
test(Arrays.asList("a", "b", "xyz"));
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class Main {
|
||||
static Predicate<String> nonEmpty = s -> s != null && !s.isEmpty();
|
||||
|
||||
private static long test(List<String> strings) {
|
||||
long count = 0;
|
||||
for (String string : strings) {
|
||||
if (nonEmpty.test(string)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class Main {
|
||||
private static long test(List<Predicate<String>> predicates, List<String> strings) {
|
||||
long count = 0;
|
||||
for (Predicate<String> pred : predicates) {
|
||||
if (pred != null) {
|
||||
for (String string : strings) {
|
||||
if (pred.test(string)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(
|
||||
Arrays.asList(String::isEmpty, s -> s.length() > 3),
|
||||
Arrays.asList("", "a", "abcd", "xyz")
|
||||
));
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.IntSummaryStatistics;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
public static IntSummaryStatistics test() {
|
||||
IntSummaryStatistics stat = new IntSummaryStatistics();
|
||||
long limit = 33;
|
||||
OUTER:
|
||||
while (true) {
|
||||
Integer x = 10;
|
||||
for (int i = 0; i < x; i++) {
|
||||
if (limit-- == 0) break OUTER;
|
||||
stat.accept(i);
|
||||
}
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.IntSummaryStatistics;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
public static Integer getInt() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
public static IntSummaryStatistics test() {
|
||||
IntSummaryStatistics stat = new IntSummaryStatistics();
|
||||
long limit = 33;
|
||||
OUTER:
|
||||
while (true) {
|
||||
Integer x = Main.getInt();
|
||||
for (int i = 0; i < x; i++) {
|
||||
if (limit-- == 0) break OUTER;
|
||||
stat.accept(i);
|
||||
}
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.DoubleSummaryStatistics;
|
||||
import java.util.Random;
|
||||
import java.util.stream.DoubleStream;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
public static DoubleSummaryStatistics test() {
|
||||
Random r = new Random();
|
||||
DoubleSummaryStatistics stat = new DoubleSummaryStatistics();
|
||||
for (int x = 0; x < 10; x++) {
|
||||
double x1 = x;
|
||||
long limit = (long) x1;
|
||||
while (true) {
|
||||
double v = r.nextDouble() * x1;
|
||||
if (limit-- == 0) break;
|
||||
stat.accept(v);
|
||||
}
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static void test(List<String> list) {
|
||||
boolean found = false;
|
||||
for (String x : list) {
|
||||
if (x != null) {
|
||||
if (x.startsWith("x")) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(found) {
|
||||
System.out.println("Ok!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
test(Arrays.asList("a", "b", "xyz"));
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.IntSummaryStatistics;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
private static IntSummaryStatistics test() {
|
||||
IntSummaryStatistics stat = new IntSummaryStatistics();
|
||||
for (int i : new int[]{1, 2, 3}) {
|
||||
stat.accept(i);
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.IntSummaryStatistics;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
private static IntSummaryStatistics test() {
|
||||
IntSummaryStatistics stat = new IntSummaryStatistics();
|
||||
for (int i : new int[]{1, 2, 3}) {
|
||||
stat.accept(i);
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.IntSummaryStatistics;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
public static IntSummaryStatistics test() {
|
||||
IntSummaryStatistics stat = new IntSummaryStatistics();
|
||||
long limit = 20;
|
||||
for (String x = ""; ; x = x + "a") {
|
||||
if (limit-- == 0) break;
|
||||
int i = x.length();
|
||||
stat.accept(i);
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public static List<String> test() {
|
||||
List<String> list = new ArrayList<>();
|
||||
long limit = 20;
|
||||
for (String x = ""; ; x = x + "a") {
|
||||
if (limit-- == 0) break;
|
||||
list.add(x);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.IntSummaryStatistics;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
public static IntSummaryStatistics test() {
|
||||
IntSummaryStatistics stat = new IntSummaryStatistics();
|
||||
for (int limit = 0; limit < 20; limit++) {
|
||||
long limitInner = limit;
|
||||
for (String x = ""; ; x = x + limit) {
|
||||
if (limitInner-- == 0) break;
|
||||
int i = x.length();
|
||||
stat.accept(i);
|
||||
}
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
private static List<String> test() {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (int x = 0; x < 20; x++) {
|
||||
Integer integer = x;
|
||||
long limit = integer;
|
||||
for (String str = ""; ; str = "a" + str) {
|
||||
if (limit-- == 0) break;
|
||||
list.add(str);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(String.join("|", test()).length());
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.IntSummaryStatistics;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
public static IntSummaryStatistics test() {
|
||||
IntSummaryStatistics stat = new IntSummaryStatistics();
|
||||
for (int x = 0; x < 20; x++) {
|
||||
if (x > 2) {
|
||||
long limit = x;
|
||||
for (String s = String.valueOf(x); ; s = s + x) {
|
||||
if (limit-- == 0) break;
|
||||
int i = s.length();
|
||||
stat.accept(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.IntSummaryStatistics;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
public static IntSummaryStatistics test() {
|
||||
IntSummaryStatistics stat = new IntSummaryStatistics();
|
||||
long limit = 50;
|
||||
for (int i = 0; i < 100; i++) {
|
||||
if (limit-- == 0) break;
|
||||
stat.accept(i);
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static long countNonEmpty(List<String> input) {
|
||||
long count = 0;
|
||||
for (String str : input) {
|
||||
String s = str.trim();
|
||||
if (!s.isEmpty()) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(countNonEmpty(Arrays.asList("a", "", "b", "", "")));
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static String getString() {
|
||||
return "abc";
|
||||
}
|
||||
|
||||
private static boolean test(List<String> strings) {
|
||||
String s = getString();
|
||||
for (String string : strings) {
|
||||
if (s.equals(string)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList("a", "b", "c")));
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Main {
|
||||
private static void test(List<String> names) {
|
||||
for (String name : names) {
|
||||
if (Objects.nonNull(name)) {
|
||||
System.out.println(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
test(Arrays.asList("a", "b", "xyz"));
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
|
||||
private static long test(Map<String, List<String>> strings) {
|
||||
long sum = 0;
|
||||
for (Map.Entry<String, List<String>> e : strings.entrySet()) {
|
||||
if (!e.getKey().isEmpty()) {
|
||||
long l = e.getValue().stream().filter(new Predicate<String>() {
|
||||
@Override
|
||||
public boolean test(String s) {
|
||||
return e.getKey().equals(s);
|
||||
}
|
||||
}).count();
|
||||
sum += l;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
boolean x = Stream.of(1, 2, 3).anyMatch(Objects::nonNull);
|
||||
Map<String, List<String>> map = new HashMap<>();
|
||||
map.put("", Arrays.asList("", "a", "b"));
|
||||
map.put("a", Arrays.asList("", "a", "b", "a"));
|
||||
map.put("b", Arrays.asList("", "a", "b"));
|
||||
map.put("c", Arrays.asList("", "a", "b"));
|
||||
System.out.println(test(map));
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
|
||||
private static long test(Map<String, List<String>> strings) {
|
||||
long sum = 0;
|
||||
for (Map.Entry<String, List<String>> e : strings.entrySet()) {
|
||||
if (!e.getKey().isEmpty()) {
|
||||
long l = e.getValue().stream().filter(s -> e.getKey().equals(s)).count();
|
||||
sum += l;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
boolean x = Stream.of(1, 2, 3).anyMatch(Objects::nonNull);
|
||||
Map<String, List<String>> map = new HashMap<>();
|
||||
map.put("", Arrays.asList("", "a", "b"));
|
||||
map.put("a", Arrays.asList("", "a", "b", "a"));
|
||||
map.put("b", Arrays.asList("", "a", "b"));
|
||||
map.put("c", Arrays.asList("", "a", "b"));
|
||||
System.out.println(test(map));
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
|
||||
private static long test(Map<String, List<String>> strings) {
|
||||
long sum = 0;
|
||||
for (Map.Entry<String, List<String>> s : strings.entrySet()) {
|
||||
if (!s.getKey().isEmpty()) {
|
||||
long l = s.getValue().stream().filter(sx -> s.getKey().equals(sx)).count();
|
||||
sum += l;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
boolean x = Stream.of(1, 2, 3).anyMatch(Objects::nonNull);
|
||||
Map<String, List<String>> map = new HashMap<>();
|
||||
map.put("", Arrays.asList("", "a", "b"));
|
||||
map.put("a", Arrays.asList("", "a", "b", "a"));
|
||||
map.put("b", Arrays.asList("", "a", "b"));
|
||||
map.put("c", Arrays.asList("", "a", "b"));
|
||||
System.out.println(test(map));
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static long test(List<String> list) {
|
||||
long count = 0;
|
||||
for (String l : list) {
|
||||
if (l != null) {
|
||||
(new Consumer<String>() {
|
||||
String lst = "hello";
|
||||
|
||||
public void accept(String lst) {
|
||||
System.out.println(this.lst + lst);
|
||||
}
|
||||
}).accept(l);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(asList("a", "b", "c")));
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static long test(List<String> list) {
|
||||
long count = 0;
|
||||
for (String l : list) {
|
||||
if (l != null) {
|
||||
(new Consumer<String>() {
|
||||
String list = "hello";
|
||||
|
||||
public void accept(String list) {
|
||||
System.out.println(this.list + l);
|
||||
}
|
||||
}).accept(l);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(asList("a", "b", "c")));
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static boolean test(List<List<String>> list) {
|
||||
for (List<String> x : list) {
|
||||
if (x != null) {
|
||||
for (String str : x) {
|
||||
if (str.startsWith("a")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(asList(asList(), asList("a"), asList("b", "c"))));
|
||||
System.out.println(test(asList(asList(), asList("d"), asList("b", "c"))));
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Main {
|
||||
private static String test(List<String> list) {
|
||||
if (list == null) return null;
|
||||
else {
|
||||
Optional<String> found = Optional.empty();
|
||||
for (String str : list) {
|
||||
if (str.contains("x")) {
|
||||
found = Optional.of(str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found.orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList("a", "b", "syz")));
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public static int test(List<String> list) {
|
||||
int sum = 0;
|
||||
for (String s : list) {
|
||||
System.out.println(s);
|
||||
int i = s.length();
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList("aaa", "b", "cc", "dddd")));
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.LongSummaryStatistics;
|
||||
|
||||
public class Main {
|
||||
public static LongSummaryStatistics test(List<String> list) {
|
||||
LongSummaryStatistics stat = new LongSummaryStatistics();
|
||||
for (String s : list) {
|
||||
System.out.println(s);
|
||||
long l = s.length();
|
||||
stat.accept(l);
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList("aaa", "b", "cc", "dddd")));
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
private static long check(int start, int stop, double v) {
|
||||
long count = 0;
|
||||
for (int x = start; x < stop; x++) {
|
||||
double x1 = 1.0 / x;
|
||||
if (x1 < v) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(check(1, 100, 0.04));
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
private static long check(int start, double val) {
|
||||
long count = 0;
|
||||
int bound = start * 200;
|
||||
for (int x = start; x <= bound; x++) {
|
||||
double v = 1.0 / x;
|
||||
if (v < val) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(check(2, 0.04));
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static String test(List<String> list) {
|
||||
String acc = "";
|
||||
for (String s : list) {
|
||||
acc = acc + s;
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(asList("a", "b", "c")));
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static int test(List<String> list) {
|
||||
Integer acc = 0;
|
||||
for (String s : list) {
|
||||
acc = acc + s.length();
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(asList("a", "b", "c")));
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static Integer test(List<Integer> numbers) {
|
||||
Integer acc = 0;
|
||||
for (Integer number : numbers) {
|
||||
acc = Math.max(acc, number);
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
test(Arrays.asList("a", "b", "xyz"));
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.OptionalInt;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
private static OptionalInt test() {
|
||||
boolean seen = false;
|
||||
int acc = 0;
|
||||
for (int i : new int[]{}) {
|
||||
if (!seen) {
|
||||
seen = true;
|
||||
acc = i;
|
||||
} else {
|
||||
acc = acc * i;
|
||||
}
|
||||
}
|
||||
return (seen ? OptionalInt.of(acc) : OptionalInt.empty());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
private static Optional<Integer> test(Integer... numbers) {
|
||||
boolean seen = false;
|
||||
Integer acc = null;
|
||||
for (Integer number : numbers) {
|
||||
if (!seen) {
|
||||
seen = true;
|
||||
acc = number;
|
||||
} else {
|
||||
acc = acc * number;
|
||||
}
|
||||
}
|
||||
return (seen ? Optional.of(acc) : Optional.empty());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(1,2,3,4));
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
private static long test(List<?> list) {
|
||||
long count = 0;
|
||||
Set<Object> uniqueValues = new HashSet<>();
|
||||
long toSkip = list.size() / 2;
|
||||
for (Object o : list) {
|
||||
if (toSkip > 0) {
|
||||
toSkip--;
|
||||
continue;
|
||||
}
|
||||
if (uniqueValues.add(o)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList(1,2,3,3,2,1,1,2,3)));
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
private static String test(List<CharSequence> list) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Set<CharSequence> uniqueValues = new HashSet<>();
|
||||
long toSkip = 1;
|
||||
for (CharSequence charSequence : list) {
|
||||
if (toSkip > 0) {
|
||||
toSkip--;
|
||||
continue;
|
||||
}
|
||||
if (uniqueValues.add(charSequence)) {
|
||||
sb.append(charSequence);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList("a", "b", "e", "c", "d", "e", "a")));
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
private static String test(List<CharSequence> list, String delimiter) {
|
||||
StringJoiner joiner = new StringJoiner(delimiter);
|
||||
long toSkip = 2;
|
||||
Set<CharSequence> uniqueValues = new HashSet<>();
|
||||
long toSkip1 = 1;
|
||||
for (CharSequence charSequence : list) {
|
||||
if (toSkip1 > 0) {
|
||||
toSkip1--;
|
||||
continue;
|
||||
}
|
||||
if (uniqueValues.add(charSequence)) {
|
||||
if (toSkip > 0) {
|
||||
toSkip--;
|
||||
continue;
|
||||
}
|
||||
joiner.add(charSequence);
|
||||
}
|
||||
}
|
||||
return joiner.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList("a", "b", "e", "c", "d", "e", "a"), ";"));
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
private static String test(List<CharSequence> list, String delimiter) {
|
||||
StringJoiner joiner = new StringJoiner(delimiter, "<", ">");
|
||||
Set<CharSequence> uniqueValues = new HashSet<>();
|
||||
long toSkip = 1;
|
||||
for (CharSequence charSequence : list) {
|
||||
if (toSkip > 0) {
|
||||
toSkip--;
|
||||
continue;
|
||||
}
|
||||
if (uniqueValues.add(charSequence)) {
|
||||
joiner.add(charSequence);
|
||||
}
|
||||
}
|
||||
return joiner.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList("a", "b", "e", "c", "d", "e", "a"), ";"));
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.IntSummaryStatistics;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
private static IntSummaryStatistics test() {
|
||||
IntSummaryStatistics stat = new IntSummaryStatistics();
|
||||
for (Integer i : new Integer[]{1, 2, 3}) {
|
||||
int i1 = i;
|
||||
stat.accept(i1);
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.IntSummaryStatistics;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
private static IntSummaryStatistics test() {
|
||||
IntSummaryStatistics stat = new IntSummaryStatistics();
|
||||
for (Number[] nums : Arrays.<Number[]>asList(new Integer[]{1, 2, 3})) {
|
||||
int i = (int) nums[0];
|
||||
stat.accept(i);
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.IntSummaryStatistics;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
private static IntSummaryStatistics test() {
|
||||
IntSummaryStatistics stat = new IntSummaryStatistics();
|
||||
for (Supplier<Integer> sup : Arrays.<Supplier<Integer>>asList(() -> 1, () -> 2, () -> 3)) {
|
||||
int i = sup.get();
|
||||
stat.accept(i);
|
||||
}
|
||||
return stat;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static Integer[][] test(int[] numbers) {
|
||||
List<Integer[]> list = new ArrayList<>();
|
||||
for (int number : numbers) {
|
||||
Integer n = number;
|
||||
Integer[] integers = new Integer[]{n};
|
||||
list.add(integers);
|
||||
}
|
||||
return list.toArray(new Integer[0][]);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Arrays.asList(test(new int[] {1,2,3})));
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static Number[] test(int[] numbers) {
|
||||
List<Integer> list = new ArrayList<>();
|
||||
for (int number : numbers) {
|
||||
Integer integer = number;
|
||||
list.add(integer);
|
||||
}
|
||||
return list.toArray(new Integer[0]);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Arrays.asList(test(new int[] {1,2,3})));
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static List<?>[] test(int[] numbers) {
|
||||
List<List<?>> list = new ArrayList<>();
|
||||
for (int number : numbers) {
|
||||
Integer n = number;
|
||||
List<Integer> integers = Collections.singletonList(n);
|
||||
list.add(integers);
|
||||
}
|
||||
return list.toArray(new List<?>[0]);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Arrays.asList(test(new int[] {1,2,3})));
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
private static Object[] test(int[] numbers) {
|
||||
List<Object> list = new ArrayList<>();
|
||||
for (int number : numbers) {
|
||||
Integer integer = number;
|
||||
list.add(integer);
|
||||
}
|
||||
return list.toArray();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Arrays.asList(test(new int[] {1,2,3})));
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
private static TreeSet<Integer> test() {
|
||||
TreeSet<Integer> collection = new TreeSet<Integer>();
|
||||
for (int i : new int[]{4, 2, 1}) {
|
||||
Integer integer = i;
|
||||
collection.add(integer);
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
private static int[] test() {
|
||||
int[] arr = new int[10];
|
||||
int count = 0;
|
||||
for (int x = -100; x < 100; x++) {
|
||||
if (x > 0) {
|
||||
if (arr.length == count) arr = Arrays.copyOf(arr, count * 2);
|
||||
arr[count++] = x;
|
||||
}
|
||||
}
|
||||
return Arrays.copyOfRange(arr, 0, count);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Arrays.toString(test()));
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static boolean test(List<List<String>> list) {
|
||||
return list.stream().filter(x -> x != null).flatMap(x -> x.stream()).allMat<caret>ch(x -> x.startsWith("a"));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(asList(asList(), asList("a"), asList("b", "c"))));
|
||||
System.out.println(test(asList(asList(), asList("d"), asList("b", "c"))));
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static void test(List<List<String>> list) {
|
||||
if(list.stream().filter(x -> x != null).flatMap(x -> x.stream()).allMat<caret>ch(x -> x.startsWith("a"))) {
|
||||
System.out.println("ok");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(asList(asList(), asList("a"), asList("b", "c"))));
|
||||
System.out.println(test(asList(asList(), asList("d"), asList("b", "c"))));
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static boolean test(List<List<String>> list) {
|
||||
return list.stream().filter(x -> x != null).flatMap(x -> x.stream()).anyMat<caret>ch(x -> x.startsWith("a"));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(asList(asList(), asList("a"), asList("b", "c"))));
|
||||
System.out.println(test(asList(asList(), asList("d"), asList("b", "c"))));
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Main {
|
||||
private static long test() {
|
||||
return Arrays.stream(new Integer[] {1,2,3,2,3}).skip(1).distinct().cou<caret>nt();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test());
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.stream.LongStream;
|
||||
|
||||
public class Main {
|
||||
private static OptionalDouble test(long... numbers) {
|
||||
return LongStream.of(numbers).filter(x -> x > 0).asDoubleStream().avera<caret>ge();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(-1,-2,-3, Long.MAX_VALUE, Long.MAX_VALUE));
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
private static OptionalDouble test(int... numbers) {
|
||||
return IntStream.of(numbers).filter(x -> x > 0).aver<caret>age();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(-1,-2,-3));
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.stream.LongStream;
|
||||
|
||||
public class Main {
|
||||
private static OptionalDouble test(long... numbers) {
|
||||
return LongStream.of(numbers).filter(x -> x > 0).avera<caret>ge();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(-1,-2,-3, Long.MAX_VALUE, Long.MAX_VALUE));
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
private static List<Integer> test(int[] numbers) {
|
||||
return Arrays.stream(numbers).boxed().c<caret>ollect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(new int[] {1,2,3}));
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static Optional<String> test(List<String> list) {
|
||||
return list.stream().coll<caret>ect(Collectors.reducing((a, b) -> a+b));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(asList("a", "b", "c")));
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class Main {
|
||||
public static String test(List<String> list) {
|
||||
return list.stream().coll<caret>ect(Collectors.reducing("", (a, b) -> a+b));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(asList("a", "b", "c")));
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public void test(List<String> list) {
|
||||
long x = list.stream().coun<caret>t();
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
static class Count {
|
||||
}
|
||||
|
||||
public long test(List<Count> count) {
|
||||
return count.stream().co<caret>unt();
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public long test(List<String> list) {
|
||||
if(!list.isEmpty()) return list.stream().coun<caret>t();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public long test(List<String> list) {
|
||||
return list.stream().coun<caret>t();
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public long test(List<String> list) {
|
||||
return list.stream().distinct().c<caret>ount();
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user