StreamToLoop tests grouped

This commit is contained in:
Tagir Valeev
2017-01-27 17:38:37 +07:00
parent babce0b78c
commit fb6ba726e5
307 changed files with 2749 additions and 4686 deletions

View File

@@ -1,6 +1,6 @@
// "Replace Stream API chain with loop" "true"
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
import java.util.List;
import java.util.*;
import static java.util.Arrays.asList;
@@ -18,8 +18,62 @@ public class Main {
return true;
}
private static boolean testEqEq(List<String> list) {
for (String s : list) {
if (s.trim() != s.toLowerCase()) {
return false;
}
}
return true;
}
public static void testIf(List<List<String>> list) {
boolean b = true;
OUTER:
for (List<String> x : list) {
if (x != null) {
for (String s : x) {
if (!s.startsWith("a")) {
b = false;
break OUTER;
}
}
}
}
if(b) {
System.out.println("ok");
}
}
boolean testNot(String... strings) {
for (String s : strings) {
if (s != null) {
if (!s.startsWith("xyz")) {
return true;
}
}
}
return false;
}
public void testVar(List<Integer> list) {
boolean x = false;
for (Integer i : list) {
if (i <= 2) {
x = true;
break;
}
}
if(x) {
System.out.println("found");
}
}
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"))));
System.out.println(testEqEq(Arrays.asList("a", "b", "c")));
System.out.println(testIf(asList(asList(), asList("a"), asList("b", "c"))));
System.out.println(testIf(asList(asList(), asList("d"), asList("b", "c"))));
}
}

View File

@@ -1,19 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.Arrays;
import java.util.List;
public class Main {
private static boolean test(List<String> list) {
for (String s : list) {
if (s.trim() != s.toLowerCase()) {
return false;
}
}
return true;
}
public static void main(String[] args) {
System.out.println(test(Arrays.asList("a", "b", "c")));
}
}

View File

@@ -1,30 +0,0 @@
// "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 b = true;
OUTER:
for (List<String> x : list) {
if (x != null) {
for (String s : x) {
if (!s.startsWith("a")) {
b = false;
break OUTER;
}
}
}
}
if(b) {
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"))));
}
}

View File

@@ -1,17 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.Arrays;
import java.util.Objects;
public class Main {
boolean test(String[] strings) {
for (String s : strings) {
if (s != null) {
if (!s.startsWith("xyz")) {
return true;
}
}
}
return false;
}
}

View File

@@ -1,6 +1,6 @@
// "Replace Stream API chain with loop" "true"
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
import java.util.List;
import java.util.*;
import static java.util.Arrays.asList;
@@ -18,6 +18,17 @@ public class Main {
return false;
}
String testTernary(String[] strings) {
for (String s : strings) {
if (s != null) {
if (!s.startsWith("xyz")) {
return "s";
}
}
}
return null;
}
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"))));

View File

@@ -1,17 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.Arrays;
import java.util.Objects;
public class Main {
String test(String[] strings) {
for (String s : strings) {
if (s != null) {
if (!s.startsWith("xyz")) {
return "s";
}
}
}
return null;
}
}

View File

@@ -1,18 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.List;
public class Main {
public void test(List<Integer> list) {
boolean x = false;
for (Integer i : list) {
if (i <= 2) {
x = true;
break;
}
}
if(x) {
System.out.println("found");
}
}
}

View File

@@ -0,0 +1,49 @@
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
import java.util.OptionalDouble;
import java.util.stream.*;
public class Main {
private static OptionalDouble testDouble(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.of(sum / count) : OptionalDouble.empty();
}
private static OptionalDouble testInt(int... numbers) {
long sum = 0;
long count = 0;
for (int x : numbers) {
if (x > 0) {
sum += x;
count++;
}
}
return count > 0 ? OptionalDouble.of((double) sum / count) : OptionalDouble.empty();
}
private static OptionalDouble testLong(long... numbers) {
long sum = 0;
long count = 0;
for (long x : numbers) {
if (x > 0) {
sum += x;
count++;
}
}
return count > 0 ? OptionalDouble.of((double) sum / count) : OptionalDouble.empty();
}
public static void main(String[] args) {
System.out.println(testDouble(-1,-2,-3, Long.MAX_VALUE, Long.MAX_VALUE));
System.out.println(testInt(-1,-2,-3));
System.out.println(testLong(-1,-2,-3, Long.MAX_VALUE, Long.MAX_VALUE));
}
}

View File

@@ -1,23 +0,0 @@
// "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.of(sum / count) : OptionalDouble.empty();
}
public static void main(String[] args) {
System.out.println(test(-1,-2,-3, Long.MAX_VALUE, Long.MAX_VALUE));
}
}

View File

@@ -1,22 +0,0 @@
// "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.of((double) sum / count) : OptionalDouble.empty();
}
public static void main(String[] args) {
System.out.println(test(-1,-2,-3));
}
}

View File

@@ -1,22 +0,0 @@
// "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.of((double) sum / count) : OptionalDouble.empty();
}
public static void main(String[] args) {
System.out.println(test(-1,-2,-3, Long.MAX_VALUE, Long.MAX_VALUE));
}
}

View File

@@ -1,23 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Main {
public void test(String... list) {
double sum = 0;
long count = 0;
for (String s : list) {
if (s != null) {
sum += 1.0 / s;
count++;
}
}
System.out.println(count > 0 ? sum / count : 0.0);
}
public static void main(String[] args) {
new Main().test("a", "bbb", null, "cc", "dd", "eedasfasdfs");
}
}

View File

@@ -1,23 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Main {
public void test(String... list) {
long sum = 0;
long count = 0;
for (String s : list) {
if (s != null) {
sum += s.length();
count++;
}
}
System.out.println(count > 0 ? (double) sum / count : 0.0);
}
public static void main(String[] args) {
new Main().test("a", "bbb", null, "cc", "dd", "eedasfasdfs");
}
}

View File

@@ -1,21 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Main {
public static long test(List<String> strings) {
long count = 0L;
for (String s : strings) {
if (!s.isEmpty()) {
count++;
}
}
return count;
}
public static void main(String[] args) {
System.out.println(test(Arrays.asList()));
System.out.println(test(Arrays.asList("a", "bbb", "cc", "d", "eee", "")));
}
}

View File

