Files
Tagir Valeev 78c8e66901 [java-inspection] Support multi-line single-return lambdas in StreamToLoopInspection
Part of IDEABKL-7718
Fixes IDEA-317735

GitOrigin-RevId: 120245c2b1f4abb464d52c43dd39078a83f4bbcd
2023-04-17 10:53:11 +00:00

66 lines
2.0 KiB
Java

// "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;
import java.util.stream.Stream;
public class Main {
void sample(List<String> people) {
// comment
List<String> list = new ArrayList<>();
for (String person : people) {
list.add(person);
}
List<String> list1 = Collections.unmodifiableList(list);
}
void sample1(List<String> people) {
// comment
List<String> list = new ArrayList<>();
for (String person : people) {
list.add(person);
}
List<String> listIdentity = list;
}
void sample2(List<String> people) {
// comment
Map<Integer, String> result = new HashMap<>();
for (String person : people) {
if (result.put(person.length(), person) != null) {
throw new IllegalStateException("Duplicate key");
}
}
Map<Integer, String> map = Collections.unmodifiableMap(result);
}
void sample3(List<String> people) {
// comment
List<String> strings = new LinkedList<>();
for (String person : people) {
strings.add(person);
}
List<String> result = new ArrayList<>();
for (Iterator<String> it = Stream.concat(strings.stream(), strings.stream()).iterator(); it.hasNext(); ) {
String s = it.next();
result.add(s);
}
List<String> list2 = result;
}
void sample4(List<String> people) {
Map<Integer, List<String>> result = new HashMap<>();
for (String person : people) {
result.computeIfAbsent(person.length(), k -> new ArrayList<>()).add(person);
}
Map<Integer, List<String>> map = Collections.unmodifiableMap(result);
}
void incomplete(List<String> people) {
List<String> list1 = people.stream().collect( // comment
Collectors.collectingAndThen(Collectors.toList()));
}
}