mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-04 01:59:35 +00:00
Merge branch 'master' into regatta-log
Conflicts: java/com.sap.sailing.domain.shared.android/src/com/sap/sailing/domain/abstractlog/race/tracking/DeviceWithTimeRange.java java/com.sap.sailing.domain.shared.android/src/com/sap/sailing/domain/abstractlog/shared/analyzing/DeviceMappingFinder.java java/com.sap.sailing.domain.shared.android/src/com/sap/sailing/domain/racelogtracking/impl/DeviceMappingImpl.java java/com.sap.sailing.domain/src/com/sap/sailing/domain/racelog/tracking/EmptyGPSFixStore.java java/com.sap.sailing.server.gateway/src/com/sap/sailing/server/gateway/trackfiles/impl/DeviceWithTimeRangeImpl.java
This commit is contained in:
commit
d693090d81
15 files changed
+24
-28
No files matched your search
@@ -0,0 +1,62 @@
|
||||
package com.sap.sse.common;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public interface TimeRange extends Comparable<TimeRange>, Serializable {
|
||||
|
||||
TimePoint from();
|
||||
|
||||
TimePoint to();
|
||||
|
||||
/**
|
||||
* Also returns true if (either or both) the from or to timepoints are equal.
|
||||
* E.g. 10-100 lies within 10-00, and 10-50 lies within 10-100.
|
||||
* @param other
|
||||
* @return
|
||||
*/
|
||||
boolean liesWithin(TimeRange other);
|
||||
|
||||
/**
|
||||
* Reverse operation of {@link #liesWithin(TimeRange)}.
|
||||
* x.includes(y) = y.liesWithin(x)
|
||||
* @param other
|
||||
* @return
|
||||
*/
|
||||
boolean includes(TimeRange other);
|
||||
|
||||
boolean includes(TimePoint timePoint);
|
||||
|
||||
boolean intersects(TimeRange other);
|
||||
|
||||
boolean startsBefore(TimeRange other);
|
||||
|
||||
boolean endsAfter(TimeRange other);
|
||||
|
||||
/**
|
||||
* Is the time range open ended towards older timepoints?
|
||||
*/
|
||||
boolean hasOpenBeginning();
|
||||
|
||||
/**
|
||||
* Is the time range open ended towards newer timepoints?
|
||||
*/
|
||||
boolean hasOpenEnd();
|
||||
|
||||
/**
|
||||
* 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. The
|
||||
* time difference is a duration that is guaranteed to be positive.
|
||||
*/
|
||||
Duration timeDifference(TimePoint timePoint);
|
||||
|
||||
/**
|
||||
* Merges the two ranges, only possible if {@code other} {@link #intersects()} this range.
|
||||
*/
|
||||
TimeRange union(TimeRange other);
|
||||
|
||||
/**
|
||||
* Intersection of the two ranges, only possible if {@code other} {@link #intersects()} this range.
|
||||
*/
|
||||
TimeRange intersection(TimeRange other);
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package com.sap.sse.common.impl;
|
||||
|
||||
import com.sap.sse.common.Duration;
|
||||
import com.sap.sse.common.TimePoint;
|
||||
import com.sap.sse.common.TimeRange;
|
||||
import com.sap.sse.common.Util;
|
||||
|
||||
public class TimeRangeImpl extends Util.Pair<TimePoint, TimePoint> implements TimeRange {
|
||||
private static final long serialVersionUID = 8710198176227507300L;
|
||||
|
||||
public static TimeRange create(long fromMillis, long toMillis) {
|
||||
return new TimeRangeImpl(new MillisecondsTimePoint(fromMillis), new MillisecondsTimePoint(toMillis));
|
||||
}
|
||||
|
||||
public TimeRangeImpl(TimePoint from, TimePoint to) {
|
||||
super(from == null ? TimePoint.BeginningOfTime : from, to == null ? TimePoint.EndOfTime : to);
|
||||
if (from().after(to())) {
|
||||
throw new IllegalArgumentException("from " + from() + " must lie before to " + to() + " in a TimeRange");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(TimeRange other) {
|
||||
final int result;
|
||||
if (other.from().equals(from()) && other.to().equals(to())) {
|
||||
result = 0;
|
||||
} else {
|
||||
result = startsBefore(other) ? -1 : 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimePoint from() {
|
||||
return getA();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimePoint to() {
|
||||
return getB();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean liesWithin(TimeRange other) {
|
||||
return from().compareTo(other.from()) >= 0 && to().compareTo(other.to()) <= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includes(TimeRange other) {
|
||||
return other.liesWithin(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean intersects(TimeRange other) {
|
||||
return includes(other.from()) || includes(other.to()) || liesWithin(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includes(TimePoint timePoint) {
|
||||
return from().compareTo(timePoint) <= 0 && to().compareTo(timePoint) >= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startsBefore(TimeRange other) {
|
||||
return from().before(other.from());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean endsAfter(TimeRange other) {
|
||||
return to().after(other.to());
|
||||
}
|
||||
|
||||
@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) {
|
||||
final TimeRange result;
|
||||
if (!intersects(other)) {
|
||||
result = null;
|
||||
} else {
|
||||
TimePoint newFrom = startsBefore(other) ? from() : other.from();
|
||||
TimePoint newTo = endsAfter(other) ? to() : other.to();
|
||||
result = new TimeRangeImpl(newFrom, newTo);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasOpenBeginning() {
|
||||
return from().equals(TimePoint.BeginningOfTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasOpenEnd() {
|
||||
return to().equals(TimePoint.EndOfTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeRange intersection(TimeRange other) {
|
||||
final TimeRange result;
|
||||
if (!intersects(other)) {
|
||||
result = null;
|
||||
} else {
|
||||
TimePoint newFrom = startsBefore(other) ? other.from() : from();
|
||||
TimePoint newTo = endsAfter(other) ? other.to() : to();
|
||||
result = new TimeRangeImpl(newFrom, newTo);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
final boolean result;
|
||||
if (this == obj) {
|
||||
result = true;
|
||||
} else {
|
||||
if (obj instanceof TimeRange) {
|
||||
TimeRange other = (TimeRange) obj;
|
||||
return from().equals(other.from()) && to().equals(other.to());
|
||||
}
|
||||
result = super.equals(obj);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return from() + "-" + to();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user