source: gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/server/ServerPlace.java@ 23906

Last change on this file since 23906 was 23906, checked in by sjm84, 13 years ago

Committing most recent version of ATLAS

File size: 8.9 KB
Line 
1package org.greenstone.server;
2
3import java.io.Serializable;
4import org.greenstone.client.Place;
5
6public class ServerPlace implements Serializable
7{
8 private static final long serialVersionUID = 6106265145261780206L;
9 protected static FindPlaceServiceImpl _fpsi = new FindPlaceServiceImpl();
10
11 protected String _placeName = null;
12 protected String _parentPlaceName = null;
13 protected String _placeType = null;
14
15 protected Float _latitude = null;
16 protected Float _longitude = null;
17
18 protected long _population = 0;
19 protected long _id = -1;
20 protected int _score = 0;
21
22 protected boolean _directlyReferenced = false;
23 protected static boolean _loopDone = false;
24
25 protected static ServerPlace _tempPlace = null;
26
27 public ServerPlace()
28 {
29
30 }
31
32 public ServerPlace(String placeName)
33 {
34 _placeName = placeName;
35 }
36
37 public void setParentPlaceName(String parentPlaceName)
38 {
39 _parentPlaceName = parentPlaceName;
40 }
41
42 public boolean equals(Object placeToCompare)
43 {
44 if (placeToCompare == null)
45 {
46 return false;
47 }
48
49 if (placeToCompare instanceof ServerPlace)
50 {
51 ServerPlace otherPlace = (ServerPlace)(placeToCompare);
52 if(_placeName != null && otherPlace.getName() != null && _parentPlaceName != null && otherPlace.getParentPlaceName() != null && _placeName.equals(otherPlace.getName()))
53 {
54 String[] cols = _parentPlaceName.split(", ");
55 String[] otherCols = otherPlace.getParentPlaceName().split(", ");
56
57 if(cols.length == 3 && otherCols.length == 2)
58 {
59 if(cols[0].equals(otherPlace.getName()) && cols[1].equals(otherCols[0]) && cols[2].equals(otherCols[1]))
60 {
61 return true;
62 }
63 }
64 else if(cols.length == 2 && otherCols.length == 3)
65 {
66 if(otherCols[0].equals(_placeName) && otherCols[1].equals(cols[0]) && otherCols[2].equals(cols[1]))
67 {
68 return true;
69 }
70 }
71 else if(cols.length == 2 && otherCols.length == 1)
72 {
73 if(cols[0].equals(otherPlace.getName()) && cols[1].equals(otherCols[0]))
74 {
75 return true;
76 }
77 }
78 else if(cols.length == 1 && otherCols.length == 2)
79 {
80 if(otherCols[0].equals(_placeName) && otherCols[1].equals(cols[0]))
81 {
82 return true;
83 }
84 }
85 }
86
87 if (_id != -1 && ((ServerPlace)(placeToCompare)).getId() != -1 && _id == otherPlace.getId())
88 {
89 return true;
90 }
91
92 String otherPlaceName = otherPlace.getName();
93 String otherParentName = otherPlace.getParentPlaceName();
94
95 if ((_placeName == null && otherPlaceName == null) && (_parentPlaceName == null && otherParentName == null))
96 {
97 return true;
98 }
99
100 if ((_placeName == null && otherPlaceName == null) && _parentPlaceName != null && otherParentName != null && _parentPlaceName.equals(otherParentName))
101 {
102 return true;
103 }
104
105 if ((_parentPlaceName == null && otherParentName == null) && _placeName != null && otherPlaceName != null && _placeName.equals(otherPlaceName))
106 {
107 return true;
108 }
109
110 if (_placeName != null && otherPlaceName != null && _parentPlaceName != null && otherParentName != null && _parentPlaceName.equals(otherPlace.getParentPlaceName()) && _placeName.equals(otherPlace.getName()))
111 {
112 return true;
113 }
114 }
115
116 if (placeToCompare instanceof Place)
117 {
118 Place otherPlace = (Place)(placeToCompare);
119 if(_placeName != null && otherPlace.getName() != null && _parentPlaceName != null && otherPlace.getParentPlaceName() != null && _placeName.equals(otherPlace.getName()))
120 {
121 String[] cols = _parentPlaceName.split(", ");
122 String[] otherCols = otherPlace.getParentPlaceName().split(", ");
123
124 if(cols.length == 3 && otherCols.length == 2)
125 {
126 if(cols[0].equals(otherPlace.getName()) && cols[1].equals(otherCols[0]) && cols[2].equals(otherCols[1]))
127 {
128 return true;
129 }
130 }
131 else if(cols.length == 2 && otherCols.length == 3)
132 {
133 if(otherCols[0].equals(_placeName) && otherCols[1].equals(cols[0]) && otherCols[2].equals(cols[1]))
134 {
135 return true;
136 }
137 }
138 else if(cols.length == 2 && otherCols.length == 1)
139 {
140 if(cols[0].equals(otherPlace.getName()) && cols[1].equals(otherCols[0]))
141 {
142 return true;
143 }
144 }
145 else if(cols.length == 1 && otherCols.length == 2)
146 {
147 if(otherCols[0].equals(_placeName) && otherCols[1].equals(cols[0]))
148 {
149 return true;
150 }
151 }
152 }
153
154 if (_id != -1 && ((Place)(placeToCompare)).getId() != -1 && _id == ((Place)(placeToCompare)).getId())
155 {
156 return true;
157 }
158
159 String otherPlaceName = otherPlace.getName();
160 String otherParentName = otherPlace.getParentPlaceName();
161
162 if ((_placeName == null && otherPlaceName == null) && (_parentPlaceName == null && otherParentName == null))
163 {
164 return true;
165 }
166
167 if ((_placeName == null && otherPlaceName == null) && _parentPlaceName != null && otherParentName != null && _parentPlaceName.equals(otherParentName))
168 {
169 return true;
170 }
171
172 if ((_parentPlaceName == null && otherParentName == null) && _placeName != null && otherPlaceName != null && _placeName.equals(otherPlaceName))
173 {
174 return true;
175 }
176
177 if (_placeName != null && otherPlaceName != null && _parentPlaceName != null && otherParentName != null && _parentPlaceName.equals(otherPlace.getParentPlaceName()) && _placeName.equals(otherPlace.getName()))
178 {
179 return true;
180 }
181 }
182
183 return false;
184 }
185
186 public String toString()
187 {
188 String info = "*************************";
189
190 info += "\nPlace name = " + _placeName + "\nParents = " + _parentPlaceName + "\nChildren = ";
191
192 info += "\nPlace type = " + _placeType;
193 info += "\nPopulation = " + _population;
194 info += "\nLatitude = " + _latitude + " Longitude = " + _longitude;
195 info += "\n*************************";
196
197 return info;
198 }
199
200 // Get Methods
201
202 public int getScore()
203 {
204 return _score;
205 }
206
207 public String getPlaceType()
208 {
209 return _placeType;
210 }
211
212 public String getParentPlaceName()
213 {
214 return _parentPlaceName;
215 }
216
217 public String getName()
218 {
219 return _placeName;
220 }
221
222 public Float getLatitude()
223 {
224 return _latitude;
225 }
226
227 public Float getLongitude()
228 {
229 return _longitude;
230 }
231
232 public long getPopulation()
233 {
234 return _population;
235 }
236
237 public long getId()
238 {
239 return _id;
240 }
241
242 public boolean isDirectlyReferenced()
243 {
244 return _directlyReferenced;
245 }
246
247 // Set Methods
248
249 public void setScore(int score)
250 {
251 _score = score;
252 }
253
254 public void setPlaceType(String placeType)
255 {
256 _placeType = placeType;
257 }
258
259 public void setLatitude(Float latitude)
260 {
261 _latitude = latitude;
262 }
263
264 public void setLongitude(Float longitude)
265 {
266 _longitude = longitude;
267 }
268
269 public void setPopulation(long population)
270 {
271 _population = population;
272 }
273
274 public void setId(long id)
275 {
276 _id = id;
277 }
278
279 public void directReference()
280 {
281 _directlyReferenced = true;
282 }
283
284 /**
285 * Figures out what sort of place the line in the file is refering to (e.g.
286 * locality, region, etc.)
287 *
288 * @param placeName
289 * is the name of the place
290 * @param subRegionName
291 * is the possible sub region the place is in
292 * @param regionName
293 * is the possible region the place is in
294 * @param countryName
295 * is the country the place is in
296 * @param placeType
297 * is the type of place
298 * @return returns the place
299 */
300 public static ServerPlace createPlaceFromInformation(long id, String placeName, String subRegionName, String regionName, String countryName, String placeType, Float longitude, Float latitude, long population)
301 {
302 ServerPlace newPlace = new ServerPlace(placeName);
303
304 String parentPlaceName = null;
305 if (!(subRegionName == null))
306 {
307 parentPlaceName = subRegionName;
308 }
309 if (!(regionName == null))
310 {
311 if (parentPlaceName == null)
312 {
313 parentPlaceName = regionName;
314 }
315 else
316 {
317 parentPlaceName += ", " + regionName;
318 }
319 }
320 if (!(countryName == null))
321 {
322 if (parentPlaceName == null)
323 {
324 parentPlaceName = countryName;
325 }
326 else
327 {
328 parentPlaceName += ", " + countryName;
329 }
330 }
331
332 if (parentPlaceName == null && countryName == null)
333 {
334 if (placeType.equals("country"))
335 {
336 countryName = placeName;
337 }
338 else
339 {
340 return null;
341 }
342 }
343
344 newPlace.setId(id);
345 newPlace.setParentPlaceName(parentPlaceName);
346 newPlace.setLatitude(latitude);
347 newPlace.setLongitude(longitude);
348 newPlace.setPopulation(population);
349 newPlace.setPlaceType(placeType);
350 return newPlace;
351 }
352
353 public static ServerPlace convert(Place p)
354 {
355 ServerPlace sp = ServerPlace.createPlaceFromInformation(p.getId(), p.getName(), null, null, p.getParentPlaceName(), p.getPlaceType(), p.getLongitude(), p.getLatitude(), p.getPopulation());
356
357 sp.setScore(p.getScore());
358
359 if(p.isDirectlyReferenced())
360 {
361 sp.directReference();
362 }
363
364 return sp;
365 }
366
367 public static ServerPlace createPlaceFromId(long id)
368 {
369 Place p = _fpsi.getPlaceById(id);
370
371 //System.out.println("P = " + p);
372
373 return ServerPlace.createPlaceFromInformation(p.getId(), p.getName(), null, null, p.getParentPlaceName(), p.getPlaceType(), p.getLongitude(), p.getLatitude(), p.getPopulation());
374 }
375}
Note: See TracBrowser for help on using the repository browser.