本文整理汇总了Java中io.reactivex.Observable.filter方法的典型用法代码示例。如果您正苦于以下问题:Java Observable.filter方法的具体用法?Java Observable.filter怎么用?Java Observable.filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.Observable
的用法示例。
在下文中一共展示了Observable.filter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
Observable<String> source = Observable.create(emitter -> {
try {
emitter.onNext("Alpha");
emitter.onNext("Beta");
emitter.onNext("Gamma");
emitter.onNext("Delta");
emitter.onNext("Epsilon");
emitter.onComplete();
} catch (Throwable e) {
emitter.onError(e);
}
});
Observable<Integer> lengths = source.map(String::length);
Observable<Integer> filtered = lengths.filter(i -> i >= 5);
filtered.subscribe(s -> System.out.println("RECEIVED: " +
s));
}
示例2: takeUntilEvent
import io.reactivex.Observable; //导入方法依赖的package包/类
private static <R> Observable<R> takeUntilEvent(final Observable<R> lifecycle, final R event) {
return lifecycle.filter(new Predicate<R>() {
@Override
public boolean test(R lifecycleEvent) throws Exception {
return lifecycleEvent.equals(event);
}
});
}
示例3: render
import io.reactivex.Observable; //导入方法依赖的package包/类
public static Observable<Component> render(final Observable<Event> events) {
Preconditions.checkNotNull(events);
final Observable<Event> fileModifiedEvent = events
.filter(x -> x instanceof WriteFileEvent || x instanceof TouchFileEvent);
final Observable<ImmutableList<Component>> modifiedSummary = fileModifiedEvent.scan(
ImmutableList.of(),
(ImmutableList<Event> list, Event event) -> Streams
.concat(list.stream(), Stream.of(event))
.collect(toImmutableList()))
.map((ImmutableList<Event> modifiedFiles) -> modifiedFiles.isEmpty() ?
ImmutableList.of() :
ImmutableList.of(
Text.of("Files modified (" + modifiedFiles.size() + "): "),
ListLayout.of(
modifiedFiles.stream()
.map(GenericEventRenderer::render)
.collect(toImmutableList()))));
final Observable<ImmutableList<Component>> resolvedDependencies = events
.ofType(ResolvedDependenciesEvent.class)
.map(GenericEventRenderer::render)
.startWith(StackLayout.of())
.map(ImmutableList::of);
final Observable<ImmutableList<Component>> notifications = events
.ofType(Notification.class)
.map(GenericEventRenderer::render)
.scan(ImmutableList.of(), MoreLists::append);
return Observable.combineLatest(
modifiedSummary, resolvedDependencies, notifications, MoreLists::concat)
.map(StackLayout::of)
.cast(Component.class);
}