1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-14 09:00:04 +02:00
Gadgetbridge/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/GBToStringBuilder.java
José Rebelo 09c44f05f8 Garmin: Improve fit parsing
* Remove the dependency on PredefinedLocalMessage from generic fit parsing code
* Standardize toString methods, omit types for known fields
* Return null on unknown field number or names, instead of crashing
* Map more Global FIT messages (device info, monitoring, sleep stages, sleep stats, stress level)
* Prioritize "timestamp" over "253_timestamp" if specified explicitly in the global message definition
* Introduce RecordData wrappers for each global message, allowing us to have proper types when getting data. If missing or unknown, the getter returns null. All classes are auto-generated by the FitCodeGen.
* Persist a list of RecordData, instead of a Map from RecordDefinition
* Fix parsing of compressed timestamps - keep them in computedTimestamp on each data record
* Use timestamp16 if available in Monitoring records
2024-05-01 23:35:16 +01:00

51 lines
1.5 KiB
Java

package nodomain.freeyourgadget.gadgetbridge.util;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class GBToStringBuilder extends ToStringBuilder {
public static final GBToStringStyle STYLE = new GBToStringStyle();
private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US);
public GBToStringBuilder(final Object object) {
super(object, STYLE);
}
public static class GBToStringStyle extends ToStringStyle {
public GBToStringStyle() {
super();
this.setUseShortClassName(true);
this.setUseIdentityHashCode(false);
this.setContentStart("{");
this.setContentEnd("}");
this.setArrayStart("[");
this.setArrayEnd("]");
this.setFieldSeparator(", ");
this.setFieldNameValueSeparator("=");
this.setNullText("null");
}
@Override
public void append(final StringBuffer buffer, final String fieldName, final Object value, final Boolean fullDetail) {
// omit nulls
if (value != null) {
if (value instanceof Date) {
super.append(buffer, fieldName, SDF.format(value), fullDetail);
} else {
super.append(buffer, fieldName, value, fullDetail);
}
}
}
}
}