mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-06-13 20:37:16 +07:00
StreamToLoopInspection: allow custom sources when option is set
This commit is contained in:
+24
@@ -0,0 +1,24 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
Stream<String> names() {
|
||||
return Stream.of("foo", "bar");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (Iterator<String> it = new Test().names().iterator(); it.hasNext(); ) {
|
||||
String name = it.next();
|
||||
String n = name.trim();
|
||||
if (!n.isEmpty()) {
|
||||
list.add(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.PrimitiveIterator;
|
||||
import java.util.Random;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Test {
|
||||
static void test() {
|
||||
for (int n = 1; n < 100; n++) {
|
||||
if (n > 20) {
|
||||
Integer integer = n;
|
||||
for (PrimitiveIterator.OfDouble it = new Random(integer).doubles(integer).iterator(); it.hasNext(); ) {
|
||||
double v = it.next();
|
||||
if (v < 0.01) {
|
||||
System.out.println(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
test();
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
Stream<String> names() {
|
||||
return Stream.of("foo", "bar");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<String> list = new Test().names().map(String::trim).filter(n -> !n.isEmpty())
|
||||
.<caret>collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class Test {
|
||||
static void test() {
|
||||
IntStream.range(1, 100)
|
||||
.filter(n -> n > 20)
|
||||
.boxed()
|
||||
.flatMapToDouble(n -> new Random(n).doubles(n))
|
||||
.filter(n -> n < 0.01)
|
||||
.fo<caret>rEach(System.out::println);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
test();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user