本文整理匯總了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);
}