mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
Speed.ZERO as constant.
This commit is contained in:
@@ -29,7 +29,7 @@ public class ChartPointTest {
|
||||
Statistics statistics = new Statistics(null, null, Duration.ofSeconds(1000), null, null, null, null, null, null, null);
|
||||
|
||||
// when
|
||||
ChartPoint point = ChartPoint.create(statistics, TrackStubUtils.createDefaultTrackPoint(), Speed.of(0), false, UnitSystem.IMPERIAL_FEET);
|
||||
ChartPoint point = ChartPoint.create(statistics, TrackStubUtils.createDefaultTrackPoint(), Speed.ZERO, false, UnitSystem.IMPERIAL_FEET);
|
||||
|
||||
// then
|
||||
assertEquals(1000000, (long) point.timeOrDistance());
|
||||
@@ -41,7 +41,7 @@ public class ChartPointTest {
|
||||
Statistics statistics = new Statistics(null, null, null, null, Distance.of(1000), null, null, null, null, null);
|
||||
|
||||
// when
|
||||
ChartPoint point = ChartPoint.create(statistics, TrackStubUtils.createDefaultTrackPoint(), Speed.of(0), true, UnitSystem.METRIC);
|
||||
ChartPoint point = ChartPoint.create(statistics, TrackStubUtils.createDefaultTrackPoint(), Speed.ZERO, true, UnitSystem.METRIC);
|
||||
|
||||
// then
|
||||
assertEquals(1, (long) point.timeOrDistance());
|
||||
|
||||
@@ -28,7 +28,7 @@ public class SpeedFormatterTest {
|
||||
assertEquals("4:59", formatter.getSpeedParts(Speed.of(3.34)).first);
|
||||
assertEquals("5:00", formatter.getSpeedParts(Speed.of(3.33)).first);
|
||||
|
||||
assertEquals("min/km", formatter.getSpeedParts(Speed.zero()).second);
|
||||
assertEquals("min/km", formatter.getSpeedParts(Speed.ZERO).second);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -39,7 +39,7 @@ public class SpeedFormatterTest {
|
||||
.build(context);
|
||||
|
||||
assertEquals("8:02", formatter.getSpeedParts(Speed.of(3.34)).first);
|
||||
assertEquals("min/mi", formatter.getSpeedParts(Speed.zero()).second);
|
||||
assertEquals("min/mi", formatter.getSpeedParts(Speed.ZERO).second);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -50,7 +50,7 @@ public class SpeedFormatterTest {
|
||||
.build(context);
|
||||
|
||||
assertEquals("9:14", formatter.getSpeedParts(Speed.of(3.34)).first);
|
||||
assertEquals("min/NM", formatter.getSpeedParts(Speed.zero()).second);
|
||||
assertEquals("min/NM", formatter.getSpeedParts(Speed.ZERO).second);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,7 +61,7 @@ public class SpeedFormatterTest {
|
||||
.build(context);
|
||||
|
||||
assertEquals("11.9", formatter.getSpeedParts(Speed.of(3.31)).first);
|
||||
assertEquals("km/h", formatter.getSpeedParts(Speed.zero()).second);
|
||||
assertEquals("km/h", formatter.getSpeedParts(Speed.ZERO).second);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,7 +72,7 @@ public class SpeedFormatterTest {
|
||||
.build(context);
|
||||
|
||||
assertEquals("7.5", formatter.getSpeedParts(Speed.of(3.34)).first);
|
||||
assertEquals("mph", formatter.getSpeedParts(Speed.zero()).second);
|
||||
assertEquals("mph", formatter.getSpeedParts(Speed.ZERO).second);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,7 +83,7 @@ public class SpeedFormatterTest {
|
||||
.build(context);
|
||||
|
||||
assertEquals("6.5", formatter.getSpeedParts(Speed.of(3.34)).first);
|
||||
assertEquals("kn", formatter.getSpeedParts(Speed.zero()).second);
|
||||
assertEquals("kn", formatter.getSpeedParts(Speed.ZERO).second);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+4
-4
@@ -203,7 +203,7 @@ public class KMLTrackImporterTest {
|
||||
12.340057, 1.23405, null,
|
||||
Altitude.WGS84.of(421.8070983886719), null,
|
||||
null,
|
||||
Speed.of(0))),
|
||||
Speed.ZERO)),
|
||||
// created resume trackpoint with time of next valid trackpoint
|
||||
new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC,
|
||||
new Position(
|
||||
@@ -211,21 +211,21 @@ public class KMLTrackImporterTest {
|
||||
12.340057, 1.23405, null,
|
||||
Altitude.WGS84.of(419.93902587890625), null,
|
||||
null,
|
||||
Speed.of(0))),
|
||||
Speed.ZERO)),
|
||||
new TrackPoint(TrackPoint.Type.TRACKPOINT,
|
||||
new Position(
|
||||
Instant.parse("2020-11-28T17:06:56.905Z"),
|
||||
12.340057, 1.23405, null,
|
||||
Altitude.WGS84.of(419.9036560058594), null,
|
||||
null,
|
||||
Speed.of(0))),
|
||||
Speed.ZERO)),
|
||||
new TrackPoint(TrackPoint.Type.TRACKPOINT,
|
||||
new Position(
|
||||
Instant.parse("2020-11-28T17:07:20.870Z"),
|
||||
12.340082, 1.234046, null,
|
||||
Altitude.WGS84.of(417.99432373046875), null,
|
||||
null,
|
||||
Speed.of(0)))
|
||||
Speed.ZERO))
|
||||
), importedTrackPoints);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -125,6 +125,6 @@ public class SensorDataCyclingTest {
|
||||
// TODO See #953
|
||||
// assertEquals(2, current.getValue().getDistance().toM(), 0.01);
|
||||
// assertEquals(2, current.getValue().getSpeed().toMPS(), 0.01);
|
||||
assertEquals(new AggregatorCyclingDistanceSpeed.Data(Distance.of(0), Distance.of(0), Speed.of(0)), current.getAggregatedValue(Instant.MIN));
|
||||
assertEquals(new AggregatorCyclingDistanceSpeed.Data(Distance.of(0), Distance.of(0), Speed.ZERO), current.getAggregatedValue(Instant.MIN));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -44,7 +44,7 @@ public class TrackRecordingServiceNotificationManagerTest {
|
||||
null, null, Distance.of(999f),
|
||||
Altitude.WGS84.of(10), null,
|
||||
null,
|
||||
Speed.of(0))
|
||||
Speed.ZERO)
|
||||
);
|
||||
|
||||
when(notificationCompatBuilder.setOnlyAlertOnce(anyBoolean()))
|
||||
|
||||
+7
-7
@@ -110,7 +110,7 @@ public class TrackRecordingServiceRecordingTest {
|
||||
|
||||
|
||||
// then
|
||||
assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(startTime), Duration.ZERO, Duration.ZERO, Distance.of(0), Speed.zero(), new AltitudeExtremities(0.0, 0.0), null, null, null)
|
||||
assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(startTime), Duration.ZERO, Duration.ZERO, Distance.of(0), Speed.ZERO, new AltitudeExtremities(0.0, 0.0), null, null, null)
|
||||
, contentProviderUtils.getTrack(trackId).getStatistics());
|
||||
|
||||
new TrackPointAssert().assertEquals(List.of(
|
||||
@@ -124,7 +124,7 @@ public class TrackRecordingServiceRecordingTest {
|
||||
service.endCurrentTrack();
|
||||
|
||||
// then
|
||||
assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(stopTime), Duration.ofSeconds(1), Duration.ofSeconds(1), Distance.of(0), Speed.zero(), new AltitudeExtremities(0.0, 0.0), new AltitudeGainLoss(0, 0), null, null)
|
||||
assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(stopTime), Duration.ofSeconds(1), Duration.ofSeconds(1), Distance.of(0), Speed.ZERO, new AltitudeExtremities(0.0, 0.0), new AltitudeGainLoss(0, 0), null, null)
|
||||
, contentProviderUtils.getTrack(trackId).getStatistics());
|
||||
|
||||
new TrackPointAssert().assertEquals(List.of(
|
||||
@@ -199,7 +199,7 @@ public class TrackRecordingServiceRecordingTest {
|
||||
service.endCurrentTrack();
|
||||
|
||||
// then
|
||||
assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(pauseTime), Duration.ofSeconds(1), Duration.ofSeconds(1), Distance.of(0), Speed.zero(), new AltitudeExtremities(0.0, 0.0), new AltitudeGainLoss(0, 0), null, null)
|
||||
assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(pauseTime), Duration.ofSeconds(1), Duration.ofSeconds(1), Distance.of(0), Speed.ZERO, new AltitudeExtremities(0.0, 0.0), new AltitudeGainLoss(0, 0), null, null)
|
||||
, contentProviderUtils.getTrack(trackId).getStatistics());
|
||||
|
||||
new TrackPointAssert().assertEquals(List.of(
|
||||
@@ -214,7 +214,7 @@ public class TrackRecordingServiceRecordingTest {
|
||||
service.resumeTrack(trackId);
|
||||
|
||||
// then
|
||||
assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(resumeTime), Duration.ofSeconds(1), Duration.ofSeconds(1), Distance.of(0), Speed.zero(), new AltitudeExtremities(0.0, 0.0), new AltitudeGainLoss(0, 0), null, null)
|
||||
assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(resumeTime), Duration.ofSeconds(1), Duration.ofSeconds(1), Distance.of(0), Speed.ZERO, new AltitudeExtremities(0.0, 0.0), new AltitudeGainLoss(0, 0), null, null)
|
||||
, contentProviderUtils.getTrack(trackId).getStatistics());
|
||||
|
||||
new TrackPointAssert().assertEquals(List.of(
|
||||
@@ -538,7 +538,7 @@ public class TrackRecordingServiceRecordingTest {
|
||||
sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 100, 15);
|
||||
|
||||
// then
|
||||
Statistics startStatistics = new Statistics(Instant.parse(startTime), Instant.parse(startTime), Duration.ofSeconds(0), Duration.ofSeconds(0), Distance.of(0), Speed.of(0), new AltitudeExtremities(0.0, 0.0), null, null, null);
|
||||
Statistics startStatistics = new Statistics(Instant.parse(startTime), Instant.parse(startTime), Duration.ofSeconds(0), Duration.ofSeconds(0), Distance.of(0), Speed.ZERO, new AltitudeExtremities(0.0, 0.0), null, null, null);
|
||||
assertEquals(startStatistics, contentProviderUtils.getTrack(trackId).getStatistics());
|
||||
|
||||
|
||||
@@ -556,7 +556,7 @@ public class TrackRecordingServiceRecordingTest {
|
||||
service.endCurrentTrack();
|
||||
|
||||
// then
|
||||
assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(stopTime), Duration.ofSeconds(10), Duration.ofSeconds(10), Distance.of(0), Speed.of(0), new AltitudeExtremities(0.0, 0.0), new AltitudeGainLoss(0, 0), null, null)
|
||||
assertEquals(new Statistics(Instant.parse(startTime), Instant.parse(stopTime), Duration.ofSeconds(10), Duration.ofSeconds(10), Distance.of(0), Speed.ZERO, new AltitudeExtremities(0.0, 0.0), new AltitudeGainLoss(0, 0), null, null)
|
||||
, contentProviderUtils.getTrack(trackId).getStatistics());
|
||||
|
||||
// then
|
||||
@@ -730,7 +730,7 @@ public class TrackRecordingServiceRecordingTest {
|
||||
45.001, 35d, Distance.of(1),
|
||||
null, null,
|
||||
null,
|
||||
Speed.of(0))) //Sensor data is now outdated, but we do not fall back to GPS.
|
||||
Speed.ZERO)) //Sensor data is now outdated, but we do not fall back to GPS.
|
||||
.setSensorDistance(Distance.of(0))
|
||||
), TestDataUtil.getTrackPoints(contentProviderUtils, trackId));
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ public class TrackStatisticsUpdaterTest {
|
||||
assertEquals(Duration.ZERO, statistics.getTotalTime());
|
||||
assertEquals(Duration.ZERO, statistics.getMovingTime());
|
||||
|
||||
assertEquals(Speed.of(0), statistics.getAverageSpeed());
|
||||
assertEquals(Speed.of(0), statistics.getAverageMovingSpeed());
|
||||
assertEquals(Speed.of(0), statistics.getMaxSpeed());
|
||||
assertEquals(Speed.ZERO, statistics.getAverageSpeed());
|
||||
assertEquals(Speed.ZERO, statistics.getAverageMovingSpeed());
|
||||
assertEquals(Speed.ZERO, statistics.getMaxSpeed());
|
||||
|
||||
assertNull(statistics.getTotalAltitudeGain());
|
||||
assertNull(statistics.getTotalAltitudeLoss());
|
||||
@@ -64,9 +64,9 @@ public class TrackStatisticsUpdaterTest {
|
||||
assertEquals(Duration.ZERO, statistics.getTotalTime());
|
||||
assertEquals(Duration.ZERO, statistics.getMovingTime());
|
||||
|
||||
assertEquals(Speed.of(0), statistics.getAverageSpeed());
|
||||
assertEquals(Speed.of(0), statistics.getAverageMovingSpeed());
|
||||
assertEquals(Speed.of(0), statistics.getMaxSpeed());
|
||||
assertEquals(Speed.ZERO, statistics.getAverageSpeed());
|
||||
assertEquals(Speed.ZERO, statistics.getAverageMovingSpeed());
|
||||
assertEquals(Speed.ZERO, statistics.getMaxSpeed());
|
||||
|
||||
assertNull(statistics.getTotalAltitudeGain());
|
||||
assertNull(statistics.getTotalAltitudeLoss());
|
||||
|
||||
@@ -6,9 +6,11 @@ import de.dennisguse.opentracks.settings.UnitSystem;
|
||||
|
||||
public record Speed(double speed_mps) {
|
||||
|
||||
public static Speed ZERO = Speed.of(0);
|
||||
|
||||
public static Speed of(Distance distance, Duration duration) {
|
||||
if (duration.isZero()) {
|
||||
return zero();
|
||||
return ZERO;
|
||||
}
|
||||
|
||||
return new Speed(distance.toM() / (duration.toMillis() / (double) Duration.ofSeconds(1).toMillis()));
|
||||
@@ -26,11 +28,6 @@ public record Speed(double speed_mps) {
|
||||
return of(Distance.ofKilometer(speed_kmh), Duration.ofHours(1));
|
||||
}
|
||||
|
||||
//TODO Like Duration.ZERO
|
||||
public static Speed zero() {
|
||||
return of(0.0);
|
||||
}
|
||||
|
||||
public static Speed max(Speed speed1, Speed speed2) {
|
||||
if (speed1.greaterThan(speed2)) {
|
||||
return speed1;
|
||||
@@ -40,7 +37,7 @@ public record Speed(double speed_mps) {
|
||||
}
|
||||
|
||||
public boolean isZero() {
|
||||
return speed_mps == 0;
|
||||
return this.equals(ZERO);
|
||||
}
|
||||
|
||||
public boolean isInvalid() {
|
||||
|
||||
@@ -50,7 +50,7 @@ public class SpeedFormatter {
|
||||
String unitString = resources.getString(unitId);
|
||||
|
||||
if (speed == null) {
|
||||
speed = Speed.zero();
|
||||
speed = Speed.ZERO;
|
||||
}
|
||||
|
||||
if (reportSpeedOrPace) {
|
||||
|
||||
@@ -36,7 +36,7 @@ public record Statistics(
|
||||
|
||||
public Speed getAverageSpeed() {
|
||||
if (totalTime.isZero()) {
|
||||
return Speed.of(0);
|
||||
return Speed.ZERO;
|
||||
}
|
||||
return Speed.of(totalDistance, totalTime);
|
||||
}
|
||||
|
||||
+2
-2
@@ -56,7 +56,7 @@ public class AggregatorCyclingDistanceSpeed extends Aggregator<BluetoothHandlerC
|
||||
|
||||
@Override
|
||||
protected void resetImmediate() {
|
||||
aggregatedValue = new Data(Distance.of(0), aggregatedValue.distanceOverall, Speed.zero());
|
||||
aggregatedValue = new Data(Distance.of(0), aggregatedValue.distanceOverall, Speed.ZERO);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,7 +69,7 @@ public class AggregatorCyclingDistanceSpeed extends Aggregator<BluetoothHandlerC
|
||||
@NonNull
|
||||
@Override
|
||||
protected Data getNoneValue() {
|
||||
return new Data(Distance.of(0), Distance.of(0), Speed.zero());
|
||||
return new Data(Distance.of(0), Distance.of(0), Speed.ZERO);
|
||||
}
|
||||
|
||||
public void setWheelCircumference(Distance wheelCircumference) {
|
||||
|
||||
@@ -37,7 +37,7 @@ public final class AggregatorRunning extends Aggregator<BluetoothHandlerRunningS
|
||||
|
||||
@Override
|
||||
protected void resetImmediate() {
|
||||
aggregatedValue = new Data(Speed.zero(), Cadence.of(0f), aggregatedValue.distance);
|
||||
aggregatedValue = new Data(Speed.ZERO, Cadence.of(0f), aggregatedValue.distance);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,7 +50,7 @@ public final class AggregatorRunning extends Aggregator<BluetoothHandlerRunningS
|
||||
@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.of(0));
|
||||
}
|
||||
|
||||
public record Data(Speed speed, Cadence cadence, @NonNull Distance distance) {
|
||||
|
||||
@@ -188,7 +188,7 @@ public class SegmentStatisticUpdater {
|
||||
totalTime = Duration.ofSeconds(0);
|
||||
movingTime = Duration.ofSeconds(0);
|
||||
totalDistance = Distance.of(0);
|
||||
maxSpeed = Speed.zero();
|
||||
maxSpeed = Speed.ZERO;
|
||||
totalAltitudeGain_m = null;
|
||||
totalAltitudeLoss_m = null;
|
||||
|
||||
@@ -305,7 +305,7 @@ public class SegmentStatisticUpdater {
|
||||
*/
|
||||
public Speed getAverageSpeed() {
|
||||
if (totalTime.isZero()) {
|
||||
return Speed.of(0);
|
||||
return Speed.ZERO;
|
||||
}
|
||||
return Speed.of(totalDistance.toM() / totalTime.getSeconds());
|
||||
}
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ public class AggregatedStatistics {
|
||||
|
||||
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);
|
||||
maxSpeed = tracks.stream().map(t -> t.getStatistics().maxSpeed()).max((o1, o2) -> (int) (o1.speed_mps() - o2.speed_mps())).orElse(Speed.zero());
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -46,7 +46,7 @@ public class SettingsCustomLayoutEditAdapter extends RecyclerView.Adapter<Recycl
|
||||
Duration.ofMinutes(0),
|
||||
|
||||
Distance.of(0),
|
||||
Speed.of(0),
|
||||
Speed.ZERO,
|
||||
null,
|
||||
|
||||
new AltitudeGainLoss(0f, 0f),
|
||||
@@ -64,7 +64,7 @@ public class SettingsCustomLayoutEditAdapter extends RecyclerView.Adapter<Recycl
|
||||
Altitude.EGM2008.of(0),
|
||||
null,
|
||||
null,
|
||||
Speed.zero()
|
||||
Speed.ZERO
|
||||
);
|
||||
|
||||
demoData = new RecordingData(track, new TrackPoint(TrackPoint.Type.TRACKPOINT, position), null, statistics);
|
||||
|
||||
Reference in New Issue
Block a user