Tuple2 { @Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || !Objects.equals(getClass(), o.getClass())) { return false; } final Tuple2<?, ?> tuple2 = (Tuple2<?, ?>) o; return Objects.equals(_1, tuple2._1) && Objects.equals(_2, tuple2._2); } Tuple2(T1 t1, T2 t2); T1 _1(); T2 _2(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString(); final T1 _1; final T2 _2; }
@Test void equals() { Tuple2 tuple = Tuple.of(1, 1); SoftAssertions.assertSoftly(softly -> { softly.assertThat(tuple) .isEqualTo(tuple); softly.assertThat(tuple) .isNotEqualTo(null); softly.assertThat(tuple) .isNotEqualTo(""); }); Tuple2 tuple2 = Tuple.of(1, 1); SoftAssertions.assertSoftly(softly -> { softly.assertThat(tuple) .isNotSameAs(tuple2); softly.assertThat(tuple) .isEqualTo(tuple2); }); Tuple2 tuple3 = Tuple.of(1, 2); SoftAssertions.assertSoftly(softly -> { softly.assertThat(tuple3) .isNotEqualTo(tuple); softly.assertThat(tuple) .isNotEqualTo(tuple3); }); }