altoslib: Store saved state in version-independent format
[fw/altos] / altoslib / AltosMag.java
index 3e82f49911299c69b568711630232f781d575303..c350ae46392f4ddd637b58fe8f34c0c825a9faf1 100644 (file)
@@ -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);
+       }
 }