本文整理了Java中io.reactivex.Flowable.filter()
方法的一些代码示例,展示了Flowable.filter()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flowable.filter()
方法的具体详情如下:
包路径:io.reactivex.Flowable
类名称:Flowable
方法名:filter
[英]Filters items emitted by a Publisher by only emitting those that satisfy a specified predicate.
Backpressure: The operator doesn't interfere with backpressure which is determined by the source Publisher's backpressure behavior. Scheduler: filter does not operate by default on a particular Scheduler.
[中]通过仅发送满足指定谓词的项来过滤发布者发出的项。
背压:操作员不会干扰由源发布者的背压行为确定的背压。调度程序:默认情况下,过滤器不会在特定调度程序上运行。
代码示例来源:origin: ReactiveX/RxJava
@Override
public Publisher<Object> apply(Flowable<Object> f) throws Exception {
return f.doFinally(FlowableDoFinallyTest.this).filter(Functions.alwaysTrue());
}
});
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testTakeFirstWithPredicateOfSome() {
Flowable<Integer> flowable = Flowable.just(1, 3, 5, 4, 6, 3);
flowable.filter(IS_EVEN).take(1).subscribe(w);
verify(w, times(1)).onNext(anyInt());
verify(w).onNext(4);
verify(w, times(1)).onComplete();
verify(w, never()).onError(any(Throwable.class));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testFirstOrElseWithPredicateOfSomeFlowable() {
Flowable<String> src = Flowable.just("a", "b", "c", "d", "e", "f");
src.filter(IS_D).first("default").toFlowable().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 testFirstWithPredicateOfNoneMatchingThePredicate() {
Flowable<Integer> flowable = Flowable.just(1, 3, 5, 7, 9, 7, 5, 3, 1);
flowable.filter(IS_EVEN).firstElement().subscribe(wm);
verify(wm, never()).onSuccess(anyInt());
verify(wm, times(1)).onComplete();
verify(wm, never()).onError(isA(NoSuchElementException.class));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void nullConditional() {
Flowable.fromIterable(Arrays.asList(1, null, 3, 4, 5))
.filter(Functions.alwaysTrue())
.test()
.assertFailure(NullPointerException.class, 1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void conditionalOneIsNullSlowPath() {
Flowable.fromArray(new Integer[] { null, 1 })
.filter(Functions.alwaysTrue())
.test(2L)
.assertFailure(NullPointerException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void emptyConditional() {
Flowable.<Integer>empty()
.doAfterNext(afterNext)
.filter(Functions.alwaysTrue())
.subscribeWith(ts)
.assertResult();
assertTrue(values.isEmpty());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void rangeConditional() {
Flowable.range(1, 5)
.doAfterNext(afterNext)
.filter(Functions.alwaysTrue())
.subscribeWith(ts)
.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 syncNoneFused2() {
TestSubscriber<Integer> ts = SubscriberFusion.newTest(QueueFuseable.ANY);
Flowable.range(1, 5)
.filter(Functions.alwaysFalse())
.filter(Functions.alwaysFalse())
.subscribe(ts);
ts.assertOf(SubscriberFusion.<Integer>assertFuseable())
.assertOf(SubscriberFusion.<Integer>assertFusionMode(QueueFuseable.SYNC))
.assertResult();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void conditionalOneByOne() {
Flowable.fromArray(new Integer[] { 1, 2, 3, 4, 5 })
.filter(Functions.alwaysTrue())
.rebatchRequests(1)
.test()
.assertResult(1, 2, 3, 4, 5);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void slowPathTakeExact() {
Flowable.range(1, 5)
.filter(Functions.alwaysTrue())
.take(5)
.test()
.assertResult(1, 2, 3, 4, 5);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void conditionalSlowPathRebatch() {
Flowable.rangeLong(1L, 5L)
.filter(Functions.alwaysTrue())
.rebatchRequests(1)
.test()
.assertResult(1L, 2L, 3L, 4L, 5L);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void asyncFusedRejectedConditional() {
TestSubscriber<Integer> ts0 = SubscriberFusion.newTest(QueueFuseable.ASYNC);
Flowable.range(1, 5)
.doAfterNext(afterNext)
.filter(Functions.alwaysTrue())
.subscribe(ts0);
SubscriberFusion.assertFusion(ts0, QueueFuseable.NONE)
.assertResult(1, 2, 3, 4, 5);
assertEquals(Arrays.asList(-1, -2, -3, -4, -5), values);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void request1Conditional() {
Flowable.range(1, 10).hide()
.observeOn(ImmediateThinScheduler.INSTANCE)
.filter(Functions.alwaysTrue())
.test(1L)
.assertValue(1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void normalEmptyConditional() {
Flowable.empty()
.doFinally(this)
.filter(Functions.alwaysTrue())
.test()
.assertResult();
assertEquals(1, calls);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void workerNotDisposedPrematurelyNormalInNormalOutConditional() {
DisposeTrackingScheduler s = new DisposeTrackingScheduler();
Flowable.concat(
Flowable.just(1).hide().observeOn(s).filter(Functions.alwaysTrue()),
Flowable.just(2)
)
.test()
.assertResult(1, 2);
assertEquals(1, s.disposedCount.get());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void normalTakeConditional() {
Flowable.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 backFusedErrorConditional() {
TestSubscriber<Integer> ts = SubscriberFusion.newTest(QueueFuseable.ANY);
Flowable.<Integer>error(new TestException())
.observeOn(ImmediateThinScheduler.INSTANCE)
.filter(Functions.alwaysTrue())
.subscribe(ts);
SubscriberFusion.assertFusion(ts, QueueFuseable.ASYNC)
.assertFailure(TestException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void syncFusedBoundaryConditional() {
TestSubscriber<Integer> ts = SubscriberFusion.newTest(QueueFuseable.SYNC | QueueFuseable.BOUNDARY);
Flowable.range(1, 5)
.doFinally(this)
.filter(Functions.alwaysTrue())
.subscribe(ts);
SubscriberFusion.assertFusion(ts, QueueFuseable.NONE)
.assertResult(1, 2, 3, 4, 5);
assertEquals(1, calls);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void backFusedConditional() {
TestSubscriber<Integer> ts = SubscriberFusion.newTest(QueueFuseable.ANY);
Flowable.range(1, 100).hide()
.observeOn(ImmediateThinScheduler.INSTANCE)
.filter(Functions.alwaysTrue())
.subscribe(ts);
SubscriberFusion.assertFusion(ts, QueueFuseable.ASYNC)
.assertValueCount(100)
.assertComplete()
.assertNoErrors();
}
内容来源于网络,如有侵权,请联系作者删除!