Percent implements Comparable<Percent> { @Override public int hashCode() { return Double.hashCode(percent); } 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 testHashCode() { Percent p1 = new Percent(1); Percent p2 = new Percent(2); Percent p3 = new Percent(1); Percent p4 = new Percent(1.000); Percent p5 = new Percent(1.00000001); assertEquals(p1.hashCode(), p1.hashCode()); assertEquals(p1.hashCode(), p3.hashCode()); assertEquals(p1.hashCode(), p4.hashCode()); assertNotEquals(p1.hashCode(), p2.hashCode()); assertNotEquals(p1.hashCode(), p5.hashCode()); }