Ratio extends Number implements Comparable<Ratio> { @Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || !Objects.equals(getClass(), o.getClass())) { return false; } final Ratio ratio = (Ratio) o; return Objects.equals(raw, ratio.raw); } private  Ratio(final BigDecimal raw); static Ratio fromRaw(final String rate); static Ratio fromRaw(final BigDecimal rate); static Ratio fromPercentage(final String rate); static Ratio fromPercentage(final Number rate); BigDecimal bigDecimalValue(); BigDecimal asPercentage(); Ratio min(final Ratio other); Ratio max(final Ratio other); @Override String toString(); @Override boolean equals(final Object o); Money apply(final Money money); @Override int hashCode(); @Override int compareTo(final Ratio o); @Override int intValue(); @Override long longValue(); @Override float floatValue(); @Override double doubleValue(); static final Ratio ZERO; static final Ratio ONE; }
@Test void equals() { final Ratio ratio = Ratio.fromRaw("2.64"); final Ratio ratio2 = Ratio.fromRaw("2.65"); final Ratio ratio3 = Ratio.fromRaw("2.64"); assertSoftly(softly -> { softly.assertThat(ratio) .isNotEqualTo(null); softly.assertThat(ratio) .isNotEqualTo(UUID.randomUUID() .toString()); softly.assertThat(ratio) .isEqualTo(ratio); softly.assertThat(ratio) .isNotEqualTo(ratio2); softly.assertThat(ratio2) .isNotEqualTo(ratio); softly.assertThat(ratio3) .isEqualTo(ratio); softly.assertThat(ratio) .isEqualTo(ratio3); }); final Ratio ratio4 = Ratio.fromRaw(BigDecimal.ZERO); Assertions.assertThat(ratio4) .isSameAs(Ratio.ZERO); final Ratio ratio5 = Ratio.fromRaw(BigDecimal.ONE); Assertions.assertThat(ratio5) .isSameAs(Ratio.ONE); }