@@ -1,19 +1,25 @@
// "Replace Stream API chain with loop" "true"
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
public class Main {
public List<? extends CharSequence> getList() {
private List<? extends CharSequence> asList(CharSequence s) {
return Collections.singletonList(s);
}
public List<? extends CharSequence> getListExtends() {
return Collections.emptyList();
}
public List<CharSequence> getList() {
return Collections.emptyList();
}
private void collect() {
List<CharSequence> list = new ArrayList<>();
for (CharSequence charSequence : getList()) {
for (CharSequence charSequence : getListExtends()) {
if (charSequence != null) {
list.add(charSequence);
}
@@ -21,4 +27,57 @@ public class Main {
List<? extends CharSequence> res = list;
System.out.println(res);
}
private void collect2() {
List<List<? extends CharSequence>> list = new ArrayList<>();
for (CharSequence charSequence : getListExtends()) {
List<? extends CharSequence> charSequences = asList(charSequence);
list.add(charSequences);
}
List<? extends List<? extends CharSequence>> res2 = list;
System.out.println(res2);
}
static class MyList<T> extends ArrayList<List<? extends CharSequence>> {
}
private void collectCustomList() {
MyList<? extends List<? extends CharSequence>> res2 =
new MyList<>();
for (CharSequence charSequence : getListExtends()) {
List<? extends CharSequence> charSequences = asList(charSequence);
res2.add(charSequences);
}
System.out.println(res2);
}
static class MyList2<T, X> extends ArrayList<X> {
}
public MyList2<? extends Number, CharSequence> createMyList2() {
return new MyList2<>();
}
private void collectGroupingByCustomList() {
Map<Integer, MyList2<? extends Number, CharSequence>> result = new HashMap<>();
for (CharSequence x : getList()) {
result.computeIfAbsent(x.length(), k -> createMyList2()).add(x);
}
Map<Integer, ? extends MyList2<? extends Number, ? extends CharSequence>> map =
result;
System.out.println(map);
}
private void collectToMap() {
Map<CharSequence, List<? extends CharSequence>> result = new HashMap<>();
for (CharSequence charSequence : getList()) {
if (charSequence != null) {
if (result.put(charSequence, asList(charSequence)) != null) {
throw new IllegalStateException("Duplicate key");
}
}
}
Map<? extends CharSequence, ? extends List<? extends CharSequence>> map = result;
System.out.println(map);
}
}

View File

@@ -1,26 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class Main {
private List<? extends CharSequence> asList(CharSequence s) {
return Collections.singletonList(s);
}
public List<? extends CharSequence> getList() {
return Collections.emptyList();
}
private void collect() {
List<List<? extends CharSequence>> list = new ArrayList<>();
for (CharSequence charSequence : getList()) {
List<? extends CharSequence> charSequences = asList(charSequence);
list.add(charSequences);
}
List<? extends List<? extends CharSequence>> res2 = list;
System.out.println(res2);
}
}

View File

@@ -1,25 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Main {
static class MyList<T, X> extends ArrayList<X> {}
public List<CharSequence> getList() {
return Collections.emptyList();
}
public MyList<? extends Number, CharSequence> createList() {
return new MyList<>();
}
private void collect() {
Map<Integer, MyList<? extends Number, CharSequence>> result = new HashMap<>();
for (CharSequence x : getList()) {
result.computeIfAbsent(x.length(), k -> createList()).add(x);
}
Map<Integer, ? extends MyList<? extends Number, ? extends CharSequence>> map =
result;
System.out.println(map);
}

View File

@@ -1,29 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class Main {
static class MyList<T> extends ArrayList<List<? extends CharSequence>> {
}
private List<? extends CharSequence> asList(CharSequence s) {
return Collections.singletonList(s);
}
public List<? extends CharSequence> getList() {
return Collections.emptyList();
}
private void collect() {
MyList<? extends List<? extends CharSequence>> res2 =
new MyList<>();
for (CharSequence charSequence : getList()) {
List<? extends CharSequence> charSequences = asList(charSequence);
res2.add(charSequences);
}
System.out.println(res2);
}
}

View File

@@ -1,28 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
public class Main {
public List<? extends CharSequence> asList(CharSequence s) {
return Collections.singletonList(s);
}
public List<? extends CharSequence> getList() {
return Collections.emptyList();
}
private void collect() {
Map<CharSequence, List<? extends CharSequence>> result = new HashMap<>();
for (CharSequence charSequence : getList()) {
if (charSequence != null) {
if (result.put(charSequence, asList(charSequence)) != null) {
throw new IllegalStateException("Duplicate key");
}
}
}
Map<? extends CharSequence, ? extends List<? extends CharSequence>> map = result;
System.out.println(map);
}
}

View File

@@ -1,25 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Main {
public static Optional<String> test(List<String> strings) {
boolean seen = false;
String best = null;
for (String s : strings) {
if (!s.isEmpty()) {
if (!seen || s.compareTo(best) > 0) {
seen = true;
best = s;
}
}
}
return seen ? Optional.of(best) : Optional.empty();
}
public static void main(String[] args) {
System.out.println(test(Arrays.asList()));
System.out.println(test(Arrays.asList("a", "bbb", "cc", "d", "eee", "")));
}
}

View File

@@ -1,27 +0,0 @@
// "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")));
}
}

View File

@@ -1,20 +0,0 @@
// "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")));
}
}

View File

@@ -1,15 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Main<T> {
void test() {
Integer totalLength = 0;
for (String s : Arrays.asList("a", "bb", "ccc")) {
Integer length = s.length();
totalLength = totalLength + length;
}
}
}

View File

@@ -1,24 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.Arrays;
import java.util.DoubleSummaryStatistics;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class Main {
public static DoubleSummaryStatistics test(List<String> strings) {
DoubleSummaryStatistics stat = new DoubleSummaryStatistics();
for (String str : strings) {
if (str != null) {
stat.accept(str.length() / 2.0);
}
}
return stat;
}
public static void main(String[] args) {
System.out.println(test(Arrays.asList(null, null)));
System.out.println(test(Arrays.asList("a", "bbb", "cc", "d", "eee", "")));
}
}

View File

@@ -1,23 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class Main {
public static Double test(List<String> strings) {
double sum = 0.0;
for (String string : strings) {
if (string != null) {
sum += string.length();
}
}
return sum;
}
public static void main(String[] args) {
System.out.println(test(Arrays.asList(null, null)));
System.out.println(test(Arrays.asList("a", "bbb", "cc", "d", "eee", "")));
}
}

View File

@@ -0,0 +1,132 @@
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
import static java.util.Arrays.asList;
import java.util.*;
import java.util.stream.*;
public class Main {
public void testAveragingDouble(String... list) {
double sum = 0;
long count = 0;
for (String s : list) {
if (s != null) {
sum += 1.0 / s.length();
count++;
}
}
System.out.println(count > 0 ? sum / count : 0.0);
}
public void testAveragingInt(String... list) {
long sum = 0;
long count = 0;
for (String s : list) {
if (s != null) {
sum += s.length();
count++;
}
}
System.out.println(count > 0 ? (double) sum / count : 0.0);
}
public static long testCounting(List<String> strings) {
long count = 0L;
for (String s : strings) {
if (!s.isEmpty()) {
count++;
}
}
return count;
}
public static Optional<String> testMaxBy(List<String> strings) {
boolean seen = false;
String best = null;
for (String s : strings) {
if (!s.isEmpty()) {
if (!seen || s.compareTo(best) > 0) {
seen = true;
best = s;
}
}
}
return seen ? Optional.of(best) : Optional.empty();
}
public static Optional<String> testReducing1(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 String testReducing2(List<String> list) {
String acc = "";
for (String s : list) {
acc = acc + s;
}
return acc;
}
static Integer testReducing3() {
Integer totalLength = 0;
for (String s : Arrays.asList("a", "bb", "ccc")) {
Integer length = s.length();
totalLength = totalLength + length;
}
return totalLength;
}
public static DoubleSummaryStatistics testSummarizingDouble(List<String> strings) {
DoubleSummaryStatistics stat = new DoubleSummaryStatistics();
for (String str : strings) {
if (str != null) {
stat.accept(str.length() / 2.0);
}
}
return stat;
}
public static Double testSummingDouble(List<String> strings) {
double sum = 0.0;
for (String string : strings) {
if (string != null) {
sum += string.length();
}
}
return sum;
}
private static TreeSet<Integer> testToCollection() {
TreeSet<Integer> integers = new TreeSet<>();
for (int i : new int[]{4, 2, 1}) {
Integer integer = i;
integers.add(integer);
}
return integers;
}
public static void main(String[] args) {
new Main().testAveragingDouble("a", "bbb", null, "cc", "dd", "eedasfasdfs");
new Main().testAveragingInt("a", "bbb", null, "cc", "dd", "eedasfasdfs");
System.out.println(testCounting(Arrays.asList()));
System.out.println(testCounting(Arrays.asList("a", "bbb", "cc", "d", "eee", "")));
System.out.println(testMaxBy(Arrays.asList()));
System.out.println(testMaxBy(Arrays.asList("a", "bbb", "cc", "d", "eee", "")));
System.out.println(testReducing1(asList("a", "b", "c")));
System.out.println(testReducing2(asList("a", "b", "c")));
System.out.println(testReducing3());
System.out.println(testSummarizingDouble(Arrays.asList(null, null)));
System.out.println(testSummarizingDouble(Arrays.asList("a", "bbb", "cc", "d", "eee", "")));
System.out.println(testSummingDouble(Arrays.asList(null, null)));
System.out.println(testSummingDouble(Arrays.asList("a", "bbb", "cc", "d", "eee", "")));
System.out.println(testToCollection());
}
}

View File

@@ -0,0 +1,43 @@
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
import java.util.List;
public class Main {
public long test(List<String> list) {
long count = 0L;
for (String s : list) {
count++;
}
return count;
}
public void testAssign(List<String> list) {
long x = 0L;
for (String s : list) {
x++;
}
System.out.println(x);
}
static class Count {
}
public long testNameConflict(List<Count> count) {
long result = 0L;
for (Count count1 : count) {
result++;
}
return result;
}
public long testNoBlock(List<String> list) {
if(!list.isEmpty()) {
long count = 0L;
for (String s : list) {
count++;
}
return count;
}
return -1;
}
}

View File

@@ -1,13 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.List;
public class Main {
public void test(List<String> list) {
long x = 0L;
for (String s : list) {
x++;
}
System.out.println(x);
}
}

View File

@@ -1,16 +0,0 @@
// "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 = 0L;
for (Count count1 : count) {
result++;
}
return result;
}
}

