/** * Map the 3rd part (T3) of this {@link Tuple8} into a different value and type, * keeping the other parts. * * @param mapper the mapping {@link Function} for the T3 part * @param <R> the new type for the T3 part * @return a new {@link Tuple8} with a different T3 value */ public <R> Tuple8<T1, T2, R, T4, T5, T6, T7, T8> mapT3(Function<T3, R> mapper) { return new Tuple8<>(t1, t2, mapper.apply(t3), t4, t5, t6, t7, t8); }
@Test public void fn8Delegate() { Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 }; Function<Tuple8<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer>, Integer> sum = t8 -> t8.getT8() + t8.getT7() + t8.getT6() + t8.getT5() + t8.getT4() + t8.getT3() + t8.getT2() + t8.getT1(); Integer result = Tuples.fn8(sum).apply(source); assertThat(result).isEqualTo(36); }
@Test public void sanityTestHashcode() { Tuple8<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer> same = new Tuple8<>(1, 2, 3, 4, 5, 6, 7, 8); Tuple8<Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer> different = new Tuple8<>(1, 2, 3, 4, 5, 6, 7, 1); assertThat(full.hashCode()) .isEqualTo(same.hashCode()) .isNotEqualTo(different.hashCode()); } }
@Test public void mapT1() { Tuple8<String, Integer, Integer, Integer, Integer, Integer, Integer, Integer> base = Tuples.of("Foo", 200, 300, 400, 500, 600, 700, 800); Tuple2<?,?> mapped = base.mapT1(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(8) .containsExactly(3, base.getT2(), base.getT3(), base.getT4(), base.getT5(), base.getT6(), base.getT7(), base.getT8()); }
@Test public void mapT5() { Tuple8<Integer, Integer, Integer, Integer, String, Integer, Integer, Integer> base = Tuples.of(100, 200, 300, 400, "Foo", 600, 700, 800); Tuple2<?,?> mapped = base.mapT5(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(8) .containsExactly(base.getT1(), base.getT2(), base.getT3(), base.getT4(), 3, base.getT6(), base.getT7(), base.getT8()); }
@Test public void mapT6() { Tuple8<Integer, Integer, Integer, Integer, Integer, String, Integer, Integer> base = Tuples.of(100, 200, 300, 400, 500, "Foo", 700, 800); Tuple2<?,?> mapped = base.mapT6(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(8) .containsExactly(base.getT1(), base.getT2(), base.getT3(), base.getT4(), base.getT5(), 3, base.getT7(), base.getT8()); }
@Test public void mapT7() { Tuple8<Integer, Integer, Integer, Integer, Integer, Integer, String, Integer> base = Tuples.of(100, 200, 300, 400, 500, 600, "Foo", 800); Tuple2<?,?> mapped = base.mapT7(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(8) .containsExactly(base.getT1(), base.getT2(), base.getT3(), base.getT4(), base.getT5(), base.getT6(), 3, base.getT8()); }
@Test public void mapT4() { Tuple8<Integer, Integer, Integer, String, Integer, Integer, Integer, Integer> base = Tuples.of(100, 200, 300, "Foo", 500, 600, 700, 800); Tuple2<?,?> mapped = base.mapT4(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(8) .containsExactly(base.getT1(), base.getT2(), base.getT3(), 3, base.getT5(), base.getT6(), base.getT7(), base.getT8()); }
@Test public void mapT8() { Tuple8<Integer, Integer, Integer, Integer, Integer, Integer, Integer, String> base = Tuples.of(100, 200, 300, 400, 500, 600, 700, "Foo"); Tuple2<?,?> mapped = base.mapT8(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(8) .containsExactly(base.getT1(), base.getT2(), base.getT3(), base.getT4(), base.getT5(), base.getT6(), base.getT7(), 3); }
@Test public void mapT2() { Tuple8<Integer, String, Integer, Integer, Integer, Integer, Integer, Integer> base = Tuples.of(100, "Foo", 300, 400, 500, 600, 700, 800); Tuple2<?,?> mapped = base.mapT2(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(8) .containsExactly(base.getT1(), 3, base.getT3(), base.getT4(), base.getT5(), base.getT6(), base.getT7(), base.getT8()); }
@Test public void mapT3() { Tuple8<Integer, Integer, String, Integer, Integer, Integer, Integer, Integer> base = Tuples.of(100, 200, "Foo", 400, 500, 600, 700, 800); Tuple2<?,?> mapped = base.mapT3(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(8) .containsExactly(base.getT1(), base.getT2(), 3, base.getT4(), base.getT5(), base.getT6(), base.getT7(), base.getT8()); }
@Test public void fn8() { Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 }; Tuple8 tuple = Tuples.fn8().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.getT7()).isEqualTo(7); assertThat(tuple.getT8()).isEqualTo(8); }
/** * Map the 2nd part (T2) of this {@link Tuple8} into a different value and type, * keeping the other parts. * * @param mapper the mapping {@link Function} for the T2 part * @param <R> the new type for the T2 part * @return a new {@link Tuple8} with a different T2 value */ public <R> Tuple8<T1, R, T3, T4, T5, T6, T7, T8> mapT2(Function<T2, R> mapper) { return new Tuple8<>(t1, mapper.apply(t2), t3, t4, t5, t6, t7, t8); }
@Test public void whenMonoJust8() { StepVerifier.create(Mono.zip(Mono.just(1), Mono.just(2), Mono.just(3), Mono.just(4), Mono.just(5), Mono.just(6), Mono.just(7), Mono.just(8))) .assertNext(v -> assertThat(v.getT1() == 1 && v.getT2() == 2 && v.getT3() == 3 && v.getT4() == 4 && v.getT5() == 5 && v.getT6() == 6 && v.getT7() == 7 && v.getT8() == 8).isTrue()) .verifyComplete(); }
/** * Map the 4th part (T4) of this {@link Tuple8} into a different value and type, * keeping the other parts. * * @param mapper the mapping {@link Function} for the T4 part * @param <R> the new type for the T4 part * @return a new {@link Tuple8} with a different T4 value */ public <R> Tuple8<T1, T2, T3, R, T5, T6, T7, T8> mapT4(Function<T4, R> mapper) { return new Tuple8<>(t1, t2, t3, mapper.apply(t4), t5, t6, t7, t8); }
@Test public void whenDelayMonoJust8() { StepVerifier.create(Mono.zipDelayError(Mono.just(1), Mono.just(2), Mono.just(3), Mono.just(4), Mono.just(5), Mono.just(6), Mono.just(7), Mono.just(8))) .assertNext(v -> assertThat(v.getT1() == 1 && v.getT2() == 2 && v.getT3() == 3 && v.getT4() == 4 && v.getT5() == 5 && v.getT6() == 6 && v.getT7() == 7 && v.getT8() == 8).isTrue()) .verifyComplete(); }
/** * Map the 8th part (t8) of this {@link Tuple8} into a different value and type, * keeping the other parts. * * @param mapper the mapping {@link Function} for the T8 part * @param <R> the new type for the T8 part * @return a new {@link Tuple8} with a different T8 value */ public <R> Tuple8<T1, T2, T3, T4, T5, T6, T7, R> mapT8(Function<T8, R> mapper) { return new Tuple8<>(t1, t2, t3, t4, t5, t6, t7, mapper.apply(t8)); }
/** * Returns a {@link Consumer} of {@link Tuple8} that wraps a consumer of the component values of the tuple * * @param consumer the component value consumer * @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 <T7> the type of the seventh value * @param <T8> the type of the eighth value * @return the wrapper consumer */ public static <T1, T2, T3, T4, T5, T6, T7, T8> Consumer<Tuple8<T1, T2, T3, T4, T5, T6, T7, T8>> consumer(Consumer8<T1, T2, T3, T4, T5, T6, T7, T8> consumer) { return tuple -> consumer.accept(tuple.getT1(), tuple.getT2(), tuple.getT3(), tuple.getT4(), tuple.getT5(), tuple.getT6(), tuple.getT7(), tuple.getT8()); }
/** * Map the 6th part (T6) of this {@link Tuple8} into a different value and type, * keeping the other parts. * * @param mapper the mapping {@link Function} for the T6 part * @param <R> the new type for the T6 part * @return a new {@link Tuple8} with a different T6 value */ public <R> Tuple8<T1, T2, T3, T4, T5, R, T7, T8> mapT6(Function<T6, R> mapper) { return new Tuple8<>(t1, t2, t3, t4, t5, mapper.apply(t6), t7, t8); }
/** * Returns a {@link Predicate} of {@link Tuple8} that wraps a predicate of the component values of the tuple * * @param predicate the component value predicate * @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 <T7> the type of the seventh value * @param <T8> the type of the eighth value * @return the wrapper predicate */ public static <T1, T2, T3, T4, T5, T6, T7, T8> Predicate<Tuple8<T1, T2, T3, T4, T5, T6, T7, T8>> predicate(Predicate8<T1, T2, T3, T4, T5, T6, T7, T8> predicate) { return tuple -> predicate.test(tuple.getT1(), tuple.getT2(), tuple.getT3(), tuple.getT4(), tuple.getT5(), tuple.getT6(), tuple.getT7(), tuple.getT8()); }