mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-17 01:31:01 +00:00
added failing test case for TimeRange.timeDifference
This commit is contained in:
1 parent
5b089b20b9
commit
050d46901c
5 files changed
+56
-33
No files matched your search
@@ -12,6 +12,7 @@ import com.sap.sailing.domain.common.impl.MillisecondsDurationImpl;
|
||||
*/
|
||||
public interface Duration extends Serializable, Comparable<Duration> {
|
||||
|
||||
static final Duration NULL = new MillisecondsDurationImpl(0);
|
||||
static final Duration ONE_SECOND = new MillisecondsDurationImpl(1000);
|
||||
static final Duration ONE_MINUTE = ONE_SECOND.times(60);
|
||||
static final Duration ONE_HOUR = ONE_MINUTE.times(60);
|
||||
|
||||
@@ -51,8 +51,6 @@ public interface TimeRange extends Comparable<TimeRange>, Serializable {
|
||||
* Get time-difference between the timepoint and this timerange.
|
||||
* It will be 0 if the timepoint lies within the timerange, otherwise the time-difference
|
||||
* to either the start or end of the timerange, depending on which is closer
|
||||
* @param timePoint
|
||||
* @return
|
||||
*/
|
||||
long timeDifference(TimePoint timePoint);
|
||||
|
||||
|
||||
+14
@@ -66,6 +66,20 @@ public class TimeRangeImpl extends Pair<TimePoint, TimePoint> implements TimeRan
|
||||
if (timePoint.before(from())) return from().asMillis() - timePoint.asMillis();
|
||||
return to().asMillis() - timePoint.asMillis();
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public Duration timeDifference(TimePoint timePoint) {
|
||||
// final Duration result;
|
||||
// if (includes(timePoint)) {
|
||||
// result = Duration.NULL;
|
||||
// } else if (timePoint.before(from())) {
|
||||
// result = timePoint.until(from());
|
||||
// } else {
|
||||
// result = to().until(timePoint);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
public TimeRange union(TimeRange other) {
|
||||
|
||||
+8
@@ -121,4 +121,12 @@ public class TimeRangeTest {
|
||||
assertEquals(0, intersection.from().asMillis());
|
||||
assertEquals(10, intersection.to().asMillis());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void timeDifferenceTest() {
|
||||
TimeRange one = create(5, 10);
|
||||
assertEquals(2, one.timeDifference(new MillisecondsTimePoint(3)));
|
||||
assertEquals(0, one.timeDifference(new MillisecondsTimePoint(7)));
|
||||
assertEquals(2, one.timeDifference(new MillisecondsTimePoint(12)));
|
||||
}
|
||||
}
|
||||
+33
-31
@@ -2348,41 +2348,43 @@ public abstract class TrackedRaceImpl extends TrackedRaceWithWindEssentials impl
|
||||
public void attachRaceLog(final RaceLog raceLog) {
|
||||
if (raceLog != null) {
|
||||
this.attachedRaceLogs.put(raceLog.getId(), raceLog);
|
||||
|
||||
//Use the new race log, that possibly contains device mappings, to load GPSFix tracks from the DB
|
||||
// Use the new race log, that possibly contains device mappings, to load GPSFix tracks from the DB
|
||||
loadingFromStoresCompleted = LoadingFromStoresState.NOT_STARTED;
|
||||
// When this tracked race is to be serialized, wait for the loading from stores to complete.
|
||||
new Thread("Mongo mark and competitor track loader for tracked race " + getRace().getName()) {
|
||||
@Override
|
||||
public void run() {
|
||||
LockUtil.lockForRead(getSerializationLock());
|
||||
LockUtil.lockForWrite(getLoadingFromStoresLock());
|
||||
synchronized (TrackedRaceImpl.this) {
|
||||
loadingFromStoresCompleted = LoadingFromStoresState.RUNNING; // indicates that the serialization lock is now safely held
|
||||
TrackedRaceImpl.this.notifyAll();
|
||||
}
|
||||
try {
|
||||
logger.info("Started loading competitor tracks for " + getRace().getName());
|
||||
for (Competitor competitor : race.getCompetitors()) {
|
||||
gpsFixStore.loadCompetitorTrack((DynamicGPSFixTrack<Competitor, GPSFixMoving>) tracks.get(competitor), raceLog, competitor);
|
||||
}
|
||||
logger.info("Finished loading competitor tracks for " + getRace().getName());
|
||||
@Override
|
||||
public void run() {
|
||||
LockUtil.lockForRead(getSerializationLock());
|
||||
LockUtil.lockForWrite(getLoadingFromStoresLock());
|
||||
synchronized (TrackedRaceImpl.this) {
|
||||
loadingFromStoresCompleted = LoadingFromStoresState.RUNNING; // indicates that the serialization
|
||||
// lock is now safely held
|
||||
TrackedRaceImpl.this.notifyAll();
|
||||
}
|
||||
try {
|
||||
logger.info("Started loading competitor tracks for " + getRace().getName());
|
||||
for (Competitor competitor : race.getCompetitors()) {
|
||||
gpsFixStore.loadCompetitorTrack(
|
||||
(DynamicGPSFixTrack<Competitor, GPSFixMoving>) tracks.get(competitor), raceLog,
|
||||
competitor);
|
||||
}
|
||||
logger.info("Finished loading competitor tracks for " + getRace().getName());
|
||||
logger.info("Started loading mark tracks for " + getRace().getName());
|
||||
for (Mark mark : getMarks()) {
|
||||
gpsFixStore.loadMarkTrack((DynamicGPSFixTrack<Mark, GPSFix>) markTracks.get(mark), raceLog,
|
||||
mark);
|
||||
}
|
||||
logger.info("Finished loading mark tracks for " + getRace().getName());
|
||||
|
||||
logger.info("Started loading mark tracks for " + getRace().getName());
|
||||
for (Mark mark : getMarks()) {
|
||||
gpsFixStore.loadMarkTrack((DynamicGPSFixTrack<Mark, GPSFix>) markTracks.get(mark), raceLog, mark);
|
||||
}
|
||||
logger.info("Finished loading mark tracks for " + getRace().getName());
|
||||
|
||||
} finally {
|
||||
synchronized (TrackedRaceImpl.this) {
|
||||
loadingFromStoresCompleted = LoadingFromStoresState.FINISHED;
|
||||
TrackedRaceImpl.this.notifyAll();
|
||||
}
|
||||
LockUtil.unlockAfterWrite(getLoadingFromStoresLock());
|
||||
LockUtil.unlockAfterRead(getSerializationLock());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
synchronized (TrackedRaceImpl.this) {
|
||||
loadingFromStoresCompleted = LoadingFromStoresState.FINISHED;
|
||||
TrackedRaceImpl.this.notifyAll();
|
||||
}
|
||||
LockUtil.unlockAfterWrite(getLoadingFromStoresLock());
|
||||
LockUtil.unlockAfterRead(getSerializationLock());
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
} else {
|
||||
logger.severe("Got a request to attach race log for an empty race log!");
|
||||
|
||||
Reference in new issue
Block a user