![]() |
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 00033 public class HAck implements HJsonObj{ 00034 00035 private JSONObject hack = new JSONObject(); 00036 00037 public HAck() {}; 00038 00039 public HAck(JSONObject jsonObj){ 00040 fromJSON(jsonObj); 00041 } 00042 00043 /* HJsonObj interface */ 00044 00045 public JSONObject toJSON() { 00046 return hack; 00047 } 00048 00049 public void fromJSON(JSONObject jsonObj) { 00050 if(jsonObj != null) { 00051 this.hack = jsonObj; 00052 } else { 00053 this.hack = new JSONObject(); 00054 } 00055 } 00056 00057 public String getHType() { 00058 return "hack"; 00059 } 00060 00061 @Override 00062 public String toString() { 00063 return hack.toString(); 00064 } 00065 00071 public boolean equals(HAck obj) { 00072 if(obj.getAckid() != this.getAckid() || obj.getAck() != this.getAck() ) { 00073 return false; 00074 } 00075 return true; 00076 } 00077 00078 @Override 00079 public int hashCode() { 00080 return hack.hashCode(); 00081 } 00082 00083 /* Getters & Setters */ 00084 00090 public String getAckid() { 00091 String ackid; 00092 try { 00093 ackid = hack.getString("ackid"); 00094 } catch (Exception e) { 00095 ackid = null; 00096 } 00097 return ackid; 00098 } 00099 00100 public void setAckid(String ackid) { 00101 try { 00102 if(ackid == null) { 00103 hack.remove("ackid"); 00104 } else { 00105 hack.put("ackid", ackid); 00106 } 00107 } catch (JSONException e) { 00108 } 00109 } 00110 00115 public HAckValue getAck() { 00116 HAckValue ack; 00117 try { 00118 String ackString = hack.getString("ack"); 00119 ack = HAckValue.constant(ackString); 00120 } catch (Exception e) { 00121 ack = null; 00122 } 00123 return ack; 00124 } 00125 00126 public void setAck(HAckValue ack) { 00127 try { 00128 if(ack == null) { 00129 hack.remove("ack"); 00130 } else { 00131 hack.put("ack", ack.value()); 00132 } 00133 } catch (JSONException e) { 00134 } 00135 } 00136 } 00137