io.reactivex.Flowable.elementAtOrError()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(4.3k)|赞(0)|评价(0)|浏览(178)

本文整理了Java中io.reactivex.Flowable.elementAtOrError()方法的一些代码示例,展示了Flowable.elementAtOrError()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flowable.elementAtOrError()方法的具体详情如下:
包路径:io.reactivex.Flowable
类名称:Flowable
方法名:elementAtOrError

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

  1. /**
  2. * Returns a Single that emits only the very first item emitted by this Flowable or
  3. * signals a {@link NoSuchElementException} if this Flowable is empty.
  4. * <p>
  5. * <img width="640" height="237" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/firstOrError.png" alt="">
  6. * <dl>
  7. * <dt><b>Backpressure:</b></dt>
  8. * <dd>The operator honors backpressure from downstream and consumes the source {@code Publisher} in an
  9. * unbounded manner (i.e., without applying backpressure).</dd>
  10. * <dt><b>Scheduler:</b></dt>
  11. * <dd>{@code firstOrError} does not operate by default on a particular {@link Scheduler}.</dd>
  12. * </dl>
  13. *
  14. * @return the new Single instance
  15. * @see <a href="http://reactivex.io/documentation/operators/first.html">ReactiveX operators documentation: First</a>
  16. */
  17. @CheckReturnValue
  18. @BackpressureSupport(BackpressureKind.SPECIAL) // take may trigger UNBOUNDED_IN
  19. @SchedulerSupport(SchedulerSupport.NONE)
  20. public final Single<T> firstOrError() {
  21. return elementAtOrError(0);
  22. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test(expected = IndexOutOfBoundsException.class)
  2. public void elementAtOrErrorNegativeIndex() {
  3. Flowable.empty()
  4. .elementAtOrError(-1);
  5. }

代码示例来源:origin: redisson/redisson

  1. /**
  2. * Returns a Single that emits only the very first item emitted by this Flowable or
  3. * signals a {@link NoSuchElementException} if this Flowable is empty.
  4. * <p>
  5. * <img width="640" height="237" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/firstOrError.png" alt="">
  6. * <dl>
  7. * <dt><b>Backpressure:</b></dt>
  8. * <dd>The operator honors backpressure from downstream and consumes the source {@code Publisher} in an
  9. * unbounded manner (i.e., without applying backpressure).</dd>
  10. * <dt><b>Scheduler:</b></dt>
  11. * <dd>{@code firstOrError} does not operate by default on a particular {@link Scheduler}.</dd>
  12. * </dl>
  13. *
  14. * @return the new Single instance
  15. * @see <a href="http://reactivex.io/documentation/operators/first.html">ReactiveX operators documentation: First</a>
  16. */
  17. @CheckReturnValue
  18. @BackpressureSupport(BackpressureKind.SPECIAL) // take may trigger UNBOUNDED_IN
  19. @SchedulerSupport(SchedulerSupport.NONE)
  20. public final Single<T> firstOrError() {
  21. return elementAtOrError(0);
  22. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void elementAtOrErrorIndex1OnEmptySource() {
  3. Flowable.empty()
  4. .elementAtOrError(1)
  5. .test()
  6. .assertFailure(NoSuchElementException.class);
  7. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void elementAtOrErrorError() {
  3. Flowable.error(new RuntimeException("error"))
  4. .elementAtOrError(0)
  5. .test()
  6. .assertNoValues()
  7. .assertErrorMessage("error")
  8. .assertError(RuntimeException.class);
  9. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void elementAtOrErrorOneElement() {
  3. Flowable.just(1)
  4. .elementAtOrError(0)
  5. .test()
  6. .assertNoErrors()
  7. .assertValue(1);
  8. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void elementAtOrErrorNoElement() {
  3. Flowable.empty()
  4. .elementAtOrError(0)
  5. .test()
  6. .assertNoValues()
  7. .assertError(NoSuchElementException.class);
  8. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void elementAtOrErrorMultipleElements() {
  3. Flowable.just(1, 2, 3)
  4. .elementAtOrError(1)
  5. .test()
  6. .assertNoErrors()
  7. .assertValue(2);
  8. }

代码示例来源:origin: ReactiveX/RxJava

  1. @Test
  2. public void elementAtOrErrorInvalidIndex() {
  3. Flowable.just(1, 2, 3)
  4. .elementAtOrError(3)
  5. .test()
  6. .assertNoValues()
  7. .assertError(NoSuchElementException.class);
  8. }

相关文章

Flowable类方法