39 lines
1.2 KiB
Java
39 lines
1.2 KiB
Java
package net.heartshield.data;
|
|
|
|
import java.io.Serializable;
|
|
|
|
/**
|
|
* Primary key for identifying a Measurement.
|
|
*
|
|
* @author David Madl (git@abanbytes.eu)
|
|
* @date 2017-04-10
|
|
*/
|
|
public class MeasurementId implements Serializable {
|
|
public String appId;
|
|
public long startTime;
|
|
|
|
public MeasurementId(String appId, long startTime) {
|
|
this.appId = appId;
|
|
this.startTime = startTime;
|
|
}
|
|
|
|
public static MeasurementId parse(String measurementId) {
|
|
int underscore = measurementId.indexOf("_");
|
|
if(underscore == -1)
|
|
throw new IllegalArgumentException("could not parse measurementId " + measurementId + " since it did not contain '_'.");
|
|
return new MeasurementId(measurementId.substring(underscore+1), Long.parseLong(measurementId.substring(0, underscore)));
|
|
}
|
|
|
|
public String toString() {
|
|
return startTime + "_" + appId;
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object obj) {
|
|
if(obj == null || !(obj instanceof MeasurementId))
|
|
return false;
|
|
MeasurementId other = (MeasurementId) obj;
|
|
return (this.startTime == other.startTime && this.appId.equals(other.appId));
|
|
}
|
|
}
|