Duration implements Comparable<Duration> { @Override public int compareTo(Duration o) { return duration.compareTo(o.duration); } 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 testCompareTo() { Duration d1 = new Duration("1s"); Duration d2 = new Duration("2s"); Duration d3 = new Duration("1 sec"); Duration d4 = new Duration("1day"); Duration d5 = new Duration("1.1s"); Duration d6 = new Duration("1100ms"); assertTrue(d1.compareTo(d1) == 0); assertTrue(d1.compareTo(d2) < 0); assertTrue(d2.compareTo(d1) > 0); assertTrue(d1.compareTo(d3) == 0); assertTrue(d4.compareTo(d1) > 0); assertTrue(d5.compareTo(d6) == 0); }