@Override public Tuple2 apply(Object o) { return fromArray((Object[])o); }
/** * Merge given monos into a new {@literal Mono} that will be fulfilled when all of the given {@literal Monos} * have produced an item, aggregating their values into a {@link Tuple2} and delaying errors. * If a Mono source completes without value, the other source is run to completion then the * resulting {@link Mono} completes empty. * If both Monos error, the two exceptions are combined (as suppressed exceptions on a root exception). * * <p> * <img class="marble" src="doc-files/marbles/zipDelayErrorFixedSources.svg" alt=""> * <p> * @param p1 The first upstream {@link Publisher} to subscribe to. * @param p2 The second upstream {@link Publisher} to subscribe to. * @param <T1> type of the value from p1 * @param <T2> type of the value from p2 * * @return a {@link Mono}. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static <T1, T2> Mono<Tuple2<T1, T2>> zipDelayError(Mono<? extends T1> p1, Mono<? extends T2> p2) { return onAssembly(new MonoZip(true, a -> Tuples.fromArray((Object[])a), p1, p2)); }
/** * Merge given monos into a new {@literal Mono} that will be fulfilled when all of the given {@literal Monos} * have produced an item, aggregating their values into a {@link Tuple3}. * An error or <strong>empty</strong> completion of any source will cause other sources * to be cancelled and the resulting Mono to immediately error or complete, respectively. * * <p> * <img class="marble" src="doc-files/marbles/zipFixedSourcesForMono.svg" alt=""> * <p> * @param p1 The first upstream {@link Publisher} to subscribe to. * @param p2 The second upstream {@link Publisher} to subscribe to. * @param p3 The third upstream {@link Publisher} to subscribe to. * @param <T1> type of the value from p1 * @param <T2> type of the value from p2 * @param <T3> type of the value from p3 * * @return a {@link Mono}. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static <T1, T2, T3> Mono<Tuple3<T1, T2, T3>> zip(Mono<? extends T1> p1, Mono<? extends T2> p2, Mono<? extends T3> p3) { return onAssembly(new MonoZip(false, a -> Tuples.fromArray((Object[])a), p1, p2, p3)); }
/** * Merge given monos into a new {@literal Mono} that will be fulfilled when all of the given {@literal Mono Monos} * have produced an item, aggregating their values into a {@link Tuple3} and delaying errors. * If a Mono source completes without value, all other sources are run to completion then * the resulting {@link Mono} completes empty. * If several Monos error, their exceptions are combined (as suppressed exceptions on a root exception). * * <p> * <img class="marble" src="doc-files/marbles/zipDelayErrorFixedSources.svg" alt=""> * <p> * @param p1 The first upstream {@link Publisher} to subscribe to. * @param p2 The second upstream {@link Publisher} to subscribe to. * @param p3 The third upstream {@link Publisher} to subscribe to. * @param <T1> type of the value from p1 * @param <T2> type of the value from p2 * @param <T3> type of the value from p3 * * @return a {@link Mono}. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static <T1, T2, T3> Mono<Tuple3<T1, T2, T3>> zipDelayError(Mono<? extends T1> p1, Mono<? extends T2> p2, Mono<? extends T3> p3) { return onAssembly(new MonoZip(true, a -> Tuples.fromArray((Object[])a), p1, p2, p3)); }
/** * Merge given monos into a new {@literal Mono} that will be fulfilled when all of the given {@literal Monos} * have produced an item, aggregating their values into a {@link Tuple4}. * An error or <strong>empty</strong> completion of any source will cause other sources * to be cancelled and the resulting Mono to immediately error or complete, respectively. * * <p> * <img class="marble" src="doc-files/marbles/zipFixedSourcesForMono.svg" alt=""> * <p> * @param p1 The first upstream {@link Publisher} to subscribe to. * @param p2 The second upstream {@link Publisher} to subscribe to. * @param p3 The third upstream {@link Publisher} to subscribe to. * @param p4 The fourth upstream {@link Publisher} to subscribe to. * @param <T1> type of the value from p1 * @param <T2> type of the value from p2 * @param <T3> type of the value from p3 * @param <T4> type of the value from p4 * * @return a {@link Mono}. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static <T1, T2, T3, T4> Mono<Tuple4<T1, T2, T3, T4>> zip(Mono<? extends T1> p1, Mono<? extends T2> p2, Mono<? extends T3> p3, Mono<? extends T4> p4) { return onAssembly(new MonoZip(false, a -> Tuples.fromArray((Object[])a), p1, p2, p3, p4)); }
/** * Merge given monos into a new {@literal Mono} that will be fulfilled when all of the given {@literal Monos} * have produced an item, aggregating their values into a {@link Tuple4} and delaying errors. * If a Mono source completes without value, all other sources are run to completion then * the resulting {@link Mono} completes empty. * If several Monos error, their exceptions are combined (as suppressed exceptions on a root exception). * * <p> * <img class="marble" src="doc-files/marbles/zipDelayErrorFixedSources.svg" alt=""> * <p> * @param p1 The first upstream {@link Publisher} to subscribe to. * @param p2 The second upstream {@link Publisher} to subscribe to. * @param p3 The third upstream {@link Publisher} to subscribe to. * @param p4 The fourth upstream {@link Publisher} to subscribe to. * @param <T1> type of the value from p1 * @param <T2> type of the value from p2 * @param <T3> type of the value from p3 * @param <T4> type of the value from p4 * * @return a {@link Mono}. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static <T1, T2, T3, T4> Mono<Tuple4<T1, T2, T3, T4>> zipDelayError(Mono<? extends T1> p1, Mono<? extends T2> p2, Mono<? extends T3> p3, Mono<? extends T4> p4) { return onAssembly(new MonoZip(true, a -> Tuples.fromArray((Object[])a), p1, p2, p3, p4)); }
Mono<? extends T5> p5, Mono<? extends T6> p6) { return onAssembly(new MonoZip(true, a -> Tuples.fromArray((Object[])a), p1, p2, p3, p4, p5, p6));
/** * Merge given monos into a new {@literal Mono} that will be fulfilled when all of the given {@literal Monos} * have produced an item, aggregating their values into a {@link Tuple5} and delaying errors. * If a Mono source completes without value, all other sources are run to completion then * the resulting {@link Mono} completes empty. * If several Monos error, their exceptions are combined (as suppressed exceptions on a root exception). * <p> * <img class="marble" src="doc-files/marbles/zipDelayErrorFixedSources.svg" alt=""> * <p> * @param p1 The first upstream {@link Publisher} to subscribe to. * @param p2 The second upstream {@link Publisher} to subscribe to. * @param p3 The third upstream {@link Publisher} to subscribe to. * @param p4 The fourth upstream {@link Publisher} to subscribe to. * @param p5 The fifth upstream {@link Publisher} to subscribe to. * @param <T1> type of the value from p1 * @param <T2> type of the value from p2 * @param <T3> type of the value from p3 * @param <T4> type of the value from p4 * @param <T5> type of the value from p5 * * @return a {@link Mono}. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static <T1, T2, T3, T4, T5> Mono<Tuple5<T1, T2, T3, T4, T5>> zipDelayError(Mono<? extends T1> p1, Mono<? extends T2> p2, Mono<? extends T3> p3, Mono<? extends T4> p4, Mono<? extends T5> p5) { return onAssembly(new MonoZip(true, a -> Tuples.fromArray((Object[])a), p1, p2, p3, p4, p5)); }
/** * Merge given monos into a new {@literal Mono} that will be fulfilled when all of the given {@literal Monos} * have produced an item, aggregating their values into a {@link Tuple5}. * An error or <strong>empty</strong> completion of any source will cause other sources * to be cancelled and the resulting Mono to immediately error or complete, respectively. * * <p> * <img class="marble" src="doc-files/marbles/zipFixedSourcesForMono.svg" alt=""> * <p> * @param p1 The first upstream {@link Publisher} to subscribe to. * @param p2 The second upstream {@link Publisher} to subscribe to. * @param p3 The third upstream {@link Publisher} to subscribe to. * @param p4 The fourth upstream {@link Publisher} to subscribe to. * @param p5 The fifth upstream {@link Publisher} to subscribe to. * @param <T1> type of the value from p1 * @param <T2> type of the value from p2 * @param <T3> type of the value from p3 * @param <T4> type of the value from p4 * @param <T5> type of the value from p5 * * @return a {@link Mono}. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static <T1, T2, T3, T4, T5> Mono<Tuple5<T1, T2, T3, T4, T5>> zip(Mono<? extends T1> p1, Mono<? extends T2> p2, Mono<? extends T3> p3, Mono<? extends T4> p4, Mono<? extends T5> p5) { return onAssembly(new MonoZip(false, a -> Tuples.fromArray((Object[])a), p1, p2, p3, p4, p5)); }
@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); }
@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); }
@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); }
@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); }
@Test @SuppressWarnings("unchecked") public void tuple5CreatedFromArray5() { Integer[] source = new Integer[] { 1, 2, 3, 4, 5 }; Tuple2 expected = Tuples.of(1, 2, 3, 4, 5); Tuple2 actual = Tuples.fromArray(source); assertThat(actual) .isExactlyInstanceOf(Tuple5.class) .isEqualTo(expected); }
@Test @SuppressWarnings("unchecked") public void tuple3CreatedFromArray3() { Integer[] source = new Integer[]{1, 2, 3}; Tuple2 expected = Tuples.of(1, 2, 3); Tuple2 actual = Tuples.fromArray(source); assertThat(actual).isExactlyInstanceOf(Tuple3.class) .isEqualTo(expected); }
@Test @SuppressWarnings("unchecked") public void tuple8CreatedFromArray8() { Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 }; Tuple2 expected = Tuples.of(1, 2, 3, 4, 5, 6, 7, 8); Tuple2 actual = Tuples.fromArray(source); assertThat(actual) .isExactlyInstanceOf(Tuple8.class) .isEqualTo(expected); }
@Test public void fromArrayRejectsNull() { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> Tuples.fromArray(null)) .withMessageStartingWith("null or too small array, need between 2 and 8 values"); }
@Test public void fromArrayRejects0() { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> Tuples.fromArray(new Object[0])) .withMessageStartingWith("null or too small array, need between 2 and 8 values"); }
@Test public void fromArrayRejects1() { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> Tuples.fromArray(new Object[1])) .withMessageStartingWith("null or too small array, need between 2 and 8 values"); }
@Test @SuppressWarnings("unchecked") public void fromArrayRejects9() { Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> Tuples.fromArray(source)) .withMessage("too many arguments (9), need between 2 and 8 values"); }