本文整理了Java中reactor.util.function.Tuples
类的一些代码示例,展示了Tuples
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tuples
类的具体详情如下:
包路径:reactor.util.function.Tuples
类名称:Tuples
[英]A Tuples is an immutable Collection of objects, each of which can be of an arbitrary type.
[中]
代码示例来源:origin: reactor/reactor-core
Tuple2<Long, T> snapshot(T data){
long now = scheduler.now(TimeUnit.MILLISECONDS);
long last = lastTime;
lastTime = now;
long delta = now - last;
return Tuples.of(delta, data);
}
代码示例来源:origin: reactor/reactor-core
/**
* A converting function from Object array to {@link Tuple3} to R.
*
* @param <T1> The type of the first value.
* @param <T2> The type of the second value.
* @param <T3> The type of the third value.
* @param <R> The type of the return value.
* @param delegate the function to delegate to
*
* @return The unchecked conversion function to R.
*/
public static <T1, T2, T3, R> Function<Object[], R> fn3(final Function<Tuple3<T1, T2, T3>, R> delegate) {
return objects -> delegate.apply(Tuples.<T1, T2, T3>fn3().apply(objects));
}
代码示例来源:origin: reactor/reactor-core
/**
* A converting function from Object array to {@link Tuple4} to R.
*
* @param <T1> The type of the first value.
* @param <T2> The type of the second value.
* @param <T3> The type of the third value.
* @param <T4> The type of the fourth value.
* @param <R> The type of the return value.
* @param delegate the function to delegate to
*
* @return The unchecked conversion function to R.
*/
public static <T1, T2, T3, T4, R> Function<Object[], R> fn4(final Function<Tuple4<T1, T2, T3, T4>, R> delegate) {
return objects -> delegate.apply(Tuples.<T1, T2, T3, T4>fn4().apply(objects));
}
代码示例来源:origin: reactor/reactor-core
@Test
@SuppressWarnings("unchecked")
public void tuple4CreatedFromArray4() {
Integer[] source = new Integer[] { 1, 2, 3, 4 };
Tuple2 expected = Tuples.of(1, 2, 3, 4);
Tuple2 actual = Tuples.fromArray(source);
assertThat(actual)
.isExactlyInstanceOf(Tuple4.class)
.isEqualTo(expected);
}
代码示例来源:origin: reactor/reactor-core
/**
* A converting function from Object array to {@link Tuple4} to R.
*
* @param <T1> The type of the first value.
* @param <T2> The type of the second value.
* @param <T3> The type of the third value.
* @param <T4> The type of the fourth value.
* @param <T5> The type of the fifth value.
* @param <R> The type of the return value.
* @param delegate the function to delegate to
*
* @return The unchecked conversion function to R.
*/
public static <T1, T2, T3, T4, T5, R> Function<Object[], R> fn5(final Function<Tuple5<T1, T2, T3, T4, T5>, R> delegate) {
return objects -> delegate.apply(Tuples.<T1, T2, T3, T4, T5>fn5().apply(objects));
}
代码示例来源:origin: reactor/reactor-core
/**
* A converting function from Object array to {@link Tuple6} to R.
*
* @param <T1> The type of the first value.
* @param <T2> The type of the second value.
* @param <T3> The type of the third value.
* @param <T4> The type of the fourth value.
* @param <T5> The type of the fifth value.
* @param <T6> The type of the sixth value.
* @param <R> The type of the return value.
* @param delegate the function to delegate to
*
* @return The unchecked conversion function to R.
*/
public static <T1, T2, T3, T4, T5, T6, R> Function<Object[], R> fn6(final Function<Tuple6<T1, T2, T3, T4, T5, T6>, R> delegate) {
return objects -> delegate.apply(Tuples.<T1, T2, T3, T4, T5, T6>fn6().apply(objects));
}
代码示例来源:origin: reactor/reactor-core
@Test
@SuppressWarnings("unchecked")
public void tuple6CreatedFromArray6() {
Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6 };
Tuple2 expected = Tuples.of(1, 2, 3, 4, 5, 6);
Tuple2 actual = Tuples.fromArray(source);
assertThat(actual)
.isExactlyInstanceOf(Tuple6.class)
.isEqualTo(expected);
}
代码示例来源:origin: reactor/reactor-core
/**
* Zip five sources together, that is to say wait for all the sources to emit one
* element and combine these elements once into a {@link Tuple5}.
* The operator will continue doing so until any of the sources completes.
* Errors will immediately be forwarded.
* This "Step-Merge" processing is especially useful in Scatter-Gather scenarios.
* <p>
* <img class="marble" src="doc-files/marbles/zipFixedSourcesForFlux.svg" alt="">
*
* @param source1 The first upstream {@link Publisher} to subscribe to.
* @param source2 The second upstream {@link Publisher} to subscribe to.
* @param source3 The third upstream {@link Publisher} to subscribe to.
* @param source4 The fourth upstream {@link Publisher} to subscribe to.
* @param source5 The fifth upstream {@link Publisher} to subscribe to.
* @param <T1> type of the value from source1
* @param <T2> type of the value from source2
* @param <T3> type of the value from source3
* @param <T4> type of the value from source4
* @param <T5> type of the value from source5
*
* @return a zipped {@link Flux}
*/
public static <T1, T2, T3, T4, T5> Flux<Tuple5<T1, T2, T3, T4, T5>> zip(Publisher<? extends T1> source1,
Publisher<? extends T2> source2,
Publisher<? extends T3> source3,
Publisher<? extends T4> source4,
Publisher<? extends T5> source5) {
return zip(Tuples.fn5(), source1, source2, source3, source4, source5);
}
代码示例来源:origin: reactor/reactor-core
Publisher<? extends T5> source5,
Publisher<? extends T6> source6) {
return zip(Tuples.fn6(), source1, source2, source3, source4, source5, source6);
代码示例来源:origin: reactor/reactor-core
OnAssemblyException(Publisher<?> parent, AssemblySnapshot ase, String message) {
super(message);
//skip the "error seen by" if light (no stack)
if (!ase.isLight()) {
chainOrder.add(Tuples.of(parent.hashCode(), Traces.extractOperatorAssemblyInformation(message, true), 0));
}
}
代码示例来源:origin: reactor/reactor-core
@Test
@SuppressWarnings("unchecked")
public void tuple7CreatedFromArray7() {
Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7 };
Tuple2 expected = Tuples.of(1, 2, 3, 4, 5, 6, 7);
Tuple2 actual = Tuples.fromArray(source);
assertThat(actual)
.isExactlyInstanceOf(Tuple7.class)
.isEqualTo(expected);
}
代码示例来源:origin: reactor/reactor-core
/**
* Zip three sources together, that is to say wait for all the sources to emit one
* element and combine these elements once into a {@link Tuple3}.
* The operator will continue doing so until any of the sources completes.
* Errors will immediately be forwarded.
* This "Step-Merge" processing is especially useful in Scatter-Gather scenarios.
* <p>
* <img class="marble" src="doc-files/marbles/zipFixedSourcesForFlux.svg" alt="">
*
* @param source1 The first upstream {@link Publisher} to subscribe to.
* @param source2 The second upstream {@link Publisher} to subscribe to.
* @param source3 The third upstream {@link Publisher} to subscribe to.
* @param <T1> type of the value from source1
* @param <T2> type of the value from source2
* @param <T3> type of the value from source3
*
* @return a zipped {@link Flux}
*/
public static <T1, T2, T3> Flux<Tuple3<T1, T2, T3>> zip(Publisher<? extends T1> source1,
Publisher<? extends T2> source2,
Publisher<? extends T3> source3) {
return zip(Tuples.fn3(), source1, source2, source3);
}
代码示例来源:origin: reactor/reactor-core
/**
* Zip four sources together, that is to say wait for all the sources to emit one
* element and combine these elements once into a {@link Tuple4}.
* The operator will continue doing so until any of the sources completes.
* Errors will immediately be forwarded.
* This "Step-Merge" processing is especially useful in Scatter-Gather scenarios.
* <p>
* <img class="marble" src="doc-files/marbles/zipFixedSourcesForFlux.svg" alt="">
*
* @param source1 The first upstream {@link Publisher} to subscribe to.
* @param source2 The second upstream {@link Publisher} to subscribe to.
* @param source3 The third upstream {@link Publisher} to subscribe to.
* @param source4 The fourth upstream {@link Publisher} to subscribe to.
* @param <T1> type of the value from source1
* @param <T2> type of the value from source2
* @param <T3> type of the value from source3
* @param <T4> type of the value from source4
*
* @return a zipped {@link Flux}
*/
public static <T1, T2, T3, T4> Flux<Tuple4<T1, T2, T3, T4>> zip(Publisher<? extends T1> source1,
Publisher<? extends T2> source2,
Publisher<? extends T3> source3,
Publisher<? extends T4> source4) {
return zip(Tuples.fn4(), source1, source2, source3, source4);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void fn5() {
Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 };
Tuple5<Object, Object, Object, Object, Object> tuple = Tuples.fn5().apply(source);
assertThat(tuple.getT1()).isEqualTo(1);
assertThat(tuple.getT2()).isEqualTo(2);
assertThat(tuple.getT3()).isEqualTo(3);
assertThat(tuple.getT4()).isEqualTo(4);
assertThat(tuple.getT5()).isEqualTo(5);
assertThat(tuple)
.isInstanceOf(Tuple8.class)
.containsExactly(1, 2, 3, 4, 5, 6, 7, 8);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void fn6() {
Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 };
Tuple6<Object, Object, Object, Object, Object, Object> tuple = Tuples.fn6().apply(source);
assertThat(tuple.getT1()).isEqualTo(1);
assertThat(tuple.getT2()).isEqualTo(2);
assertThat(tuple.getT3()).isEqualTo(3);
assertThat(tuple.getT4()).isEqualTo(4);
assertThat(tuple.getT5()).isEqualTo(5);
assertThat(tuple.getT6()).isEqualTo(6);
assertThat(tuple)
.isInstanceOf(Tuple8.class)
.containsExactly(1, 2, 3, 4, 5, 6, 7, 8);
}
代码示例来源:origin: reactor/reactor-core
private void plugHooks() {
Hooks.onErrorDropped(droppedErrors::offer);
Hooks.onNextDropped(droppedElements::offer);
Hooks.onOperatorError((t, d) -> {
operatorErrors.offer(Tuples.of(Optional.ofNullable(t), Optional.ofNullable(d)));
return t;
});
}
代码示例来源:origin: reactor/reactor-core
@Test
@SuppressWarnings("unchecked")
public void tuple2CreatedFromArray2() {
Integer[] source = new Integer[] { 1, 2 };
Tuple2 expected = Tuples.of(1, 2);
Tuple2 actual = Tuples.fromArray(source);
assertThat(actual)
.isExactlyInstanceOf(Tuple2.class)
.isEqualTo(expected);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void fn3() {
Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 };
Tuple3<Object, Object, Object> tuple = Tuples.fn3().apply(source);
assertThat(tuple.getT1()).isEqualTo(1);
assertThat(tuple.getT2()).isEqualTo(2);
assertThat(tuple.getT3()).isEqualTo(3);
assertThat(tuple)
.isInstanceOf(Tuple8.class)
.containsExactly(1, 2, 3, 4, 5, 6, 7, 8);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void fn4() {
Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 };
Tuple4<Object, Object, Object, Object> tuple = Tuples.fn4().apply(source);
assertThat(tuple.getT1()).isEqualTo(1);
assertThat(tuple.getT2()).isEqualTo(2);
assertThat(tuple.getT3()).isEqualTo(3);
assertThat(tuple.getT4()).isEqualTo(4);
assertThat(tuple)
.isInstanceOf(Tuple8.class)
.containsExactly(1, 2, 3, 4, 5, 6, 7, 8);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void fn5Delegate() {
Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 };
Function<Tuple5<Integer, Integer, Integer, Integer, Integer>, Tuple5> invert =
t5 -> new Tuple5<>(t5.getT5(), t5.getT4(), t5.getT3(), t5.getT2(), t5.getT1());
Tuple5 tuple = Tuples.fn5(invert).apply(source);
assertThat(tuple.getT1()).isEqualTo(5);
assertThat(tuple.getT2()).isEqualTo(4);
assertThat(tuple.getT3()).isEqualTo(3);
assertThat(tuple.getT4()).isEqualTo(2);
assertThat(tuple.getT5()).isEqualTo(1);
assertThat((Object) tuple).isExactlyInstanceOf(Tuple5.class);
}
内容来源于网络,如有侵权,请联系作者删除!