View File

@@ -1,16 +0,0 @@
// "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 = 0L;
for (String s : list) {
count++;
}
return count;
}
return -1;
}
}

View File

@@ -1,13 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.List;
public class Main {
public long test(List<String> list) {
long count = 0L;
for (String s : list) {
count++;
}
return count;
}
}

View File

@@ -0,0 +1,35 @@
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.*;
public class Main {
public long testCount(List<String> list) {
long count = 0L;
Set<String> uniqueValues = new HashSet<>();
for (String s : list) {
if (uniqueValues.add(s)) {
count++;
}
}
return count;
}
private static List<Object> testToList(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(testToList(Arrays.asList(1,2,3,5,3,2,2,2,1,1,4,3)));
}
}

View File

@@ -1,18 +0,0 @@
// "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 = 0L;
Set<String> uniqueValues = new HashSet<>();
for (String s : list) {
if (uniqueValues.add(s)) {
count++;
}
}
return count;
}
}

View File

@@ -1,4 +1,4 @@
// "Replace Stream API chain with loop" "true"
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
import java.util.Arrays;
@@ -15,7 +15,67 @@ public class Main {
return count;
}
private static long countInRange1(int... input) {
int x = 1;
long count = 0L;
for (int y : input) {
if (y > 0) {
if (y < 10) {
count++;
}
}
}
return count;
}
private static long countInRange2(int... input) {
int x = 1;
int y = 2;
long count = 0L;
for (int i : input) {
if (i > 0) {
if (i < 10) {
count++;
}
}
}
return count;
}
private static long countInRange3(int... input) {
int x = 1;
int y = 2;
int i = 3;
long count = 0L;
for (int x1 : input) {
if (x1 > 0) {
if (x1 < 10) {
count++;
}
}
}
return count;
}
private static long countInRange4(int... input) {
int x = 1;
int i = 3;
long result = 0L;
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));
System.out.println(countInRange1(1, 2, 3, -1, -2));
System.out.println(countInRange2(1, 2, 3, -1, -2));
System.out.println(countInRange3(1, 2, 3, -1, -2));
System.out.println(countInRange4(1, 2, 3, -1, -2));
}
}

