reactor.util.function.Tuples类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(699)

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

Tuples介绍

[英]A Tuples is an immutable Collection of objects, each of which can be of an arbitrary type.
[中]

代码示例

代码示例来源:origin: reactor/reactor-core

  1. Tuple2<Long, T> snapshot(T data){
  2. long now = scheduler.now(TimeUnit.MILLISECONDS);
  3. long last = lastTime;
  4. lastTime = now;
  5. long delta = now - last;
  6. return Tuples.of(delta, data);
  7. }

代码示例来源:origin: reactor/reactor-core

  1. /**
  2. * A converting function from Object array to {@link Tuple3} to R.
  3. *
  4. * @param <T1> The type of the first value.
  5. * @param <T2> The type of the second value.
  6. * @param <T3> The type of the third value.
  7. * @param <R> The type of the return value.
  8. * @param delegate the function to delegate to
  9. *
  10. * @return The unchecked conversion function to R.
  11. */
  12. public static <T1, T2, T3, R> Function<Object[], R> fn3(final Function<Tuple3<T1, T2, T3>, R> delegate) {
  13. return objects -> delegate.apply(Tuples.<T1, T2, T3>fn3().apply(objects));
  14. }

代码示例来源:origin: reactor/reactor-core

  1. /**
  2. * A converting function from Object array to {@link Tuple4} to R.
  3. *
  4. * @param <T1> The type of the first value.
  5. * @param <T2> The type of the second value.
  6. * @param <T3> The type of the third value.
  7. * @param <T4> The type of the fourth value.
  8. * @param <R> The type of the return value.
  9. * @param delegate the function to delegate to
  10. *
  11. * @return The unchecked conversion function to R.
  12. */
  13. public static <T1, T2, T3, T4, R> Function<Object[], R> fn4(final Function<Tuple4<T1, T2, T3, T4>, R> delegate) {
  14. return objects -> delegate.apply(Tuples.<T1, T2, T3, T4>fn4().apply(objects));
  15. }

代码示例来源:origin: reactor/reactor-core

  1. @Test
  2. @SuppressWarnings("unchecked")
  3. public void tuple4CreatedFromArray4() {
  4. Integer[] source = new Integer[] { 1, 2, 3, 4 };
  5. Tuple2 expected = Tuples.of(1, 2, 3, 4);
  6. Tuple2 actual = Tuples.fromArray(source);
  7. assertThat(actual)
  8. .isExactlyInstanceOf(Tuple4.class)
  9. .isEqualTo(expected);
  10. }

代码示例来源:origin: reactor/reactor-core

  1. /**
  2. * A converting function from Object array to {@link Tuple4} to R.
  3. *
  4. * @param <T1> The type of the first value.
  5. * @param <T2> The type of the second value.
  6. * @param <T3> The type of the third value.
  7. * @param <T4> The type of the fourth value.
  8. * @param <T5> The type of the fifth value.
  9. * @param <R> The type of the return value.
  10. * @param delegate the function to delegate to
  11. *
  12. * @return The unchecked conversion function to R.
  13. */
  14. public static <T1, T2, T3, T4, T5, R> Function<Object[], R> fn5(final Function<Tuple5<T1, T2, T3, T4, T5>, R> delegate) {
  15. return objects -> delegate.apply(Tuples.<T1, T2, T3, T4, T5>fn5().apply(objects));
  16. }

代码示例来源:origin: reactor/reactor-core

  1. /**
  2. * A converting function from Object array to {@link Tuple6} to R.
  3. *
  4. * @param <T1> The type of the first value.
  5. * @param <T2> The type of the second value.
  6. * @param <T3> The type of the third value.
  7. * @param <T4> The type of the fourth value.
  8. * @param <T5> The type of the fifth value.
  9. * @param <T6> The type of the sixth value.
  10. * @param <R> The type of the return value.
  11. * @param delegate the function to delegate to
  12. *
  13. * @return The unchecked conversion function to R.
  14. */
  15. public static <T1, T2, T3, T4, T5, T6, R> Function<Object[], R> fn6(final Function<Tuple6<T1, T2, T3, T4, T5, T6>, R> delegate) {
  16. return objects -> delegate.apply(Tuples.<T1, T2, T3, T4, T5, T6>fn6().apply(objects));
  17. }

代码示例来源:origin: reactor/reactor-core

  1. @Test
  2. @SuppressWarnings("unchecked")
  3. public void tuple6CreatedFromArray6() {
  4. Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6 };
  5. Tuple2 expected = Tuples.of(1, 2, 3, 4, 5, 6);
  6. Tuple2 actual = Tuples.fromArray(source);
  7. assertThat(actual)
  8. .isExactlyInstanceOf(Tuple6.class)
  9. .isEqualTo(expected);
  10. }

