本文整理了Java中io.reactivex.Observable.filter()
方法的一些代码示例,展示了Observable.filter()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.filter()
方法的具体详情如下:
包路径:io.reactivex.Observable
类名称:Observable
方法名:filter
[英]Filters items emitted by an ObservableSource by only emitting those that satisfy a specified predicate.
Scheduler: filter does not operate by default on a particular Scheduler.
[中]通过仅发送满足指定谓词的项来过滤ObservableSource发出的项。
调度程序:默认情况下,过滤器不会在特定调度程序上运行。
代码示例来源:origin: ReactiveX/RxJava
@Override
public ObservableSource<Object> apply(Observable<Object> o) throws Exception {
return o.filter(Functions.alwaysTrue());
}
});
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testFirstOrElseWithPredicateOfNoneMatchingThePredicate() {
Observable<String> src = Observable.just("a", "b", "c");
src.filter(IS_D).first("default").subscribe(wo);
verify(wo, times(1)).onSuccess(anyString());
verify(wo, times(1)).onSuccess("default");
verify(wo, never()).onError(any(Throwable.class));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testFirstOrElseWithPredicateOfSome() {
Observable<String> src = Observable.just("a", "b", "c", "d", "e", "f");
src.filter(IS_D).first("default").subscribe(wo);
verify(wo, times(1)).onSuccess(anyString());
verify(wo, times(1)).onSuccess("d");
verify(wo, never()).onError(any(Throwable.class));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testTakeFirstWithPredicateOfNoneMatchingThePredicate() {
Observable<Integer> o = Observable.just(1, 3, 5, 7, 9, 7, 5, 3, 1);
o.filter(IS_EVEN).take(1).subscribe(w);
verify(w, never()).onNext(anyInt());
verify(w, times(1)).onComplete();
verify(w, never()).onError(any(Throwable.class));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testFirstOrElseWithPredicateOfSomeObservable() {
Observable<String> src = Observable.just("a", "b", "c", "d", "e", "f");
src.filter(IS_D).first("default").toObservable().subscribe(w);
verify(w, times(1)).onNext(anyString());
verify(w, times(1)).onNext("d");
verify(w, never()).onError(any(Throwable.class));
verify(w, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testFirstOrElseWithPredicateOfNoneMatchingThePredicateObservable() {
Observable<String> src = Observable.just("a", "b", "c");
src.filter(IS_D).first("default").toObservable().subscribe(w);
verify(w, times(1)).onNext(anyString());
verify(w, times(1)).onNext("default");
verify(w, never()).onError(any(Throwable.class));
verify(w, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testFirstWithPredicateOfNoneMatchingThePredicate() {
Observable<Integer> o = Observable.just(1, 3, 5, 7, 9, 7, 5, 3, 1);
o.filter(IS_EVEN).firstElement().subscribe(wm);
verify(wm, never()).onSuccess(anyInt());
verify(wm).onComplete();
verify(wm, never()).onError(any(Throwable.class));
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public Observable<Object> apply(Observable<Object> f) throws Exception {
return f.doFinally(ObservableDoFinallyTest.this).filter(Functions.alwaysTrue());
}
});
代码示例来源:origin: ReactiveX/RxJava
@Test
public void justConditional() {
Observable.just(1)
.doAfterNext(afterNext)
.filter(Functions.alwaysTrue())
.subscribeWith(to)
.assertResult(1);
assertEquals(Arrays.asList(1, -1), values);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void normalJustConditional() {
Observable.just(1)
.doFinally(this)
.filter(Functions.alwaysTrue())
.test()
.assertResult(1);
assertEquals(1, calls);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void asyncFusedRejectedConditional() {
TestObserver<Integer> to0 = ObserverFusion.newTest(QueueFuseable.ASYNC);
Observable.range(1, 5)
.doAfterNext(afterNext)
.filter(Functions.alwaysTrue())
.subscribe(to0);
ObserverFusion.assertFusion(to0, QueueFuseable.NONE)
.assertResult(1, 2, 3, 4, 5);
assertEquals(Arrays.asList(-1, -2, -3, -4, -5), values);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void syncFusedConditional() {
TestObserver<Integer> to0 = ObserverFusion.newTest(QueueFuseable.SYNC);
Observable.range(1, 5)
.doAfterNext(afterNext)
.filter(Functions.alwaysTrue())
.subscribe(to0);
ObserverFusion.assertFusion(to0, QueueFuseable.SYNC)
.assertResult(1, 2, 3, 4, 5);
assertEquals(Arrays.asList(-1, -2, -3, -4, -5), values);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void rangeConditional() {
Observable.range(1, 5)
.doAfterNext(afterNext)
.filter(Functions.alwaysTrue())
.subscribeWith(to)
.assertResult(1, 2, 3, 4, 5);
assertEquals(Arrays.asList(1, -1, 2, -2, 3, -3, 4, -4, 5, -5), values);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void emptyConditional() {
Observable.<Integer>empty()
.doAfterNext(afterNext)
.filter(Functions.alwaysTrue())
.subscribeWith(to)
.assertResult();
assertTrue(values.isEmpty());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void syncFusedBoundaryConditional() {
TestObserver<Integer> to = ObserverFusion.newTest(QueueFuseable.SYNC | QueueFuseable.BOUNDARY);
Observable.range(1, 5)
.doFinally(this)
.filter(Functions.alwaysTrue())
.subscribe(to);
ObserverFusion.assertFusion(to, QueueFuseable.NONE)
.assertResult(1, 2, 3, 4, 5);
assertEquals(1, calls);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void syncFusedConditional() {
TestObserver<Integer> to = ObserverFusion.newTest(QueueFuseable.SYNC);
Observable.range(1, 5)
.doFinally(this)
.filter(Functions.alwaysTrue())
.subscribe(to);
ObserverFusion.assertFusion(to, QueueFuseable.SYNC)
.assertResult(1, 2, 3, 4, 5);
assertEquals(1, calls);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void errorConditional() {
Observable.<Integer>error(new TestException())
.doAfterNext(afterNext)
.filter(Functions.alwaysTrue())
.subscribeWith(to)
.assertFailure(TestException.class);
assertTrue(values.isEmpty());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void normalEmptyConditional() {
Observable.empty()
.doFinally(this)
.filter(Functions.alwaysTrue())
.test()
.assertResult();
assertEquals(1, calls);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void normalTakeConditional() {
Observable.range(1, 10)
.doFinally(this)
.filter(Functions.alwaysTrue())
.take(5)
.test()
.assertResult(1, 2, 3, 4, 5);
assertEquals(1, calls);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void normalErrorConditional() {
Observable.error(new TestException())
.doFinally(this)
.filter(Functions.alwaysTrue())
.test()
.assertFailure(TestException.class);
assertEquals(1, calls);
}
内容来源于网络,如有侵权,请联系作者删除!