mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-26 08:21:26 +07:00
StreamToLoopInspection: support some simple StreamEx scenarios; support Java 9 takeWhile/dropWhile
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Test {
|
||||
// Mock Java 9 methods with inheritor
|
||||
interface MyStream<T> extends Stream<T> {
|
||||
<R> MyStream<R> flatMap(Function<? super T, ? extends Stream<? extends R>> mapper);
|
||||
|
||||
MyStream<T> takeWhile(Predicate<? super T> predicate);
|
||||
|
||||
MyStream<T> dropWhile(Predicate<? super T> predicate);
|
||||
|
||||
static <T> MyStream<T> of(List<T> list) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void test(List<String> data) {
|
||||
List<String> xyz = MyStream.of(data)
|
||||
.flatMap(s -> Stream.of(s, s + s)).takeWhile(s -> !s.isEmpty())
|
||||
.dropWhile(s -> s.length() < 3).col<caret>lect(Collectors.toList());
|
||||
System.out.println(xyz);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user