mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-09 20:42:52 +07:00
IDEA-170626 Suggest to use Stream.peek instead of Stream.map if the lambda parameter is not reassigned during the operation.
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
// "Replace with 'peek'" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
void test(List<String> list) {
|
||||
// hello
|
||||
/* in return */
|
||||
long count = list.stream()
|
||||
.peek(System.out::println)
|
||||
.count();
|
||||
System.out.println(count);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Replace with 'peek'" "true"
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
void test() {
|
||||
AtomicInteger counter = new AtomicInteger();
|
||||
int[] ints = IntStream.range(0, 100)
|
||||
.filter(x -> x % 3 == 0)
|
||||
.peek((x -> counter.incrementAndGet()))
|
||||
.toArray();
|
||||
System.out.println(counter.get());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// "Replace with 'peek'" "true"
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
void test(List<String> list) {
|
||||
long count = list.stream()
|
||||
.ma<caret>p(e -> {
|
||||
System.out.println(e);
|
||||
// hello
|
||||
return /* in return */ e;
|
||||
})
|
||||
.count();
|
||||
System.out.println(count);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// "Replace with 'peek'" "true"
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
void test() {
|
||||
AtomicInteger counter = new AtomicInteger();
|
||||
int[] ints = IntStream.range(0, 100)
|
||||
.filter(x -> x % 3 == 0)
|
||||
.m<caret>ap((x -> {
|
||||
counter.incrementAndGet();
|
||||
return x;
|
||||
}))
|
||||
.toArray();
|
||||
System.out.println(counter.get());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// "Replace with 'peek'" "false"
|
||||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Main {
|
||||
void test() {
|
||||
int[] ints = IntStream.range(0, 100)
|
||||
.filter(x -> x % 3 == 0)
|
||||
.m<caret>ap(x -> {
|
||||
x++;
|
||||
return x;
|
||||
})
|
||||
.toArray();
|
||||
System.out.println(ints.length);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user