![]() |
Hubiquitus Android
0.3
Android client for hubiquitus protocol
|
00001 /* 00002 * Copyright (c) Novedia Group 2012. 00003 * 00004 * This file is part of Hubiquitus. 00005 * 00006 * Hubiquitus is free software: you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation, either version 3 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * Hubiquitus is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with Hubiquitus. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 package org.hubiquitus.hapi.hStructures; 00021 00022 import org.json.JSONException; 00023 import org.json.JSONObject; 00024 00030 public class HMeasure implements HJsonObj{ 00031 00032 private JSONObject hmeasure = new JSONObject(); 00033 00034 public HMeasure() {}; 00035 00036 public HMeasure(JSONObject jsonObj){ 00037 fromJSON(jsonObj); 00038 } 00039 00040 /* HJsonObj interface */ 00041 00042 public JSONObject toJSON() { 00043 return hmeasure; 00044 } 00045 00046 public void fromJSON(JSONObject jsonObj) { 00047 if(jsonObj != null) { 00048 this.hmeasure = jsonObj; 00049 } else { 00050 this.hmeasure = new JSONObject(); 00051 } 00052 } 00053 00054 public String getHType() { 00055 return "hmeasure"; 00056 } 00057 00058 @Override 00059 public String toString() { 00060 return hmeasure.toString(); 00061 } 00062 00068 public boolean equals(HMeasure obj) { 00069 if(obj.getUnit() != this.getUnit()) 00070 return false; 00071 if(obj.getValue() != this.getValue()) 00072 return false; 00073 return true; 00074 } 00075 00076 @Override 00077 public int hashCode() { 00078 return hmeasure.hashCode(); 00079 } 00080 00081 /* Getters & Setters */ 00082 00087 public String getUnit() { 00088 String unit; 00089 try { 00090 unit = hmeasure.getString("unit"); 00091 } catch (Exception e) { 00092 unit = null; 00093 } 00094 return unit; 00095 } 00096 00097 public void setUnit(String unit) { 00098 try { 00099 if(unit == null) { 00100 hmeasure.remove("unit"); 00101 } else { 00102 hmeasure.put("unit", unit); 00103 } 00104 } catch (JSONException e) { 00105 } 00106 } 00107 00112 public String getValue() { 00113 String value; 00114 try { 00115 value = hmeasure.getString("value"); 00116 } catch (Exception e) { 00117 value = null; 00118 } 00119 return value; 00120 } 00121 00122 public void setValue(String value) { 00123 try { 00124 if(value == null) { 00125 hmeasure.remove("value"); 00126 } else { 00127 hmeasure.put("value", value); 00128 } 00129 } catch (JSONException e) { 00130 } 00131 } 00132 }