@Test public void fn6Delegate() { Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 }; Function<Tuple6<Integer, Integer, Integer, Integer, Integer, Integer>, Tuple6> invert = t6 -> new Tuple6<>(t6.getT6(), t6.getT5(), t6.getT4(), t6.getT3(), t6.getT2(), t6.getT1()); Tuple6 tuple = Tuples.fn6(invert).apply(source); assertThat(tuple.getT1()).isEqualTo(6); assertThat(tuple.getT2()).isEqualTo(5); assertThat(tuple.getT3()).isEqualTo(4); assertThat(tuple.getT4()).isEqualTo(3); assertThat(tuple.getT5()).isEqualTo(2); assertThat(tuple.getT6()).isEqualTo(1); assertThat((Object) tuple).isExactlyInstanceOf(Tuple6.class); }
@Test public void sanityTestHashcode() { Tuple6<Integer, Integer, Integer, Integer, Integer, Integer> same = new Tuple6<>(1, 2, 3, 4, 5, 6); Tuple6<Integer, Integer, Integer, Integer, Integer, Integer> different = new Tuple6<>(1, 2, 3, 4, 5, 1); assertThat(full.hashCode()) .isEqualTo(same.hashCode()) .isNotEqualTo(different.hashCode()); } }
@Override public boolean equals(@Nullable Object o) { if (this == o) return true; if (!(o instanceof Tuple7)) return false; if (!super.equals(o)) return false; @SuppressWarnings("rawtypes") Tuple7 tuple7 = (Tuple7) o; return t7.equals(tuple7.t7); }
@Test public void mapT2() { Tuple6<Integer, String, Integer, Integer, Integer, Integer> base = Tuples.of(100, "Foo", 300, 400, 500, 600); Tuple2<?,?> mapped = base.mapT2(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(6) .containsExactly(base.getT1(), 3, base.getT3(), base.getT4(), base.getT5(), base.getT6()); }
@Test public void mapT6() { Tuple6<Integer, Integer, Integer, Integer, Integer, String> base = Tuples.of(100, 200, 300, 400, 500, "Foo"); Tuple2<?,?> mapped = base.mapT6(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(6) .containsExactly(base.getT1(), base.getT2(), base.getT3(), base.getT4(), base.getT5(), 3); }
@Test public void mapT5() { Tuple6<Integer, Integer, Integer, Integer, String, Integer> base = Tuples.of(100, 200, 300, 400, "Foo", 600); Tuple2<?,?> mapped = base.mapT5(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(6) .containsExactly(base.getT1(), base.getT2(), base.getT3(), base.getT4(), 3, base.getT6()); }
@Test public void mapT1() { Tuple6<String, Integer, Integer, Integer, Integer, Integer> base = Tuples.of("Foo", 200, 300, 400, 500, 600); Tuple2<?,?> mapped = base.mapT1(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(6) .containsExactly(3, base.getT2(), base.getT3(), base.getT4(), base.getT5(), base.getT6()); }
@Test public void mapT3() { Tuple6<Integer, Integer, String, Integer, Integer, Integer> base = Tuples.of(100, 200, "Foo", 400, 500, 600); Tuple2<?,?> mapped = base.mapT3(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(6) .containsExactly(base.getT1(), base.getT2(), 3, base.getT4(), base.getT5(), base.getT6()); }
@Test public void mapT4() { Tuple6<Integer, Integer, Integer, String, Integer, Integer> base = Tuples.of(100, 200, 300, "Foo", 500, 600); Tuple2<?,?> mapped = base.mapT4(String::length); assertThat(mapped).isNotSameAs(base) .hasSize(6) .containsExactly(base.getT1(), base.getT2(), base.getT3(), 3, base.getT5(), base.getT6()); }
/** * Map the 3rd part (T3) of this {@link Tuple6} 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 Tuple6} with a different T3 value */ public <R> Tuple6<T1, T2, R, T4, T5, T6> mapT3(Function<T3, R> mapper) { return new Tuple6<>(t1, t2, mapper.apply(t3), t4, t5, t6); }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + t7.hashCode(); return result; }
/** * Map the 2nd part (T2) of this {@link Tuple6} 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 Tuple6} with a different T2 value */ public <R> Tuple6<T1, R, T3, T4, T5, T6> mapT2(Function<T2, R> mapper) { return new Tuple6<>(t1, mapper.apply(t2), t3, t4, t5, t6); }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + t7.hashCode(); return result; }
@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); }
/** * Map the 4th part (T4) of this {@link Tuple6} 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 Tuple6} with a different T4 value */ public <R> Tuple6<T1, T2, T3, R, T5, T6> mapT4(Function<T4, R> mapper) { return new Tuple6<>(t1, t2, t3, mapper.apply(t4), t5, t6); }
@Override public boolean equals(@Nullable Object o) { if (this == o) return true; if (!(o instanceof Tuple7)) return false; if (!super.equals(o)) return false; @SuppressWarnings("rawtypes") Tuple7 tuple7 = (Tuple7) o; return t7.equals(tuple7.t7); }
@Test public void whenDelayMonoJust6() { MonoProcessor<Tuple6<Integer, Integer, Integer, Integer, Integer, Integer>> mp = MonoProcessor.create(); StepVerifier.create(Mono.zipDelayError(Mono.just(1), Mono.just(2), Mono.just(3), Mono.just(4), Mono.just(5), Mono.just(6)) .subscribeWith(mp)) .then(() -> assertThat(mp.isError()).isFalse()) .then(() -> assertThat(mp.isSuccess()).isTrue()) .then(() -> assertThat(mp.isTerminated()).isTrue()) .assertNext(v -> assertThat(v.getT1() == 1 && v.getT2() == 2 && v.getT3() == 3 && v.getT4() == 4 && v.getT5() == 5 && v.getT6() == 6).isTrue()) .verifyComplete(); }
/** * Map the 6th part (T6) of this {@link Tuple6} 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 Tuple6} with a different T6 value */ public <R> Tuple6<T1, T2, T3, T4, T5, R> mapT6(Function<T6, R> mapper) { return new Tuple6<>(t1, t2, t3, t4, t5, mapper.apply(t6)); }
@Test public void whenMonoJust6() { MonoProcessor<Tuple6<Integer, Integer, Integer, Integer, Integer, Integer>> mp = MonoProcessor.create(); StepVerifier.create(Mono.zip(Mono.just(1), Mono.just(2), Mono.just(3), Mono.just(4), Mono.just(5), Mono.just(6)) .subscribeWith(mp)) .then(() -> assertThat(mp.isError()).isFalse()) .then(() -> assertThat(mp.isSuccess()).isTrue()) .then(() -> assertThat(mp.isTerminated()).isTrue()) .assertNext(v -> assertThat(v.getT1() == 1 && v.getT2() == 2 && v.getT3() == 3 && v.getT4() == 4 && v.getT5() == 5 && v.getT6() == 6).isTrue()) .verifyComplete(); }
/** * Map the 1st part (T1) of this {@link Tuple6} into a different value and type, * keeping the other parts. * * @param mapper the mapping {@link Function} for the T1 part * @param <R> the new type for the T1 part * @return a new {@link Tuple6} with a different T1 value */ public <R> Tuple6<R, T2, T3, T4, T5, T6> mapT1(Function<T1, R> mapper) { return new Tuple6<>(mapper.apply(t1), t2, t3, t4, t5, t6); }