From b1a90adac9f6e2a609ce1ccd6749462bb5c9adbe Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 12 May 2016 23:33:53 -0700 Subject: altoslib: Store saved state in version-independent format Use AltosHashSet for AltosState so that AltosDroid doesn't lose tracker information when the application is upgraded. Signed-off-by: Keith Packard --- altoslib/AltosMag.java | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'altoslib/AltosMag.java') diff --git a/altoslib/AltosMag.java b/altoslib/AltosMag.java index 3e82f499..c350ae46 100644 --- a/altoslib/AltosMag.java +++ b/altoslib/AltosMag.java @@ -20,12 +20,12 @@ package org.altusmetrum.altoslib_11; import java.util.concurrent.*; import java.io.*; -public class AltosMag implements Cloneable, Serializable { +public class AltosMag implements Cloneable, AltosHashable { public int along; public int across; public int through; - public static double counts_per_gauss = 1090; + public static final double counts_per_gauss = 1090; public static double convert_gauss(double counts) { return counts / counts_per_gauss; @@ -93,4 +93,28 @@ public class AltosMag implements Cloneable, Serializable { break; } } + + public AltosHashSet hashSet() { + AltosHashSet h = new AltosHashSet(); + + h.putInt("along", along); + h.putInt("across", across); + h.putInt("through", through); + return h; + } + + public AltosMag(AltosHashSet h) { + this(); + + along = h.getInt("along", along); + across = h.getInt("across", across); + through = h.getInt("through", through); + } + + public static AltosMag fromHashSet(AltosHashSet h, AltosMag def) { + if (h == null) + return def; + + return new AltosMag(h); + } } -- cgit v1.2.3