Duration implements Comparable<Duration> { @Override public int hashCode() { return duration.hashCode(); } Duration(String value);  Duration(long value); @Override boolean equals(Object obj); @Override int hashCode(); java.time.Duration getDuration(); @Override int compareTo(Duration o); @Override String toString(); static final Duration ZERO; }
@Test public void testHashCode() { Duration d1 = new Duration("1s"); Duration d2 = new Duration("2s"); Duration d3 = new Duration("1 sec"); Duration d4 = new Duration("1000ms"); assertEquals(d1.hashCode(), d1.hashCode()); assertEquals(d1.hashCode(), d3.hashCode()); assertEquals(d1.hashCode(), d4.hashCode()); assertNotEquals(d1.hashCode(), d2.hashCode()); }