代码示例来源:origin: reactor/reactor-core

  1. /**
  2. * Zip five sources together, that is to say wait for all the sources to emit one
  3. * element and combine these elements once into a {@link Tuple5}.
  4. * The operator will continue doing so until any of the sources completes.
  5. * Errors will immediately be forwarded.
  6. * This "Step-Merge" processing is especially useful in Scatter-Gather scenarios.
  7. * <p>
  8. * <img class="marble" src="doc-files/marbles/zipFixedSourcesForFlux.svg" alt="">
  9. *
  10. * @param source1 The first upstream {@link Publisher} to subscribe to.
  11. * @param source2 The second upstream {@link Publisher} to subscribe to.
  12. * @param source3 The third upstream {@link Publisher} to subscribe to.
  13. * @param source4 The fourth upstream {@link Publisher} to subscribe to.
  14. * @param source5 The fifth upstream {@link Publisher} to subscribe to.
  15. * @param <T1> type of the value from source1
  16. * @param <T2> type of the value from source2
  17. * @param <T3> type of the value from source3
  18. * @param <T4> type of the value from source4
  19. * @param <T5> type of the value from source5
  20. *
  21. * @return a zipped {@link Flux}
  22. */
  23. public static <T1, T2, T3, T4, T5> Flux<Tuple5<T1, T2, T3, T4, T5>> zip(Publisher<? extends T1> source1,
  24. Publisher<? extends T2> source2,
  25. Publisher<? extends T3> source3,
  26. Publisher<? extends T4> source4,
  27. Publisher<? extends T5> source5) {
  28. return zip(Tuples.fn5(), source1, source2, source3, source4, source5);
  29. }

代码示例来源:origin: reactor/reactor-core

  1. Publisher<? extends T5> source5,
  2. Publisher<? extends T6> source6) {
  3. return zip(Tuples.fn6(), source1, source2, source3, source4, source5, source6);

代码示例来源:origin: reactor/reactor-core

  1. OnAssemblyException(Publisher<?> parent, AssemblySnapshot ase, String message) {
  2. super(message);
  3. //skip the "error seen by" if light (no stack)
  4. if (!ase.isLight()) {
  5. chainOrder.add(Tuples.of(parent.hashCode(), Traces.extractOperatorAssemblyInformation(message, true), 0));
  6. }
  7. }

代码示例来源:origin: reactor/reactor-core

  1. @Test
  2. @SuppressWarnings("unchecked")
  3. public void tuple7CreatedFromArray7() {
  4. Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7 };
  5. Tuple2 expected = Tuples.of(1, 2, 3, 4, 5, 6, 7);
  6. Tuple2 actual = Tuples.fromArray(source);
  7. assertThat(actual)
  8. .isExactlyInstanceOf(Tuple7.class)
  9. .isEqualTo(expected);
  10. }

代码示例来源:origin: reactor/reactor-core

  1. /**
  2. * Zip three sources together, that is to say wait for all the sources to emit one
  3. * element and combine these elements once into a {@link Tuple3}.
  4. * The operator will continue doing so until any of the sources completes.
  5. * Errors will immediately be forwarded.
  6. * This "Step-Merge" processing is especially useful in Scatter-Gather scenarios.
  7. * <p>
  8. * <img class="marble" src="doc-files/marbles/zipFixedSourcesForFlux.svg" alt="">
  9. *
  10. * @param source1 The first upstream {@link Publisher} to subscribe to.
  11. * @param source2 The second upstream {@link Publisher} to subscribe to.
  12. * @param source3 The third upstream {@link Publisher} to subscribe to.
  13. * @param <T1> type of the value from source1
  14. * @param <T2> type of the value from source2
  15. * @param <T3> type of the value from source3
  16. *
  17. * @return a zipped {@link Flux}
  18. */
  19. public static <T1, T2, T3> Flux<Tuple3<T1, T2, T3>> zip(Publisher<? extends T1> source1,
  20. Publisher<? extends T2> source2,
  21. Publisher<? extends T3> source3) {
  22. return zip(Tuples.fn3(), source1, source2, source3);
  23. }

代码示例来源:origin: reactor/reactor-core

  1. /**
  2. * Zip four sources together, that is to say wait for all the sources to emit one
  3. * element and combine these elements once into a {@link Tuple4}.
  4. * The operator will continue doing so until any of the sources completes.
  5. * Errors will immediately be forwarded.
  6. * This "Step-Merge" processing is especially useful in Scatter-Gather scenarios.
  7. * <p>
  8. * <img class="marble" src="doc-files/marbles/zipFixedSourcesForFlux.svg" alt="">
  9. *
  10. * @param source1 The first upstream {@link Publisher} to subscribe to.
  11. * @param source2 The second upstream {@link Publisher} to subscribe to.
  12. * @param source3 The third upstream {@link Publisher} to subscribe to.
  13. * @param source4 The fourth upstream {@link Publisher} to subscribe to.
  14. * @param <T1> type of the value from source1
  15. * @param <T2> type of the value from source2
  16. * @param <T3> type of the value from source3
  17. * @param <T4> type of the value from source4
  18. *
  19. * @return a zipped {@link Flux}
  20. */
  21. public static <T1, T2, T3, T4> Flux<Tuple4<T1, T2, T3, T4>> zip(Publisher<? extends T1> source1,
  22. Publisher<? extends T2> source2,
  23. Publisher<? extends T3> source3,
  24. Publisher<? extends T4> source4) {
  25. return zip(Tuples.fn4(), source1, source2, source3, source4);
  26. }