View File

@@ -1,22 +0,0 @@
// "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 = 0L;
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));
}
}

View File

@@ -1,23 +0,0 @@
// "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 = 0L;
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));
}
}

View File

@@ -1,24 +0,0 @@
// "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 = 0L;
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));
}
}

View File

@@ -1,23 +0,0 @@
// "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 = 0L;
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));
}
}

View File

@@ -0,0 +1,75 @@
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
import java.util.List;
import java.util.Optional;
import static java.util.Arrays.asList;
public class Main {
public static Optional<String> testSimple(List<String> list) {
for (String s : list) {
return Optional.of(s);
}
return Optional.empty();
}
public void testAssign(List<String> list) {
String res = "";
for (String s : list) {
String trim = s.trim();
if (!trim.isEmpty()) {
res = trim;
break;
}
}
System.out.println(res);
}
public void testAssignFinal(List<String> list) {
String res = "";
for (String s : list) {
String trim = s.trim();
if (!trim.isEmpty()) {
res = trim;
break;
}
}
System.out.println(res);
}
public static Optional<String> testFlatMap(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 String testFlatMapLabelConflict(List<List<String>> list) {
String res = null;
OUTER:
for(int i=0; i<10; i++) {
String found = "";
OUTER1:
for (List<String> x : list) {
if (x != null) {
for (String s : x) {
found = s;
break OUTER1;
}
}
}
res = found;
}
return res;
}
public static void main(String[] args) {
System.out.println(testSimple(asList("a", "b", "c")));
System.out.println(testFlatMap(asList(asList(), asList("a"), asList("b", "c"))));
System.out.println(testFlatMapLabelConflict(asList(asList(), asList("a"), asList("b", "c"))));
}
}

View File

@@ -1,17 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.List;
public class Main {
public void test(List<String> list) {
String res = "";
for (String s : list) {
String trim = s.trim();
if (!trim.isEmpty()) {
res = trim;
break;
}
}
System.out.println(res);
}
}

View File

@@ -1,17 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.List;
public class Main {
public void test(List<String> list) {
String res = "";
for (String s : list) {
String trim = s.trim();
if (!trim.isEmpty()) {
res = trim;
break;
}
}
System.out.println(res);
}
}

View File

@@ -1,23 +0,0 @@
// "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"))));
}
}

View File

@@ -1,31 +0,0 @@
// "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) {
String res = null;
OUTER:
for(int i=0; i<10; i++) {
String found = "";
OUTER1:
for (List<String> x : list) {
if (x != null) {
for (String s : x) {
found = s;
break OUTER1;
}
}
}
res = found;
}
return res;
}
public static void main(String[] args) {
System.out.println(test(asList(asList(), asList("a"), asList("b", "c"))));
}
}

View File

@@ -1,22 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
import static java.util.Arrays.asList;
public class Main {
public static boolean test(List<List<String>> list) {
for (List<String> strings : list) {
if (strings != null) {
for (String s : strings) {
return true;
}
}
}
return false;
}
public static void main(String[] args) {
System.out.println(test(asList(asList(), asList("a"), asList("b", "c"))));
}
}

View File

@@ -1,17 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.List;
import java.util.Objects;
public class Main {
String test(List<List<String>> strings) {
for (List<String> string : strings) {
if (string != null) {
for (String s : string) {
return "abc";
}
}
}
return "xyz";
}
}

View File

@@ -1,4 +1,4 @@
// "Replace Stream API chain with loop" "true"
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
import java.util.*;
import java.util.stream.*;
@@ -14,7 +14,40 @@ public class Main {
return OptionalInt.empty();
}
private static int test2() {
for (int x = 0; x < 100; x++) {
if (x > 50) {
return x;
}
}
return 0;
}
private static int test3() {
for (int x = 0; x < 100; x++) {
if (x > 50) {
return x;
}
}
return Math.abs(-1);
}
private static int test4() {
OptionalInt found = OptionalInt.empty();
for (int x = 0; x < 100; x++) {
if (x > 50) {
found = OptionalInt.of(x);
break;
}
}
int res = found.orElseGet(() -> Math.abs(-1));
return res;
}
public static void main(String[] args) {
System.out.println(test());
System.out.println(test2());
System.out.println(test3());
System.out.println(test4());
}
}

View File

@@ -1,20 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
import java.util.stream.*;
public class Main {
private static int test() {
for (int x = 0; x < 100; x++) {
if (x > 50) {
return x;
}
}
return 0;
}
public static void main(String[] args) {
System.out.println(test());
}
}

View File

@@ -1,20 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
import java.util.stream.*;
public class Main {
private static int test() {
for (int x = 0; x < 100; x++) {
if (x > 50) {
return x;
}
}
return Math.abs(-1);
}
public static void main(String[] args) {
System.out.println(test());
}
}

View File

@@ -1,23 +0,0 @@
// "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;
}
}
int res = found.orElseGet(() -> Math.abs(-1));
return res;
}
public static void main(String[] args) {
System.out.println(test());
}
}

View File

@@ -1,19 +0,0 @@
// "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")));
}
}

View File

