Comparable not sensibly implemented
GregDThomas opened this issue · 2 comments
GregDThomas commented
The following fairly simply test fails;
@Test
public void aSecondIsLongerThanTenMilliseconds() {
assertThat(Duration.seconds(1).compareTo(Duration.millis(10)), is(greaterThan(0)));
}
Largely because the compareTo()
implementation is comparing the raw figures (1 vs. 10) not the implied duration (1 second vs 10 milliseconds).
The fix is fairly simple; in Duration.java
change
public int compareTo(Duration other) {
return this.value.compareTo(other.value);
}
to
public int compareTo(Duration other) {
return ((Long)this.inMillis()).compareTo(other.inMillis());
}
tobyweston commented
Thanks, I'll fix that. If you want to do a pull request, you might get round to it quicker than me.
Cheers
GregDThomas commented
There you go; enjoy!