Refactor comparator

This commit is contained in:
pivovarit 2017-05-14 08:12:28 +02:00
parent 73925c14dc
commit 98ec0ac0b3
1 changed files with 3 additions and 7 deletions

View File

@ -1,5 +1,7 @@
package com.baeldung.concurrent.delayqueue;
import com.google.common.primitives.Ints;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;
@ -20,13 +22,7 @@ public class DelayObject implements Delayed {
@Override
public int compareTo(Delayed o) {
if (this.startTime < ((DelayObject) o).startTime) {
return -1;
}
if (this.startTime > ((DelayObject) o).startTime) {
return 1;
}
return 0;
return Ints.saturatedCast(this.startTime - ((DelayObject) o).startTime);
}
@Override