forked from upstream-mirrors/OpenTracks
Introduced value objects for heartrate, cadence, and power.
Fixes #896.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package de.dennisguse.opentracks.data.models;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Cadence {
|
||||
|
||||
public static Cadence of(float value) {
|
||||
return new Cadence(value);
|
||||
}
|
||||
|
||||
private final float value;
|
||||
|
||||
private Cadence(float value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public float getRPM() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Cadence cadence = (Cadence) o;
|
||||
return Float.compare(cadence.value, value) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(value);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Cadence{" +
|
||||
"value=" + value + " rpm" +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package de.dennisguse.opentracks.data.models;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class HeartRate {
|
||||
|
||||
public static HeartRate of(float value) {
|
||||
return new HeartRate(value);
|
||||
}
|
||||
|
||||
private final float value;
|
||||
|
||||
private HeartRate(float value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public float getBPM() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
HeartRate heartRate = (HeartRate) o;
|
||||
return Float.compare(heartRate.value, value) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(value);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HeartRate{" +
|
||||
"value=" + value + " bpm" +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package de.dennisguse.opentracks.data.models;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Power {
|
||||
|
||||
public static Power of(float value) {
|
||||
return new Power(value);
|
||||
}
|
||||
|
||||
private final float value;
|
||||
|
||||
private Power(float value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public float getW() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Power power = (Power) o;
|
||||
return Float.compare(power.value, value) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(value);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Power{" +
|
||||
"value=" + value + " W" +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -91,9 +91,9 @@ public class TrackPoint {
|
||||
@NonNull
|
||||
private Type type;
|
||||
|
||||
private Float heartRate_bpm = null;
|
||||
private Float cadence_rpm = null;
|
||||
private Float power = null;
|
||||
private HeartRate heartRate = null;
|
||||
private Cadence cadence = null;
|
||||
private Power power = null;
|
||||
private Float altitudeGain_m = null;
|
||||
private Float altitudeLoss_m = null;
|
||||
|
||||
@@ -382,44 +382,56 @@ public class TrackPoint {
|
||||
}
|
||||
|
||||
public boolean hasHeartRate() {
|
||||
return heartRate_bpm != null && heartRate_bpm > 0;
|
||||
return heartRate != null;
|
||||
}
|
||||
|
||||
public float getHeartRate_bpm() {
|
||||
return heartRate_bpm;
|
||||
public HeartRate getHeartRate() {
|
||||
return heartRate;
|
||||
}
|
||||
|
||||
public TrackPoint setHeartRate_bpm(Float heartRate_bpm) {
|
||||
this.heartRate_bpm = heartRate_bpm;
|
||||
public TrackPoint setHeartRate(HeartRate heartRate) {
|
||||
this.heartRate = heartRate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TrackPoint setHeartRate(float heartRate) {
|
||||
return setHeartRate(HeartRate.of(heartRate));
|
||||
}
|
||||
|
||||
public boolean hasCadence() {
|
||||
return cadence_rpm != null;
|
||||
return cadence != null;
|
||||
}
|
||||
|
||||
public float getCadence_rpm() {
|
||||
return cadence_rpm;
|
||||
public Cadence getCadence() {
|
||||
return cadence;
|
||||
}
|
||||
|
||||
public TrackPoint setCadence_rpm(Float cadence_rpm) {
|
||||
this.cadence_rpm = cadence_rpm;
|
||||
public TrackPoint setCadence(Cadence cadence) {
|
||||
this.cadence = cadence;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TrackPoint setCadence(float cadence) {
|
||||
return setCadence(Cadence.of(cadence));
|
||||
}
|
||||
|
||||
public boolean hasPower() {
|
||||
return power != null;
|
||||
}
|
||||
|
||||
public float getPower() {
|
||||
public Power getPower() {
|
||||
return power;
|
||||
}
|
||||
|
||||
public TrackPoint setPower(Float power) {
|
||||
public TrackPoint setPower(Power power) {
|
||||
this.power = power;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TrackPoint setPower(float power) {
|
||||
return setPower(Power.of(power));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
@@ -434,8 +446,8 @@ public class TrackPoint {
|
||||
", bearing=" + bearing +
|
||||
", sensorDistance=" + sensorDistance +
|
||||
", type=" + type +
|
||||
", heartRate_bpm=" + heartRate_bpm +
|
||||
", cadence_rpm=" + cadence_rpm +
|
||||
", heartRate_bpm=" + heartRate +
|
||||
", cadence_rpm=" + cadence +
|
||||
", power=" + power +
|
||||
", altitudeGain_m=" + altitudeGain_m +
|
||||
", altitudeLoss_m=" + altitudeLoss_m +
|
||||
|
||||
Reference in New Issue
Block a user