@@ -0,0 +1,289 @@
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import static java.util.Arrays.asList;
public class Main {
private static long testChain(List<? extends String> list) {
long count = 0L;
for (Object o : Arrays.asList(0, null, "1", list)) {
for (Object o1 : Arrays.asList(o)) {
for (Object o2 : Arrays.asList(o1)) {
for (Object o3 : Arrays.asList(o2)) {
for (Object o4 : Arrays.asList(o3)) {
for (Object o5 : Arrays.asList(o4)) {
count++;
}
}
}
}
}
}
return count;
}
public static void testComplexFilter(List<String> list) {
List<Integer> result = new ArrayList<>();
for (String x : list) {
if (x != null) {
Predicate<Integer> predicate = Predicate.isEqual(x.length());
for (int i = 0; i < 10; i++) {
Integer integer = i;
if (predicate.test(integer)) {
result.add(integer);
}
}
}
}
System.out.println(result);
}
public void testConditional(List<List<String>> list) {
for (List<String> lst : list) {
if (lst != null) {
for (String s : lst) {
System.out.println(s);
}
}
}
}
private static long testDistinctUnpluralize(List<List<String>> nested) {
long count = 0L;
for (List<String> names : nested) {
Set<String> uniqueValues = new HashSet<>();
for (String name : names) {
if (uniqueValues.add(name)) {
count++;
}
}
}
return count;
}
public static IntSummaryStatistics testLimit() {
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 IntSummaryStatistics testLimit3() {
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 IntSummaryStatistics testLimitCrazy() {
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;
}
private static List<String> testMethodRef(List<List<String>> list) {
List<String> result = new ArrayList<>();
for (List<String> strings : list) {
for (String s : strings) {
result.add(s);
}
}
return result;
}
private static List<String> testMethodRef2(List<String[]> list) {
List<String> result = new ArrayList<>();
for (String[] strings : list) {
for (String s : strings) {
result.add(s);
}
}
return result;
}
private static List<List<String>> testMethodRef3(List<List<List<String>>> list) {
List<List<String>> result = new ArrayList<>();
for (List<List<String>> lists : list) {
for (List<String> strings : lists) {
result.add(strings);
}
}
return result;
}
private static long testBoundRename(Map<String, List<String>> strings) {
long count = 0L;
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 IntSummaryStatistics testNestedFlatMap(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 length = str.length();
stat.accept(length);
}
}
}
}
}
return stat;
}
public static LongSummaryStatistics testNestedMap(List<List<String>> list) {
LongSummaryStatistics stat = new LongSummaryStatistics();
for (List<String> a : list) {
if (a != null) {
for (String s : a) {
long length = s.length();
stat.accept(length);
}
}
}
return stat;
}
public static IntSummaryStatistics testNestedSkip(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 IntSummaryStatistics testNestedSkip2(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 String testSorted(List<List<String>> list) {
for (List<String> lst : list) {
List<String> toSort = new ArrayList<>();
for (String x : lst) {
if (x != null) {
toSort.add(x);
}
}
toSort.sort(null);
for (String x : toSort) {
if (x.length() < 5) {
return x;
}
}
}
return "";
}
public static void main(String[] args) {
testChain(asList("aa", "bbb", "c", null, "dd"));
testComplexFilter(asList("a", "bbbb", "cccccccccc", "dd", ""));
System.out.println(testDistinctUnpluralize(asList(asList("a"), asList(null, "bb", "ccc"))));
System.out.println(testLimit());
System.out.println(testLimit3());
System.out.println(testLimitCrazy());
System.out.println(testMethodRef(asList(asList("", "a", "abcd", "xyz"), asList("x", "y"))));
System.out.println(testMethodRef2(asList(new String[] {"", "a", "abcd", "xyz"}, new String[] {"x", "y"})));
System.out.println(testMethodRef3(asList(asList(asList("a", "d")), asList(asList("c"), asList("b")))));
System.out.println(testNestedFlatMap(asList(asList(asList("a", "bbb", "ccc")), asList(), null, asList(asList("z")))));
System.out.println(testNestedMap(asList(null, asList("aaa", "b", "cc", "dddd"), asList("gggg"))));
System.out.println(testNestedSkip(1, 95, -2, 0, 97, 90));
System.out.println(testNestedSkip2(1, 95, -2, 0, 97, 90));
Map<String, List<String>> map = new HashMap<>();
map.put("", asList("", "a", "b"));
map.put("a", asList("", "a", "b", "a"));
map.put("b", asList("", "a", "b"));
map.put("c", asList("", "a", "b"));
System.out.println(testBoundRename(map));
}
}

View File

@@ -1,29 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
public class Main {
private static long test(List<? extends String> list) {
long count = 0L;
for (Object o : Arrays.asList(0, null, "1", list)) {
for (Object o1 : Arrays.asList(o)) {
for (Object o2 : Arrays.asList(o1)) {
for (Object o3 : Arrays.asList(o2)) {
for (Object o4 : Arrays.asList(o3)) {
for (Object o5 : Arrays.asList(o4)) {
count++;
}
}
}
}
}
}
return count;
}
public static void main(String[] args) {
test(Arrays.asList("aa", "bbb", "c", null, "dd"));
}
}

View File

@@ -1,30 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Main {
public static void test(List<String> list) {
List<Integer> result = new ArrayList<>();
for (String x : list) {
if (x != null) {
Predicate<Integer> predicate = Predicate.isEqual(x.length());
for (int i = 0; i < 10; i++) {
Integer integer = i;
if (predicate.test(integer)) {
result.add(integer);
}
}
}
}
System.out.println(result);
}
public static void main(String[] args) {
test(Arrays.asList("a", "bbbb", "cccccccccc", "dd", ""));
}
}

View File

@@ -1,16 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
import java.util.stream.*;
public class Main {
public void test(List<List<String>> list) {
for (List<String> lst : list) {
if (lst != null) {
for (String s : lst) {
System.out.println(s);
}
}
}
}
}

View File

@@ -1,26 +0,0 @@
// "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 = 0L;
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"))));
}
}

View File

@@ -1,25 +0,0 @@
// "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());
}
}

View File

@@ -1,31 +0,0 @@
// "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());
}
}

View File

@@ -1,35 +0,0 @@
// "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());
}
}

View File

@@ -1,23 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
public class Main {
private static List<String> test(List<List<String>> list) {
List<String> result = new ArrayList<>();
for (List<String> strings : list) {
for (String s : strings) {
result.add(s);
}
}
return result;
}
public static void main(String[] args) {
System.out.println(test(Arrays.asList(Arrays.asList("", "a", "abcd", "xyz"), Arrays.asList("x", "y"))));
}
}

View File

@@ -1,23 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Main {
private static List<String> test(List<String[]> list) {
List<String> result = new ArrayList<>();
for (String[] strings : list) {
for (String s : strings) {
result.add(s);
}
}
return result;
}
public static void main(String[] args) {
System.out.println(test(Arrays.asList(new String[] {"", "a", "abcd", "xyz"}, new String[] {"x", "y"})));
}
}

View File

