Refactoring: move TrackPointDataSet directly into TrackPoint.

This commit is contained in:
Dennis Guse
2020-04-24 23:32:12 +02:00
parent ddb17f61cb
commit 3408ea97f4
15 changed files with 166 additions and 256 deletions
@@ -29,6 +29,10 @@ public class TrackPoint {
private final Location location;
private Float heartRate_bpm = null;
private Float cyclingCadence_rpm = null;
private Float power = null;
public TrackPoint() {
this.location = new Location("");
}
@@ -37,17 +41,13 @@ public class TrackPoint {
this.location = location;
}
public TrackPoint(@NonNull Location location, TrackPointSensorDataSet sensorDataSet) {
this.location = location;
this.sensorDataSet = sensorDataSet;
}
public TrackPoint(@NonNull TrackPoint trackPoint, TrackPointSensorDataSet sensorDataSet) {
public TrackPoint(@NonNull TrackPoint trackPoint) {
this.location = trackPoint.getLocation();
this.sensorDataSet = sensorDataSet;
}
private TrackPointSensorDataSet sensorDataSet = null;
this.heartRate_bpm = trackPoint.getHeartRate_bpm();
this.cyclingCadence_rpm = trackPoint.getCyclingCadence_rpm();
this.power = trackPoint.getPower();
}
public TrackPoint(double latitude, double longitude, Double altitude, long time) {
location = new Location(LocationManager.GPS_PROVIDER);
@@ -88,14 +88,6 @@ public class TrackPoint {
return location;
}
public TrackPointSensorDataSet getSensorDataSet() {
return sensorDataSet;
}
public void setSensorDataSet(TrackPointSensorDataSet sensorDataSet) {
this.sensorDataSet = sensorDataSet;
}
public double getLatitude() {
return location.getLatitude();
}
@@ -180,6 +172,47 @@ public class TrackPoint {
return location.bearingTo(dest);
}
// Sensor data
public boolean hasSensorData() {
return hasHeartRate() || hasCyclingCadence() || hasPower();
}
public boolean hasHeartRate() {
return heartRate_bpm != null && heartRate_bpm > 0;
}
public float getHeartRate_bpm() {
return heartRate_bpm;
}
public void setHeartRate_bpm(Float heartRate_bpm) {
this.heartRate_bpm = heartRate_bpm;
}
public boolean hasCyclingCadence() {
return cyclingCadence_rpm != null;
}
public Float getCyclingCadence_rpm() {
return cyclingCadence_rpm;
}
public void setCyclingCadence_rpm(Float cyclingCadence_rpm) {
this.cyclingCadence_rpm = cyclingCadence_rpm;
}
public boolean hasPower() {
return power != null;
}
public Float getPower() {
return power;
}
public void setPower(Float power) {
this.power = power;
}
@NonNull
@Override
public String toString() {
@@ -1,99 +0,0 @@
package de.dennisguse.opentracks.content.data;
import androidx.annotation.NonNull;
//TODO Rename.
public final class TrackPointSensorDataSet {
private long time_ms;
private Float heartRate_bpm = null;
private Float cyclingCadence = null;
private Float cyclingSpeed = null;
private Float power = null;
public TrackPointSensorDataSet() {
this(System.currentTimeMillis());
}
public TrackPointSensorDataSet(long time_ms) {
this.time_ms = time_ms;
}
public boolean hasHeartRate() {
return heartRate_bpm != null && heartRate_bpm > 0;
}
public float getHeartRate_bpm() {
return heartRate_bpm;
}
public void setHeartRate_bpm(Float heartRate_bpm) {
this.heartRate_bpm = heartRate_bpm;
}
public boolean hasCyclingCadence() {
return cyclingCadence != null;
}
public Float getCyclingCadence_rpm() {
return cyclingCadence;
}
public void setCyclingCadence(Float cyclingCadence) {
this.cyclingCadence = cyclingCadence;
}
public void setCyclingCadence(Integer cyclingCadence) {
this.cyclingCadence = cyclingCadence != null ? cyclingCadence.floatValue() : null;
}
public boolean hasCyclingSpeed() {
return cyclingSpeed != null;
}
public Float getCyclingSpeed() {
return cyclingSpeed;
}
public void setCyclingSpeed(Float cyclingSpeed) {
this.cyclingSpeed = cyclingSpeed;
}
public boolean hasPower() {
return power != null;
}
public Float getPower() {
return power;
}
public void setPower(Float power) {
this.power = power;
}
public long getTime() {
return time_ms;
}
public void setTime(long time_ms) {
this.time_ms = time_ms;
}
/**
* Is the data recent considering the current time.
*
* @param maxAge the maximal age in milliseconds.
*/
public boolean isRecent(long maxAge) {
return time_ms + maxAge > System.currentTimeMillis();
}
@NonNull
@Override
public String toString() {
return "time=" + getTime()
+ (hasHeartRate() ? " heart=" + getHeartRate_bpm() : "")
+ (hasCyclingCadence() ? " cyclingCad=" + getCyclingCadence_rpm() : "")
+ (hasCyclingSpeed() ? " cyclingSpeed=" + getCyclingSpeed() : "");
}
}