diff options
author | Keith Packard <keithp@keithp.com> | 2016-06-15 22:40:27 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2016-06-15 22:40:27 -0700 |
commit | 1b5ea911049a8afae6af475a4a2bf62a6e3aa57b (patch) | |
tree | 7f896e587da5e7911b7b5a42aade1b7692670200 /altoslib/AltosMag.java | |
parent | 1de8b6c340cec0b5a327392686c5a4e00f201e98 (diff) |
altoslib: Switch preserved state format to JSON
This is much easier to debug than the icky strings with backslashes everywhere.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib/AltosMag.java')
-rw-r--r-- | altoslib/AltosMag.java | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/altoslib/AltosMag.java b/altoslib/AltosMag.java index c350ae46..ec98882f 100644 --- a/altoslib/AltosMag.java +++ b/altoslib/AltosMag.java @@ -20,7 +20,7 @@ package org.altusmetrum.altoslib_11; import java.util.concurrent.*; import java.io.*; -public class AltosMag implements Cloneable, AltosHashable { +public class AltosMag implements Cloneable, AltosHashable, AltosJsonable { public int along; public int across; public int through; @@ -103,6 +103,15 @@ public class AltosMag implements Cloneable, AltosHashable { 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(); @@ -117,4 +126,19 @@ public class AltosMag implements Cloneable, AltosHashable { 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); + } } |