代码示例来源:origin: reactor/reactor-core

  1. @Test
  2. public void fn5() {
  3. Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 };
  4. Tuple5<Object, Object, Object, Object, Object> tuple = Tuples.fn5().apply(source);
  5. assertThat(tuple.getT1()).isEqualTo(1);
  6. assertThat(tuple.getT2()).isEqualTo(2);
  7. assertThat(tuple.getT3()).isEqualTo(3);
  8. assertThat(tuple.getT4()).isEqualTo(4);
  9. assertThat(tuple.getT5()).isEqualTo(5);
  10. assertThat(tuple)
  11. .isInstanceOf(Tuple8.class)
  12. .containsExactly(1, 2, 3, 4, 5, 6, 7, 8);
  13. }

代码示例来源:origin: reactor/reactor-core

  1. @Test
  2. public void fn6() {
  3. Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 };
  4. Tuple6<Object, Object, Object, Object, Object, Object> tuple = Tuples.fn6().apply(source);
  5. assertThat(tuple.getT1()).isEqualTo(1);
  6. assertThat(tuple.getT2()).isEqualTo(2);
  7. assertThat(tuple.getT3()).isEqualTo(3);
  8. assertThat(tuple.getT4()).isEqualTo(4);
  9. assertThat(tuple.getT5()).isEqualTo(5);
  10. assertThat(tuple.getT6()).isEqualTo(6);
  11. assertThat(tuple)
  12. .isInstanceOf(Tuple8.class)
  13. .containsExactly(1, 2, 3, 4, 5, 6, 7, 8);
  14. }

代码示例来源:origin: reactor/reactor-core

  1. private void plugHooks() {
  2. Hooks.onErrorDropped(droppedErrors::offer);
  3. Hooks.onNextDropped(droppedElements::offer);
  4. Hooks.onOperatorError((t, d) -> {
  5. operatorErrors.offer(Tuples.of(Optional.ofNullable(t), Optional.ofNullable(d)));
  6. return t;
  7. });
  8. }

代码示例来源:origin: reactor/reactor-core

  1. @Test
  2. @SuppressWarnings("unchecked")
  3. public void tuple2CreatedFromArray2() {
  4. Integer[] source = new Integer[] { 1, 2 };
  5. Tuple2 expected = Tuples.of(1, 2);
  6. Tuple2 actual = Tuples.fromArray(source);
  7. assertThat(actual)
  8. .isExactlyInstanceOf(Tuple2.class)
  9. .isEqualTo(expected);
  10. }

代码示例来源:origin: reactor/reactor-core

  1. @Test
  2. public void fn3() {
  3. Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 };
  4. Tuple3<Object, Object, Object> tuple = Tuples.fn3().apply(source);
  5. assertThat(tuple.getT1()).isEqualTo(1);
  6. assertThat(tuple.getT2()).isEqualTo(2);
  7. assertThat(tuple.getT3()).isEqualTo(3);
  8. assertThat(tuple)
  9. .isInstanceOf(Tuple8.class)
  10. .containsExactly(1, 2, 3, 4, 5, 6, 7, 8);
  11. }

代码示例来源:origin: reactor/reactor-core

  1. @Test
  2. public void fn4() {
  3. Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 };
  4. Tuple4<Object, Object, Object, Object> tuple = Tuples.fn4().apply(source);
  5. assertThat(tuple.getT1()).isEqualTo(1);
  6. assertThat(tuple.getT2()).isEqualTo(2);
  7. assertThat(tuple.getT3()).isEqualTo(3);
  8. assertThat(tuple.getT4()).isEqualTo(4);
  9. assertThat(tuple)
  10. .isInstanceOf(Tuple8.class)
  11. .containsExactly(1, 2, 3, 4, 5, 6, 7, 8);
  12. }

代码示例来源:origin: reactor/reactor-core

  1. @Test
  2. public void fn5Delegate() {
  3. Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 };
  4. Function<Tuple5<Integer, Integer, Integer, Integer, Integer>, Tuple5> invert =
  5. t5 -> new Tuple5<>(t5.getT5(), t5.getT4(), t5.getT3(), t5.getT2(), t5.getT1());
  6. Tuple5 tuple = Tuples.fn5(invert).apply(source);
  7. assertThat(tuple.getT1()).isEqualTo(5);
  8. assertThat(tuple.getT2()).isEqualTo(4);
  9. assertThat(tuple.getT3()).isEqualTo(3);
  10. assertThat(tuple.getT4()).isEqualTo(2);
  11. assertThat(tuple.getT5()).isEqualTo(1);
  12. assertThat((Object) tuple).isExactlyInstanceOf(Tuple5.class);
  13. }

相关文章