@@ -1,23 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import static java.util.Arrays.asList;
public class Main {
private static List<List<String>> test(List<List<List<String>>> list) {
List<List<String>> result = new ArrayList<>();
for (List<List<String>> lists : list) {
for (List<String> strings : lists) {
result.add(strings);
}
}
return result;
}
public static void main(String[] args) {
System.out.println(test(asList(asList(asList("a", "d")), asList(asList("c"), asList("b")))));
}
}

View File

@@ -1,30 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
public class Main {
private static long test(Map<String, List<String>> strings) {
long count = 0L;
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));
}
}

View File

@@ -1,15 +0,0 @@
// "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"))));
}
}

View File

@@ -1,29 +0,0 @@
// "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 length = str.length();
stat.accept(length);
}
}
}
}
}
return stat;
}
public static void main(String[] args) {
System.out.println(test(asList(asList(asList("a", "bbb", "ccc")), asList(), null, asList(asList("z")))));
}
}

View File

@@ -1,24 +0,0 @@
// "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 length = s.length();
stat.accept(length);
}
}
}
return stat;
}
public static void main(String[] args) {
System.out.println(test(Arrays.asList(null, Arrays.asList("aaa", "b", "cc", "dddd"), Arrays.asList("gggg"))));
}
}

View File

@@ -1,33 +0,0 @@
// "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));
}
}

View File

@@ -1,33 +0,0 @@
// "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));
}
}

View File

@@ -1,23 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
public class Main {
public String testSorted(List<List<String>> list) {
for (List<String> lst : list) {
List<String> toSort = new ArrayList<>();
for (String x : lst) {
if (x != null) {
toSort.add(x);
}
}
toSort.sort(null);
for (String x : toSort) {
if (x.length() < 5) {
return x;
}
}
}
return "";
}
}

View File

@@ -1,21 +0,0 @@
// "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 = 0L;
for (String string : strings) {
if (nonEmpty.test(string)) {
count++;
}
}
return count;
}
public static void main(String[] args) {
}
}

View File

