当前位置: 首页>>代码示例>>Java>>正文


Java Observable.filter方法代码示例

本文整理汇总了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));
}
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:19,代码来源:Ch2_3.java

示例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);
        }
    });
}
 
开发者ID:xufreshman,项目名称:RxLifeCycle,代码行数:9,代码来源:RxLifecycle.java

示例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);
    }
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:39,代码来源:SummaryView.java


注:本文中的io.reactivex.Observable.filter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。