當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。