mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
StreamToLoop inspection: simplify toMap mergers (a,b)->a (use putIfAbsent) and (a,b)->b (use put)
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
public static TreeMap<Integer, String> test(List<String> strings) {
|
||||
return strings.stream().filter(s -> !s.isEmpty())
|
||||
.col<caret>lect(Collectors.toMap(String::length, String::trim, (s, string) -> string, TreeMap::new));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(test(Arrays.asList()));
|
||||
System.out.println(test(Arrays.asList("a", "bbb", "cc", "d", "eee", "")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user