1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

add helper methods

This commit is contained in:
oblonski 2020-01-23 10:43:33 +01:00
parent 74c3c6839b
commit 8c410bef19
No known key found for this signature in database
GPG key ID: 179DE487285680D1

View file

@ -41,9 +41,9 @@ import java.util.Collection;
*/
public class TimeTermination implements PrematureAlgorithmTermination, AlgorithmStartsListener {
public static interface TimeGetter {
public interface TimeGetter {
public long getCurrentTime();
long getCurrentTime();
}
@ -51,14 +51,7 @@ public class TimeTermination implements PrematureAlgorithmTermination, Algorithm
private final long timeThreshold;
private TimeGetter timeGetter = new TimeGetter() {
@Override
public long getCurrentTime() {
return System.currentTimeMillis();
}
};
private TimeGetter timeGetter = System::currentTimeMillis;
private long startTime;
@ -91,7 +84,7 @@ public class TimeTermination implements PrematureAlgorithmTermination, Algorithm
this.startTime = startTime;
}
private long now() {
public long now() {
return timeGetter.getCurrentTime();
}
@ -100,4 +93,12 @@ public class TimeTermination implements PrematureAlgorithmTermination, Algorithm
start(timeGetter.getCurrentTime());
}
public long getRemainingTime() {
return timeThreshold - (now() - startTime);
}
public long getStartTime() {
return startTime;
}
}