Percent implements Comparable<Percent> { @Override public boolean equals(Object obj) { if (obj instanceof Percent) { return percent == ((Percent) obj).percent; } return false; } Percent(String value);  Percent(int value);  Percent(double value); double getValue(); double getPercent(); @Override String toString(); String toString(int precision); @Override boolean equals(Object obj); @Override int hashCode(); @Override int compareTo(Percent o); static final Percent ZERO; static final Percent HUNDRED; }
@Test public void testEquals() { Percent p1 = new Percent(1); Percent p2 = new Percent(2); Percent p3 = new Percent(1); Percent p4 = new Percent(1.000); assertTrue(p1.equals(p1)); assertFalse(p1.equals(null)); assertFalse(p1.equals(p2)); assertTrue(p1.equals(p3)); assertTrue(p1.equals(p4)); assertTrue(p4.equals(p1)); }