本文整理了Java中reactor.core.publisher.Flux.elementAt()
方法的一些代码示例,展示了Flux.elementAt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flux.elementAt()
方法的具体详情如下:
包路径:reactor.core.publisher.Flux
类名称:Flux
方法名:elementAt
[英]Emit only the element at the given index position or IndexOutOfBoundsExceptionif the sequence is shorter.
[中]如果序列较短,则仅在给定索引位置或IndexOutofBoundsException处发射元素。
代码示例来源:origin: reactor/reactor-core
@Test
public void fluxCanReturnValueAtCertainIndexOrDefaultValue() {
// "A Flux can return a value at a certain index or a default value"
// given: "a composable with values 1 to 5"
Flux<Integer> s = Flux.just(1, 2, 3, 4, 5);
// when: "element at index 2 is requested"
Integer tap = s.elementAt(2, -1)
.block();
// then: "3 is emitted"
assertThat(tap).isEqualTo(3);
// when: "element with index > number of values is requested"
tap = s.elementAt(10, -1).block();
// then: "-1 is emitted"
assertThat(tap).isEqualTo(-1);
}
代码示例来源:origin: reactor/reactor-core
@Test(expected = IndexOutOfBoundsException.class)
public void indexNegative1() {
Flux.never().elementAt(-1);
}
代码示例来源:origin: reactor/reactor-core
@Test(expected = IndexOutOfBoundsException.class)
public void indexNegative2() {
Flux.never().elementAt(-1, 1);
}
代码示例来源:origin: reactor/reactor-core
@Test(expected = NullPointerException.class)
public void defaultSupplierNull() {
Flux.never().elementAt(1, null);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void fluxCanReturnValueAtCertainIndex() {
// "A Flux can return a value at a certain index"
// given: "a composable with values 1 to 5"
Flux<Integer> s = Flux.just(1, 2, 3, 4, 5);
LongAdder error = new LongAdder();
Consumer<Throwable> errorConsumer = e -> error.increment();
// when: "element at index 2 is requested"
Integer tap = s.elementAt(2)
.block();
// then: "3 is emitted"
assertThat(tap).isEqualTo(3);
// when: "element with negative index is requested"
// then: "error is thrown"
assertThatExceptionOfType(IndexOutOfBoundsException.class)
.isThrownBy(() -> s.elementAt(-1));
// when: "element with index > number of values is requested"
// then: "error is thrown"
assertThatExceptionOfType(IndexOutOfBoundsException.class)
.isThrownBy(() -> s.elementAt(10).doOnError(errorConsumer).block());
assertThat(error.intValue()).isEqualTo(1);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void emptyDefault() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Flux.<Integer>empty().elementAt(0, 20).subscribe(ts);
ts.assertValues(20)
.assertNoError()
.assertComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void nonEmptyDefault() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Flux.range(1, 10).elementAt(20, 20).subscribe(ts);
ts.assertValues(20)
.assertNoError()
.assertComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void empty() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Flux.<Integer>empty().elementAt(0).subscribe(ts);
ts.assertNoValues()
.assertError(IndexOutOfBoundsException.class)
.assertNotComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void normal() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Flux.range(1, 10).elementAt(0).subscribe(ts);
ts.assertValues(1)
.assertNoError()
.assertComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void normal2() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Flux.range(1, 10).elementAt(4).subscribe(ts);
ts.assertValues(5)
.assertNoError()
.assertComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void normal3() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Flux.range(1, 10).elementAt(9).subscribe(ts);
ts.assertValues(10)
.assertNoError()
.assertComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void cancel() {
TestPublisher<String> cancelTester = TestPublisher.create();
MonoProcessor<String> processor = cancelTester.flux()
.elementAt(1000)
.toProcessor();
processor.subscribe();
processor.cancel();
cancelTester.assertCancelled();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void normal3Backpressured() {
AssertSubscriber<Integer> ts = AssertSubscriber.create(0);
Flux.range(1, 10).elementAt(9).subscribe(ts);
ts.assertNoValues()
.assertNoError()
.assertNotComplete();
ts.request(1);
ts.assertValues(10)
.assertNoError()
.assertComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void nonEmptyDefaultBackpressured() {
AssertSubscriber<Integer> ts = AssertSubscriber.create(0);
Flux.range(1, 10).elementAt(20, 20).subscribe(ts);
ts.assertNoValues()
.assertNoError()
.assertNotComplete();
ts.request(1);
ts.assertValues(20)
.assertNoError()
.assertComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void normalBackpressured() {
AssertSubscriber<Integer> ts = AssertSubscriber.create(0);
Flux.range(1, 10).elementAt(0).subscribe(ts);
ts.assertNoValues()
.assertNoError()
.assertNotComplete();
ts.request(1);
ts.assertValues(1)
.assertNoError()
.assertComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void normal5Backpressured() {
AssertSubscriber<Integer> ts = AssertSubscriber.create(0);
Flux.range(1, 10).elementAt(4).subscribe(ts);
ts.assertNoValues()
.assertNoError()
.assertNotComplete();
ts.request(1);
ts.assertValues(5)
.assertNoError()
.assertComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void emptyDefaultBackpressured() {
AssertSubscriber<Integer> ts = AssertSubscriber.create(0);
Flux.<Integer>empty().elementAt(0, 20).subscribe(ts);
ts.assertNoValues()
.assertNoError()
.assertNotComplete();
ts.request(1);
ts.assertValues(20)
.assertNoError()
.assertComplete();
}
代码示例来源:origin: com.aol.cyclops/cyclops-reactor
/**
* @param index
* @return
* @see reactor.core.publisher.Flux#elementAt(int)
*/
public final Mono<T> elementAt(int index) {
return boxed.elementAt(index);
}
/**
代码示例来源:origin: com.aol.cyclops/cyclops-reactor
/**
* @param index
* @param defaultValue
* @return
* @see reactor.core.publisher.Flux#elementAt(int, java.lang.Object)
*/
public final Mono<T> elementAt(int index, T defaultValue) {
return boxed.elementAt(index, defaultValue);
}
/**
代码示例来源:origin: spring-projects/sts4
private int getHoverPosition(String hoverOver, int occurrence) throws Exception {
assertTrue(occurrence>0);
return occurrences(getRawText(), hoverOver)
.elementAt(occurrence-1)
.map(offset -> offset + hoverOver.length()/2)
.block();
}
内容来源于网络,如有侵权,请联系作者删除!