@Test public void fromJSONTest() throws JSONException { TriggerCOB t = new TriggerCOB().setValue(4).comparator(Comparator.Compare.IS_EQUAL); TriggerCOB t2 = (TriggerCOB) Trigger.instantiate(new JSONObject(t.toJSON())); Assert.assertEquals(Comparator.Compare.IS_EQUAL, t2.getComparator().getValue()); Assert.assertEquals(4, t2.getValue(), 0.01d); }
@Override Trigger fromJSON(String data) { try { JSONObject d = new JSONObject(data); value.setValue(JsonHelper.safeGetDouble(d, "carbs")); lastRun = JsonHelper.safeGetLong(d, "lastRun"); comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator"))); } catch (Exception e) { log.error("Unhandled exception", e); } return this; }
TriggerCOB extends Trigger { @Override Trigger fromJSON(String data) { try { JSONObject d = new JSONObject(data); value.setValue(JsonHelper.safeGetDouble(d, "carbs")); lastRun = JsonHelper.safeGetLong(d, "lastRun"); comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator"))); } catch (Exception e) { log.error("Unhandled exception", e); } return this; } }
TriggerCOB extends Trigger { @Override Trigger fromJSON(String data) { try { JSONObject d = new JSONObject(data); value.setValue(JsonHelper.safeGetDouble(d, "carbs")); lastRun = JsonHelper.safeGetLong(d, "lastRun"); comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator"))); } catch (Exception e) { log.error("Unhandled exception", e); } return this; } TriggerCOB(); private  TriggerCOB(TriggerCOB triggerCOB); }
TriggerCOB extends Trigger { @Override Trigger fromJSON(String data) { try { JSONObject d = new JSONObject(data); value.setValue(JsonHelper.safeGetDouble(d, "carbs")); lastRun = JsonHelper.safeGetLong(d, "lastRun"); comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator"))); } catch (Exception e) { log.error("Unhandled exception", e); } return this; } TriggerCOB(); private  TriggerCOB(TriggerCOB triggerCOB); double getValue(); Comparator getComparator(); @Override synchronized boolean shouldRun(); @Override synchronized String toJSON(); @Override int friendlyName(); @Override String friendlyDescription(); @Override Optional<Integer> icon(); @Override Trigger duplicate(); @Override void generateDialog(LinearLayout root, FragmentManager fragmentManager); }
TriggerCOB extends Trigger { @Override Trigger fromJSON(String data) { try { JSONObject d = new JSONObject(data); value.setValue(JsonHelper.safeGetDouble(d, "carbs")); lastRun = JsonHelper.safeGetLong(d, "lastRun"); comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator"))); } catch (Exception e) { log.error("Unhandled exception", e); } return this; } TriggerCOB(); private  TriggerCOB(TriggerCOB triggerCOB); double getValue(); Comparator getComparator(); @Override synchronized boolean shouldRun(); @Override synchronized String toJSON(); @Override int friendlyName(); @Override String friendlyDescription(); @Override Optional<Integer> icon(); @Override Trigger duplicate(); @Override void generateDialog(LinearLayout root, FragmentManager fragmentManager);  }