@@ -1,11 +1,22 @@
// "Replace Stream API chain with loop" "true"
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "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) {
static Predicate<String> nonEmpty = s -> s != null && !s.isEmpty();
private static long testFunctionInField(List<String> strings) {
long count = 0L;
for (String string : strings) {
if (nonEmpty.test(string)) {
count++;
}
}
return count;
}
private static long testStreamOfFunctions(List<Predicate<String>> predicates, List<String> strings) {
long count = 0L;
for (Predicate<String> pred : predicates) {
if (pred != null) {
@@ -20,7 +31,7 @@ public class Main {
}
public static void main(String[] args) {
System.out.println(test(
System.out.println(testStreamOfFunctions(
Arrays.asList(String::isEmpty, s -> s.length() > 3),
Arrays.asList("", "a", "abcd", "xyz")
));

View File

@@ -1,11 +1,15 @@
// "Replace Stream API chain with loop" "true"
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
import java.util.DoubleSummaryStatistics;
import java.util.IntSummaryStatistics;
import java.util.Random;
import java.util.SplittableRandom;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class Main {
public static IntSummaryStatistics test() {
public static IntSummaryStatistics generate() {
IntSummaryStatistics stat = new IntSummaryStatistics();
long limit = 33;
OUTER:
@@ -19,7 +23,52 @@ public class Main {
return stat;
}
public static void generateLimit() {
Integer acc = 0;
SplittableRandom splittableRandom = new SplittableRandom(1);
for (long count = 100; count > 0; count--) {
Integer integer = 500;
acc = splittableRandom.nextInt(acc, integer);
}
int n1 = acc;
System.out.println(n1);
}
public static Integer getInt() {
return 10;
}
public static IntSummaryStatistics generateMethodRef() {
IntSummaryStatistics stat = new IntSummaryStatistics();
long limit = 33;
OUTER:
while (true) {
Integer x = getInt();
for (int i = 0; i < x; i++) {
if (limit-- == 0) break OUTER;
stat.accept(i);
}
}
return stat;
}
public static DoubleSummaryStatistics generateNested() {
Random r = new Random();
DoubleSummaryStatistics stat = new DoubleSummaryStatistics();
for (int x = 0; x < 10; x++) {
double v = x;
for (long count = (long) v; count > 0; count--) {
double v1 = r.nextDouble() * v;
stat.accept(v1);
}
}
return stat;
}
public static void main(String[] args) {
System.out.println(test());
System.out.println(generate());
System.out.println(generateMethodRef());
System.out.println(generateNested());
generateLimit();
}
}

View File

@@ -1,17 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.SplittableRandom;
import java.util.stream.Stream;
public class Main {
public static void main(String[] args) {
Integer acc = 0;
SplittableRandom splittableRandom = new SplittableRandom(1);
for (long count = 100; count > 0; count--) {
Integer integer = 500;
acc = splittableRandom.nextInt(acc, integer);
}
int n1 = acc;
System.out.println(n1);
}
}

View File

@@ -1,29 +0,0 @@
// "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 = 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());
}
}

View File

@@ -1,25 +0,0 @@
// "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 v = x;
for (long count = (long) v; count > 0; count--) {
double v1 = r.nextDouble() * v;
stat.accept(v1);
}
}
return stat;
}
public static void main(String[] args) {
System.out.println(test());
}
}

View File

@@ -1,10 +1,11 @@
// "Replace Stream API chain with loop" "true"
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
public class Main {
public static Map<Integer, List<String>> test(List<String> strings) {
public static Map<Integer, List<String>> testSimple(List<String> strings) {
Map<Integer, List<String>> map = new HashMap<>();
for (String str : strings) {
map.computeIfAbsent(str.length(), k -> new ArrayList<>()).add(str);
@@ -12,8 +13,108 @@ public class Main {
return map;
}
public static Map<Integer, List<String>> testVarConflict(List<String> strings, int k) {
Map<Integer, List<String>> map = new HashMap<>();
for (String string : strings) {
map.computeIfAbsent(string.length(), key -> new ArrayList<>()).add(string);
}
return map;
}
static void testCounting(List<String> list) {
Map<Integer, Long> map = new HashMap<>();
for (String s : list) {
map.merge(s.length(), 1L, Long::sum);
}
System.out.println(map);
}
private static TreeMap<Integer, LinkedHashSet<String>> testCustomMap(List<String> strings) {
TreeMap<Integer, LinkedHashSet<String>> map = new TreeMap<>(Comparator.reverseOrder());
for (String string : strings) {
map.computeIfAbsent(string.length(), k -> new LinkedHashSet<>()).add(string);
}
return map;
}
static void testSummingDouble(List<String> list) {
Map<Integer, Double> map4 = new HashMap<>();
for (String s : list) {
map4.merge(s.length(), (double) s.length(), Double::sum);
}
System.out.println(map4);
}
static void testMappingSummingInt(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);
}
System.out.println(map3);
}
public static void testGroupingGroupingToSet(List<String> strings) {
Map<Integer, Map<Character, Set<String>>> map = new HashMap<>();
for (String s : strings) {
map.computeIfAbsent(s.length(), key -> new HashMap<>()).computeIfAbsent(s.charAt(0), k -> new HashSet<>()).add(s);
}
System.out.println(map);
}
private static TreeMap<Integer, List<Integer>> testMappingToList(List<String> strings) {
TreeMap<Integer, List<Integer>> map = new TreeMap<>(Comparator.reverseOrder());
for (String string : strings) {
Integer len = string.length();
Integer integer = len * 2;
map.computeIfAbsent(string.length(), k -> new ArrayList<>()).add(integer);
}
return map;
}
public static void testSummarizingDouble(List<String> strings) {
Map<Integer, DoubleSummaryStatistics> map = new HashMap<>();
for (String string : strings) {
if (string != null) {
map.computeIfAbsent(string.length(), k -> new DoubleSummaryStatistics()).accept(string.length());
}
}
System.out.println(map);
}
public static void testToMap(List<String> strings) {
Map<Integer, Map<Character, String>> map = new HashMap<>();
for (String s : strings) {
if (map.computeIfAbsent(s.length(), k -> new HashMap<>()).put(s.charAt(0), s) != null) {
throw new IllegalStateException("Duplicate key");
}
}
System.out.println(map);
}
public static void testToSet(List<String> strings) {
Map<Integer, Set<String>> map = new HashMap<>();
for (String string : strings) {
if (string != null) {
map.computeIfAbsent(string.length(), k -> new HashSet<>()).add(string);
}
}
System.out.println(map);
}
public static void main(String[] args) {
System.out.println(test(Arrays.asList()));
System.out.println(test(Arrays.asList("a", "bbb", "cc", "d", "eee")));
System.out.println(testSimple(Arrays.asList()));
System.out.println(testSimple(Arrays.asList("a", "bbb", "cc", "d", "eee")));
System.out.println(testVarConflict(Arrays.asList(), 1));
System.out.println(testVarConflict(Arrays.asList("a", "bbb", "cc", "d", "eee"), 2));
testCounting(Arrays.asList("a", "bbb", "cc", "d", "eee"));
System.out.println(testCustomMap(Arrays.asList("a", "bbb", "cccc", "dddd", "ee", "e")));
testGroupingGroupingToSet(Arrays.asList("a", "bbb", "cccc", "dddd"));
System.out.println(testMappingToList(Arrays.asList("a", "bbb", "cccc", "dddd", "ee", "e")));
testSummingDouble(Arrays.asList("a", "bbb", "cccc", "dddd"));
testMappingSummingInt(Arrays.asList("a", "bbb", "cccc", "dddd"));
testSummarizingDouble(Arrays.asList("a", "bbb", "cccc", "dddd"));
testToMap(Arrays.asList("a", "bbb", "cccc", "dddd"));
testToSet(Arrays.asList("a", "bbb", "cccc", "dddd"));
}
}

View File

@@ -1,19 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Main {
public static Map<Integer, List<String>> test(List<String> strings, int k) {
Map<Integer, List<String>> map = new HashMap<>();
for (String string : strings) {
map.computeIfAbsent(string.length(), key -> new ArrayList<>()).add(string);
}
return map;
}
public static void main(String[] args) {
System.out.println(test(Arrays.asList()));
System.out.println(test(Arrays.asList("a", "bbb", "cc", "d", "eee")));
}
}

View File

@@ -1,15 +0,0 @@
// "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);
}
}
}

View File

@@ -1,18 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Main {
private static TreeMap<Integer, LinkedHashSet<String>> getMap(List<String> strings) {
TreeMap<Integer, LinkedHashSet<String>> map = new TreeMap<>(Comparator.reverseOrder());
for (String string : strings) {
map.computeIfAbsent(string.length(), k -> new LinkedHashSet<>()).add(string);
}
return map;
}
public static void main(String[] args) {
System.out.println(getMap(Arrays.asList("a", "bbb", "cccc", "dddd", "ee", "e")));
}
}

View File

@@ -1,16 +0,0 @@
// "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);
}
}
}

View File

@@ -1,15 +0,0 @@
// "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);
}
}
}

View File

@@ -1,19 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
public class Main {
public static void test(List<String> strings) {
Map<Integer, Map<Character, Set<String>>> map = new HashMap<>();
for (String s : strings) {
map.computeIfAbsent(s.length(), key -> new HashMap<>()).computeIfAbsent(s.charAt(0), k -> new HashSet<>()).add(s);
}
System.out.println(map);
}
public static void main(String[] args) {
test(Arrays.asList("a", "bbb", "cccc", "dddd"));
}
}

View File

@@ -1,20 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Main {
private static TreeMap<Integer, List<Integer>> getMap(List<String> strings) {
TreeMap<Integer, List<Integer>> map = new TreeMap<>(Comparator.reverseOrder());
for (String string : strings) {
Integer len = string.length();
Integer integer = len * 2;
map.computeIfAbsent(string.length(), k -> new ArrayList<>()).add(integer);
}
return map;
}
public static void main(String[] args) {
System.out.println(getMap(Arrays.asList("a", "bbb", "cccc", "dddd", "ee", "e")));
}
}

View File

@@ -1,21 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
public class Main {
public static void test(List<String> strings) {
Map<Integer, DoubleSummaryStatistics> map = new HashMap<>();
for (String string : strings) {
if (string != null) {
map.computeIfAbsent(string.length(), k -> new DoubleSummaryStatistics()).accept(string.length());
}
}
System.out.println(map);
}
public static void main(String[] args) {
test(Arrays.asList("a", "bbb", "cccc", "dddd"));
}
}

