本文整理了Java中io.reactivex.Observable.elementAtOrError()
方法的一些代码示例,展示了Observable.elementAtOrError()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.elementAtOrError()
方法的具体详情如下:
包路径:io.reactivex.Observable
类名称:Observable
方法名:elementAtOrError
[英]Returns a Single that emits the item found at a specified index in a sequence of emissions from this Observable or signals a NoSuchElementException if this Observable signals fewer elements than index.
Scheduler: elementAtOrError does not operate by default on a particular Scheduler.
[中]返回一个单一元素,该元素在该可观测元素的一系列发射中的指定索引处发现,或者如果该可观测元素的信号元素少于索引元素,则表示无接触元素异常。
Scheduler:ElementAtoreRor默认情况下不会在特定的计划程序上运行。
代码示例来源:origin: ReactiveX/RxJava
/**
* Returns a Single that emits only the very first item emitted by this Observable or
* signals a {@link NoSuchElementException} if this Observable is empty.
* <p>
* <img width="640" height="434" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/firstOrError.o.png" alt="">
* <dl>
* <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
@SchedulerSupport(SchedulerSupport.NONE)
public final Single<T> firstOrError() {
return elementAtOrError(0L);
}
代码示例来源:origin: redisson/redisson
/**
* Returns a Single that emits only the very first item emitted by this Observable or
* signals a {@link NoSuchElementException} if this Observable is empty.
* <p>
* <img width="640" height="434" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/firstOrError.o.png" alt="">
* <dl>
* <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
@SchedulerSupport(SchedulerSupport.NONE)
public final Single<T> firstOrError() {
return elementAtOrError(0L);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = IndexOutOfBoundsException.class)
public void elementAtOrErrorNegativeIndex() {
Observable.empty()
.elementAtOrError(-1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void elementAtOrErrorOneElement() {
Observable.just(1)
.elementAtOrError(0)
.test()
.assertNoErrors()
.assertValue(1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void elementAtOrErrorInvalidIndex() {
Observable.just(1, 2, 3)
.elementAtOrError(3)
.test()
.assertNoValues()
.assertError(NoSuchElementException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void elementAtOrErrorMultipleElements() {
Observable.just(1, 2, 3)
.elementAtOrError(1)
.test()
.assertNoErrors()
.assertValue(2);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void elementAtOrErrorIndex1OnEmptySource() {
Observable.empty()
.elementAtOrError(1)
.test()
.assertFailure(NoSuchElementException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void elementAtOrErrorError() {
Observable.error(new RuntimeException("error"))
.elementAtOrError(0)
.test()
.assertNoValues()
.assertErrorMessage("error")
.assertError(RuntimeException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void elementAtOrErrorNoElement() {
Observable.empty()
.elementAtOrError(0)
.test()
.assertNoValues()
.assertError(NoSuchElementException.class);
}
内容来源于网络,如有侵权,请联系作者删除!