Files
openide/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/streamToLoop/afterCollectingAndThen.java
Tagir Valeev b7688efea7 TerminalOperation: check arguments count for "collectingAndThen" collector.
Fixes EA-127467 - AIOOBE: TerminalOperation.fromCollector
2018-09-17 09:30:59 +07:00

65 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) {
List<String> list2 = people.stream().collect( // comment
Collectors.collectingAndThen(Collectors.<String, List<String>>toCollection(LinkedList::new),
list -> {
List<String> result = new ArrayList<>();
for (Iterator<String> it = Stream.concat(list.stream(), list.stream()).iterator(); it.hasNext(); ) {
String s = it.next();
result.add(s);
}
return 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()));
}
}