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:
parent
74c3c6839b
commit
8c410bef19
1 changed files with 12 additions and 11 deletions
|
|
@ -41,9 +41,9 @@ import java.util.Collection;
|
||||||
*/
|
*/
|
||||||
public class TimeTermination implements PrematureAlgorithmTermination, AlgorithmStartsListener {
|
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 final long timeThreshold;
|
||||||
|
|
||||||
private TimeGetter timeGetter = new TimeGetter() {
|
private TimeGetter timeGetter = System::currentTimeMillis;
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getCurrentTime() {
|
|
||||||
return System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
private long startTime;
|
private long startTime;
|
||||||
|
|
||||||
|
|
@ -91,7 +84,7 @@ public class TimeTermination implements PrematureAlgorithmTermination, Algorithm
|
||||||
this.startTime = startTime;
|
this.startTime = startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
private long now() {
|
public long now() {
|
||||||
return timeGetter.getCurrentTime();
|
return timeGetter.getCurrentTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,4 +93,12 @@ public class TimeTermination implements PrematureAlgorithmTermination, Algorithm
|
||||||
start(timeGetter.getCurrentTime());
|
start(timeGetter.getCurrentTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getRemainingTime() {
|
||||||
|
return timeThreshold - (now() - startTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getStartTime() {
|
||||||
|
return startTime;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue