本文整理了Java中io.reactivex.Flowable.elementAtOrError()
方法的一些代码示例,展示了Flowable.elementAtOrError()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flowable.elementAtOrError()
方法的具体详情如下:
包路径:io.reactivex.Flowable
类名称:Flowable
方法名:elementAtOrError
[英]Returns a Flowable that emits the item found at a specified index in a sequence of emissions from this Flowable or signals a NoSuchElementException if this Flowable has fewer elements than index.
Backpressure: The operator honors backpressure from downstream and consumes the source Publisher in an unbounded manner (i.e., no backpressure applied to it). Scheduler: elementAtOrError does not operate by default on a particular Scheduler.
[中]返回一个FlowTable,该FlowTable在该FlowTable的一系列发射中发射在指定索引处找到的项,或者如果该FlowTable的元素少于索引,则发出NosTouchElementException信号。
背压:操作员接受来自下游的背压,并以无限制的方式使用源发布服务器(即,不向其施加背压)。Scheduler:ElementAtoreRor默认情况下不会在特定的计划程序上运行。
代码示例来源:origin: ReactiveX/RxJava
/**
* Returns a Single that emits only the very first item emitted by this Flowable or
* signals a {@link NoSuchElementException} if this Flowable is empty.
* <p>
* <img width="640" height="237" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/firstOrError.png" alt="">
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The operator honors backpressure from downstream and consumes the source {@code Publisher} in an
* unbounded manner (i.e., without applying backpressure).</dd>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code firstOrError} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @return the new Single instance
* @see <a href="http://reactivex.io/documentation/operators/first.html">ReactiveX operators documentation: First</a>
*/
@CheckReturnValue
@BackpressureSupport(BackpressureKind.SPECIAL) // take may trigger UNBOUNDED_IN
@SchedulerSupport(SchedulerSupport.NONE)
public final Single<T> firstOrError() {
return elementAtOrError(0);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = IndexOutOfBoundsException.class)
public void elementAtOrErrorNegativeIndex() {
Flowable.empty()
.elementAtOrError(-1);
}
代码示例来源:origin: redisson/redisson
/**
* Returns a Single that emits only the very first item emitted by this Flowable or
* signals a {@link NoSuchElementException} if this Flowable is empty.
* <p>
* <img width="640" height="237" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/firstOrError.png" alt="">
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The operator honors backpressure from downstream and consumes the source {@code Publisher} in an
* unbounded manner (i.e., without applying backpressure).</dd>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code firstOrError} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @return the new Single instance
* @see <a href="http://reactivex.io/documentation/operators/first.html">ReactiveX operators documentation: First</a>
*/
@CheckReturnValue
@BackpressureSupport(BackpressureKind.SPECIAL) // take may trigger UNBOUNDED_IN
@SchedulerSupport(SchedulerSupport.NONE)
public final Single<T> firstOrError() {
return elementAtOrError(0);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void elementAtOrErrorIndex1OnEmptySource() {
Flowable.empty()
.elementAtOrError(1)
.test()
.assertFailure(NoSuchElementException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void elementAtOrErrorError() {
Flowable.error(new RuntimeException("error"))
.elementAtOrError(0)
.test()
.assertNoValues()
.assertErrorMessage("error")
.assertError(RuntimeException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void elementAtOrErrorOneElement() {
Flowable.just(1)
.elementAtOrError(0)
.test()
.assertNoErrors()
.assertValue(1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void elementAtOrErrorNoElement() {
Flowable.empty()
.elementAtOrError(0)
.test()
.assertNoValues()
.assertError(NoSuchElementException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void elementAtOrErrorMultipleElements() {
Flowable.just(1, 2, 3)
.elementAtOrError(1)
.test()
.assertNoErrors()
.assertValue(2);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void elementAtOrErrorInvalidIndex() {
Flowable.just(1, 2, 3)
.elementAtOrError(3)
.test()
.assertNoValues()
.assertError(NoSuchElementException.class);
}
内容来源于网络,如有侵权,请联系作者删除!