X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altoslib%2FAltosMag.java;h=ec98882f2e0513629fa3e25395d814b120a9b757;hb=1b5ea911049a8afae6af475a4a2bf62a6e3aa57b;hp=3e82f49911299c69b568711630232f781d575303;hpb=97adfff4cfb67c17a96f3ff46606b4e439422b01;p=fw%2Faltos diff --git a/altoslib/AltosMag.java b/altoslib/AltosMag.java index 3e82f499..ec98882f 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, 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; @@ -93,4 +93,52 @@ 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 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); + } }