X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altoslib%2FAltosMag.java;h=ec98882f2e0513629fa3e25395d814b120a9b757;hb=1b5ea911049a8afae6af475a4a2bf62a6e3aa57b;hp=1fa8877b9c639b4d1b5bdd714be5687424dd70be;hpb=00ae706dab6e8fddef4c5730a17c433a022228b7;p=fw%2Faltos diff --git a/altoslib/AltosMag.java b/altoslib/AltosMag.java index 1fa8877b..ec98882f 100644 --- a/altoslib/AltosMag.java +++ b/altoslib/AltosMag.java @@ -15,16 +15,17 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_5; +package org.altusmetrum.altoslib_11; import java.util.concurrent.*; +import java.io.*; -public class AltosMag implements Cloneable { +public class AltosMag implements Cloneable, AltosHashable, AltosJsonable { 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; @@ -92,4 +93,52 @@ public class AltosMag implements Cloneable { break; } } + + public AltosHashSet hashSet() { + AltosHashSet h = new AltosHashSet(); + + h.putInt("along", along); + h.putInt("across", across); + h.putInt("through", through); + return h; + } + + public AltosJson json() { + AltosJson j = new AltosJson(); + + j.put("along", along); + j.put("across", across); + j.put("through", through); + return j; + } + + 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); + } + + public AltosMag(AltosJson j) { + this(); + + along = j.get_int("along", along); + across = j.get_int("across", across); + through = j.get_int("through", through); + } + + public static AltosMag fromJson(AltosJson j, AltosMag def) { + if (j == null) + return def; + + return new AltosMag(j); + } }