View File

@@ -1,21 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
public class Main {
public static void test(List<String> strings) {
Map<Integer, Map<Character, String>> map = new HashMap<>();
for (String s : strings) {
if (map.computeIfAbsent(s.length(), k -> new HashMap<>()).put(s.charAt(0), s) != null) {
throw new IllegalStateException("Duplicate key");
}
}
System.out.println(map);
}
public static void main(String[] args) {
test(Arrays.asList("a", "bbb", "cccc", "dddd"));
}
}

View File

@@ -1,21 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
public class Main {
public static void test(List<String> strings) {
Map<Integer, Set<String>> map = new HashMap<>();
for (String string : strings) {
if (string != null) {
map.computeIfAbsent(string.length(), k -> new HashSet<>()).add(string);
}
}
System.out.println(map);
}
public static void main(String[] args) {
test(Arrays.asList("a", "bbb", "cccc", "dddd"));
}
}

View File

@@ -1,19 +0,0 @@
// "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 str : list) {
if (str.contains("x")) {
System.out.println(str);
break;
}
}
}
public static void main(String[] args) {
test(Arrays.asList("a", "b", "syz"));
}
}

View File

@@ -1,18 +0,0 @@
// "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,/*two*/2,/*three*/3}) {
stat.accept(i);
}
return stat;
}
public static void main(String[] args) {
System.out.println(test());
}
}

View File

@@ -1,18 +0,0 @@
// "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());
}
}

View File

@@ -1,6 +1,10 @@
// "Replace Stream API chain with loop" "true"
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
import java.util.ArrayList;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class Main {
@@ -15,7 +19,63 @@ public class Main {
return stat;
}
public static List<String> testUseName() {
/*limit*/
List<String> list = new ArrayList<>();
long limit = 20;
for (String x = ""; ; x = x /* add "a" */ + "a") {
if (limit-- == 0) break;
list.add(x);
}
return list;
}
public static IntSummaryStatistics testNested() {
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 length = x.length();
stat.accept(length);
}
}
return stat;
}
private static List<String> testNestedUseName() {
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 IntSummaryStatistics testNestedRename() {
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 length = s.length();
stat.accept(length);
}
}
}
return stat;
}
public static void main(String[] args) {
System.out.println(test());
System.out.println(testUseName());
System.out.println(testNested());
System.out.println(testNestedRename());
System.out.println(String.join("|", testNestedUseName()).length());
}
}

View File

@@ -1,23 +0,0 @@
// "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() {
/*limit*/
List<String> list = new ArrayList<>();
long limit = 20;
for (String x = ""; ; x = x /* add "a" */ + "a") {
if (limit-- == 0) break;
list.add(x);
}
return list;
}
public static void main(String[] args) {
System.out.println(test());
}
}

View File

@@ -1,24 +0,0 @@
// "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 length = x.length();
stat.accept(length);
}
}
return stat;
}
public static void main(String[] args) {
System.out.println(test());
}
}

View File

@@ -1,26 +0,0 @@
// "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());
}
}

View File

@@ -1,26 +0,0 @@
// "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 length = s.length();
stat.accept(length);
}
}
}
return stat;
}
public static void main(String[] args) {
System.out.println(test());
}
}

View File

@@ -1,25 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
public class Main {
public static String test(List<String> strings) {
boolean seen = false;
String best = null;
Comparator<String> comparator = Comparator.comparing(String::length);
for (String string : strings) {
if (!seen || comparator.compare(string, best) > 0) {
seen = true;
best = string;
}
}
return seen ? best : null;
}
public static void main(String[] args) {
System.out.println(test(Arrays.asList()));
System.out.println(test(Arrays.asList("a", "bbb", "cc", "d", "eee")));
}
}

View File

@@ -1,23 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
public class Main {
public static OptionalDouble test(List<String> strings) {
boolean seen = false;
double best = 0;
for (String string : strings) {
double length = string.length();
if (!seen || Double.compare(length, best) > 0) {
seen = true;
best = length;
}
}
return seen ? OptionalDouble.of(best) : OptionalDouble.empty();
}
public static void main(String[] args) {
System.out.println(test(Arrays.asList()));
System.out.println(test(Arrays.asList("a", "bbb", "cc", "d")));
}
}

View File

@@ -1,17 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
public class Main {
private static Optional<String> max(Map<String, List<String>> dependencies, String fruits, Map<String, Integer> weights) {
boolean seen = false;
String best = null;
for (String s : dependencies.get(fruits)) {
if (!seen || weights.get(s) - weights.get(best) > 0) {
seen = true;
best = s;
}
}
return seen ? Optional.of(best) : Optional.empty();
}
}

View File

@@ -1,17 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
public class Main {
private static Optional<String> max(Map<String, List<String>> dependencies, String fruits, Map<String, String> weights) {
boolean seen = false;
String best = null;
for (String s : dependencies.get(fruits)) {
if (!seen || (s.compareTo(best) < 0 ? -1 : s.compareTo(best) > 0 ? 1 : 0) > 0) {
seen = true;
best = s;
}
}
return seen ? Optional.of(best) : Optional.empty();
}
}

View File

@@ -1,17 +0,0 @@
// "Replace Stream API chain with loop" "true"
import java.util.*;
public class Main {
private static Optional<String> max(Map<String, List<String>> dependencies, String fruits, Map<String, String> weights) {
boolean seen = false;
String best = null;
for (String s : dependencies.get(fruits)) {
if (!seen || best.compareTo(s) > 0) {
seen = true;
best = s;
}
}
return seen ? Optional.of(best) : Optional.empty();
}
}

View File

@@ -1,24 +0,0 @@
// "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")));
}
}

View File

@@ -1,4 +1,4 @@
// "Replace Stream API chain with loop" "true"
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
import java.util.Arrays;
import java.util.List;
@@ -13,7 +13,22 @@ public class Main {
}
}
private static String getString() {
return "abc";
}
private static boolean testBound(List<String> strings) {
String s = getString();
for (String string : strings) {
if (s.equals(string)) {
return true;
}
}
return false;
}
public static void main(String[] args) {
test(Arrays.asList("a", "b", "xyz"));
System.out.println(testBound(Arrays.asList("a", "b", "c")));
}
}

Some files were not shown because too many files have changed in this diff Show More