Distance.ZERO as constant.

This commit is contained in:
Dennis Guse
2025-11-02 08:32:04 +01:00
parent fffeb40200
commit 6e4d46a14d
13 changed files with 30 additions and 28 deletions
@@ -7,6 +7,8 @@ import de.dennisguse.opentracks.settings.UnitSystem;
public record Distance(double distance_m) {
public static Distance ZERO = Distance.of(0);
public static Distance of(double distance_m) {
return new Distance(distance_m);
}
@@ -124,7 +124,7 @@ public class GPXTrackExporter implements TrackExporter {
private void writeTrackPoints(Track track) throws InterruptedException {
boolean wroteTrack = false;
boolean wroteSegment = false;
Distance trackDistance = Distance.of(0);
Distance trackDistance = Distance.ZERO;
LinkedList<TrackPoint> sensorPoints = new LinkedList<>();
@@ -383,7 +383,7 @@ public class GPXTrackExporter implements TrackExporter {
if (cumulativeDistance != null) {
return cumulativeDistance;
}
return Distance.of(0);
return Distance.ZERO;
}
private Double cumulateSensorData(TrackPoint trackPoint, List<TrackPoint> sensorPoints, Function<TrackPoint, Double> map) {
@@ -56,20 +56,20 @@ public class AggregatorCyclingDistanceSpeed extends Aggregator<BluetoothHandlerC
@Override
protected void resetImmediate() {
aggregatedValue = new Data(Distance.of(0), aggregatedValue.distanceOverall, Speed.ZERO);
aggregatedValue = new Data(Distance.ZERO, aggregatedValue.distanceOverall, Speed.ZERO);
}
@Override
public void resetAggregated() {
if (aggregatedValue != null) {
aggregatedValue = new Data(aggregatedValue.distance, Distance.of(0), aggregatedValue.speed);
aggregatedValue = new Data(aggregatedValue.distance, Distance.ZERO, aggregatedValue.speed);
}
}
@NonNull
@Override
protected Data getNoneValue() {
return new Data(Distance.of(0), Distance.of(0), Speed.ZERO);
return new Data(Distance.ZERO, Distance.ZERO, Speed.ZERO);
}
public void setWheelCircumference(Distance wheelCircumference) {
@@ -43,14 +43,14 @@ public final class AggregatorRunning extends Aggregator<BluetoothHandlerRunningS
@Override
public void resetAggregated() {
if (aggregatedValue != null) {
aggregatedValue = new Data(aggregatedValue.speed, aggregatedValue.cadence, Distance.of(0));
aggregatedValue = new Data(aggregatedValue.speed, aggregatedValue.cadence, Distance.ZERO);
}
}
@NonNull
@Override
protected Data getNoneValue() {
return new Data(Speed.ZERO, Cadence.of(0f), Distance.of(0));
return new Data(Speed.ZERO, Cadence.of(0f), Distance.ZERO);
}
public record Data(Speed speed, Cadence cadence, @NonNull Distance distance) {
@@ -187,7 +187,7 @@ public class SegmentStatisticUpdater {
totalTime = Duration.ofSeconds(0);
movingTime = Duration.ofSeconds(0);
totalDistance = Distance.of(0);
totalDistance = Distance.ZERO;
maxSpeed = Speed.ZERO;
totalAltitudeGain_m = null;
totalAltitudeLoss_m = null;
@@ -65,7 +65,7 @@ public class AggregatedStatistics {
this.countTracks = tracks.size();
totalMovingTime = tracks.stream().map(t -> t.getStatistics().movingTime()).reduce(Duration.ZERO, Duration::plus);
totalDistance = tracks.stream().map(t -> t.getStatistics().totalDistance()).reduce(Distance.of(0), Distance::plus);
totalDistance = tracks.stream().map(t -> t.getStatistics().totalDistance()).reduce(Distance.ZERO, Distance::plus);
maxSpeed = tracks.stream().map(t -> t.getStatistics().maxSpeed()).max((o1, o2) -> (int) (o1.speed_mps() - o2.speed_mps())).orElse(Speed.ZERO);
avgMovingSpeed = Speed.of(totalDistance, totalMovingTime);
}
@@ -45,7 +45,7 @@ public class SettingsCustomLayoutEditAdapter extends RecyclerView.Adapter<Recycl
Duration.ofMinutes(0),
Duration.ofMinutes(0),
Distance.of(0),
Distance.ZERO,
Speed.ZERO,
null,
@@ -103,7 +103,7 @@ public class IntervalStatisticsUpdater {
//TODO Could be replaced with Statistics?
@Deprecated
private static class Interval {
private Distance distance = Distance.of(0);
private Distance distance = Distance.ZERO;
private Duration time = Duration.ofSeconds(0);
private Float gain_m;
private Float loss_m;