![]() |
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 HLocation implements HJsonObj{ 00031 00032 private JSONObject hlocation = new JSONObject(); 00033 00034 public HLocation() {}; 00035 00036 public HLocation(JSONObject jsonObj){ 00037 fromJSON(jsonObj); 00038 } 00039 00040 /* HJsonObj interface */ 00041 00042 public JSONObject toJSON() { 00043 return hlocation; 00044 } 00045 00046 public void fromJSON(JSONObject jsonObj) { 00047 if(jsonObj != null) { 00048 this.hlocation = jsonObj; 00049 } else { 00050 this.hlocation = new JSONObject(); 00051 } 00052 } 00053 00054 public String getHType() { 00055 return "hlocation"; 00056 } 00057 00058 @Override 00059 public String toString() { 00060 return hlocation.toString(); 00061 } 00062 00068 public boolean equals(HLocation obj) { 00069 if(obj.getLat() != this.getLat()) 00070 return false; 00071 if(obj.getLng() != this.getLng()) 00072 return false; 00073 if(obj.getZip() != this.getZip()) 00074 return false; 00075 if(obj.getAddress() != this.getAddress()) 00076 return false; 00077 if(obj.getCity() != this.getCity()) 00078 return false; 00079 if(obj.getCountry() != this.getCountry()) 00080 return false; 00081 return true; 00082 } 00083 00084 @Override 00085 public int hashCode() { 00086 return hlocation.hashCode(); 00087 } 00088 00089 /* Getters & Setters */ 00090 00094 public double getLat() { 00095 double lat; 00096 try { 00097 lat = hlocation.getDouble("lat"); 00098 } catch (Exception e) { 00099 lat = 0; 00100 } 00101 return lat; 00102 } 00103 00104 public void setLat(double lat) { 00105 try { 00106 if(lat == 0) { 00107 hlocation.remove("lat"); 00108 } else { 00109 hlocation.put("lat", lat); 00110 } 00111 } catch (JSONException e) { 00112 } 00113 } 00114 00118 public double getLng() { 00119 double lng; 00120 try { 00121 lng = hlocation.getDouble("lng"); 00122 } catch (Exception e) { 00123 lng = 0; 00124 } 00125 return lng; 00126 } 00127 00128 public void setLng(double lng) { 00129 try { 00130 if(lng == 0) { 00131 hlocation.remove("lng"); 00132 } else { 00133 hlocation.put("lng", lng); 00134 } 00135 } catch (JSONException e) { 00136 } 00137 } 00138 00142 public String getZip() { 00143 String zip; 00144 try { 00145 zip = hlocation.getString("zip"); 00146 } catch (Exception e) { 00147 zip = null; 00148 } 00149 return zip; 00150 } 00151 00152 public void setZip(String zip) { 00153 try { 00154 if(zip == null) { 00155 hlocation.remove("zip"); 00156 } else { 00157 hlocation.put("zip", zip); 00158 } 00159 } catch (JSONException e) { 00160 } 00161 } 00162 00166 public String getAddress() { 00167 String address; 00168 try { 00169 address = hlocation.getString("addr"); 00170 } catch (Exception e) { 00171 address = null; 00172 } 00173 return address; 00174 } 00175 00176 public void setAddress(String address) { 00177 try { 00178 if(address == null) { 00179 hlocation.remove("addr"); 00180 } else { 00181 hlocation.put("addr", address); 00182 } 00183 } catch (JSONException e) { 00184 } 00185 } 00186 00190 public String getCity() { 00191 String city; 00192 try { 00193 city = hlocation.getString("city"); 00194 } catch (Exception e) { 00195 city = null; 00196 } 00197 return city; 00198 } 00199 00200 public void setCity(String city) { 00201 try { 00202 if(city == null) { 00203 hlocation.remove("city"); 00204 } else { 00205 hlocation.put("city", city); 00206 } 00207 } catch (JSONException e) { 00208 } 00209 } 00210 00214 public String getCountry() { 00215 String country; 00216 try { 00217 country = hlocation.getString("country"); 00218 } catch (Exception e) { 00219 country = null; 00220 } 00221 return country; 00222 } 00223 00224 public void setCountry(String country) { 00225 try { 00226 if(country == null) { 00227 hlocation.remove("country"); 00228 } else { 00229 hlocation.put("country", country); 00230 } 00231 } catch (JSONException e) { 00232 } 00233 } 00234 }