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,7 @@
// "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 {
@@ -14,7 +15,43 @@ public class Main {
return mapping;
}
public static Map<Integer, String> testMerge(List<String> strings) {
Map<Integer, String> map = new HashMap<>();
for (String s : strings) {
if (!s.isEmpty()) {
map.merge(s.length(), s, String::concat);
}
}
return map;
}
public static TreeMap<Integer, String> testPut(List<String> strings) {
TreeMap<Integer, String> map = new TreeMap<>();
for (String s1 : strings) {
if (!s1.isEmpty()) {
map.put(s1.length(), s1.trim());
}
}
return map;
}
public static TreeMap<Integer, String> testSupplier(List<String> strings) {
TreeMap<Integer, String> map = new TreeMap<>();
for (String s1 : strings) {
if (!s1.isEmpty()) {
map.putIfAbsent(s1.length(), s1);
}
}
return map;
}
public static void main(String[] args) {
System.out.println(testMerge(Arrays.asList()));
System.out.println(testMerge(Arrays.asList("a", "bbb", "cc", "d", "eee", "")));
System.out.println(testPut(Arrays.asList()));
System.out.println(testPut(Arrays.asList("a", "bbb", "cc", "d", "eee", "")));
System.out.println(testSupplier(Arrays.asList()));
System.out.println(testSupplier(Arrays.asList("a", "bbb", "cc", "d", "eee", "")));
System.out.println(test(Arrays.asList()));
System.out.println(test(Arrays.asList("a", "bbb", "cc", "d", "eee", "")));
}