001    /*
002     * Copyright 2008 Marc Wick, geonames.org
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *     http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     *
016     */
017    package org.geonames;
018    
019    /**
020     * a GeoNames toponym
021     * 
022     * @author marc@geonames
023     * 
024     */
025    public class Toponym {
026    
027            private int geoNameId;
028    
029            private String name;
030    
031            private String alternateNames;
032    
033            private String continentCode;
034    
035            private String countryCode;
036    
037            private String countryName;
038    
039            private Long population;
040    
041            private Integer elevation;
042    
043            private FeatureClass featureClass;
044    
045            private String featureClassName;
046    
047            private String featureCode;
048    
049            private String featureCodeName;
050    
051            private double latitude;
052    
053            private double longitude;
054    
055            private String adminCode1;
056    
057            private String adminName1;
058    
059            private String adminCode2;
060    
061            private String adminName2;
062    
063            private String adminCode3;
064    
065            private String adminCode4;
066    
067            private Timezone timezone;
068    
069            private Style style;
070    
071            /**
072             * @return the continentCode
073             */
074            public String getContinentCode() {
075                    return continentCode;
076            }
077    
078            /**
079             * @param continentCode
080             *            the continentCode to set
081             */
082            public void setContinentCode(String continentCode) {
083                    this.continentCode = continentCode;
084            }
085    
086            /**
087             * @return Returns the ISO 3166-1-alpha-2 countryCode.
088             */
089            public String getCountryCode() {
090                    return countryCode;
091            }
092    
093            /**
094             * @param countryCode
095             *            The ISO 3166-1-alpha-2 countryCode to set.
096             */
097            public void setCountryCode(String countryCode) {
098                    this.countryCode = countryCode;
099            }
100    
101            /**
102             * @return Returns the elevation in meter.
103             */
104            public Integer getElevation() throws InsufficientStyleException {
105                    if (elevation == null && style != null
106                                    && Style.LONG.compareTo(style) > 0) {
107                            throw new InsufficientStyleException(
108                                            "elevation not supported by style " + style.name());
109                    }
110                    return elevation;
111            }
112    
113            /**
114             * @param elevation
115             *            The elevation im meter to set.
116             */
117            public void setElevation(Integer elevation) {
118                    this.elevation = elevation;
119            }
120    
121            /**
122             * the feature class {@link FeatureClass}
123             * 
124             * @see <a href="http://www.geonames.org/export/codes.html">GeoNames Feature
125             *      Codes</a>
126             * @return Returns the featureClass.
127             */
128            public FeatureClass getFeatureClass() {
129                    return featureClass;
130            }
131    
132            /**
133             * @param featureClass
134             *            The featureClass to set.
135             */
136            public void setFeatureClass(FeatureClass featureClass) {
137                    this.featureClass = featureClass;
138            }
139    
140            /**
141             * @see <a href="http://www.geonames.org/export/codes.html">GeoNames Feature
142             *      Codes</a>
143             * @return Returns the featureCode.
144             */
145            public String getFeatureCode() {
146                    return featureCode;
147            }
148    
149            /**
150             * @param featureCode
151             *            The featureCode to set.
152             */
153            public void setFeatureCode(String featureCode) {
154                    this.featureCode = featureCode;
155            }
156    
157            /**
158             * latitude in decimal degrees (wgs84)
159             * 
160             * @return Returns the latitude.
161             */
162            public double getLatitude() {
163                    return latitude;
164            }
165    
166            /**
167             * @param latitude
168             *            The latitude to set.
169             */
170            public void setLatitude(double latitude) {
171                    this.latitude = latitude;
172            }
173    
174            /**
175             * longitude in decimal degrees (wgs84)
176             * 
177             * @return Returns the longitude.
178             */
179            public double getLongitude() {
180                    return longitude;
181            }
182    
183            /**
184             * @param longitude
185             *            The longitude to set.
186             */
187            public void setLongitude(double longitude) {
188                    this.longitude = longitude;
189            }
190    
191            /**
192             * @return Returns the name.
193             */
194            public String getName() {
195                    return name;
196            }
197    
198            /**
199             * @param name
200             *            The name to set.
201             */
202            public void setName(String name) {
203                    this.name = name;
204            }
205    
206            /**
207             * @return Returns the population.
208             */
209            public Long getPopulation() throws InsufficientStyleException {
210                    if (population == null && style != null
211                                    && Style.LONG.compareTo(style) > 0) {
212                            throw new InsufficientStyleException(
213                                            "population not supported by style " + style.name());
214                    }
215                    return population;
216            }
217    
218            /**
219             * @param population
220             *            The population to set.
221             */
222            public void setPopulation(Long population) {
223                    this.population = population;
224            }
225    
226            /**
227             * @return Returns the geoNameId.
228             */
229            public int getGeoNameId() {
230                    return geoNameId;
231            }
232    
233            /**
234             * @param geoNameId
235             *            The geoNameId to set.
236             */
237            public void setGeoNameId(int geonameId) {
238                    this.geoNameId = geonameId;
239            }
240    
241            /**
242             * @return Returns the featureClassName.
243             */
244            public String getFeatureClassName() {
245                    return featureClassName;
246            }
247    
248            /**
249             * @param featureClassName
250             *            The featureClassName to set.
251             */
252            public void setFeatureClassName(String featureClassName) {
253                    this.featureClassName = featureClassName;
254            }
255    
256            /**
257             * @return Returns the featureCodeName.
258             */
259            public String getFeatureCodeName() {
260                    return featureCodeName;
261            }
262    
263            /**
264             * @param featureCodeName
265             *            The featureCodeName to set.
266             */
267            public void setFeatureCodeName(String featureCodeName) {
268                    this.featureCodeName = featureCodeName;
269            }
270    
271            /**
272             * @return Returns the countryName.
273             */
274            public String getCountryName() {
275                    return countryName;
276            }
277    
278            /**
279             * @param countryName
280             *            The countryName to set.
281             */
282            public void setCountryName(String countryName) {
283                    this.countryName = countryName;
284            }
285    
286            /**
287             * alternate names of this place as comma separated list
288             * 
289             * @return the alternateNames as comma separated list
290             */
291            public String getAlternateNames() throws InsufficientStyleException {
292                    if (alternateNames == null && style != null
293                                    && Style.LONG.compareTo(style) > 0) {
294                            throw new InsufficientStyleException(
295                                            "alternateNames not supported by style " + style.name());
296                    }
297                    return alternateNames;
298            }
299    
300            /**
301             * @param alternateNames
302             *            the alternateNames to set
303             */
304            public void setAlternateNames(String alternateNames) {
305                    this.alternateNames = alternateNames;
306            }
307    
308            public String toString() {
309                    StringBuilder str = new StringBuilder();
310                    str.append("geoNameId=" + geoNameId + ",");
311                    str.append("name=" + name + ",");
312                    if (alternateNames != null) {
313                            str.append("alternateNames=" + alternateNames + ",");
314                    }
315                    str.append("latitude=" + latitude + ",");
316                    str.append("longitude=" + longitude + ",");
317                    str.append("countryCode=" + countryCode + ",");
318                    str.append("population=" + population + ",");
319                    str.append("elevation=" + elevation + ",");
320                    str.append("featureClass=" + featureClass + ",");
321                    str.append("featureCode=" + featureCode);
322                    return str.toString();
323            }
324    
325            /**
326             * @return the adminCode1
327             */
328            public String getAdminCode1() throws InsufficientStyleException {
329                    if (adminCode1 == null && style != null
330                                    && Style.LONG.compareTo(style) > 0) {
331                            throw new InsufficientStyleException(
332                                            "adminCode1 not supported by style " + style.name());
333                    }
334                    return adminCode1;
335            }
336    
337            /**
338             * @param adminCode1
339             *            the adminCode1 to set
340             */
341            public void setAdminCode1(String adminCode1) {
342                    this.adminCode1 = adminCode1;
343            }
344    
345            /**
346             * @return the adminCode2
347             */
348            public String getAdminCode2() throws InsufficientStyleException {
349                    if (adminCode2 == null && style != null
350                                    && Style.LONG.compareTo(style) > 0) {
351                            throw new InsufficientStyleException(
352                                            "adminCode2 not supported by style " + style.name());
353                    }
354                    return adminCode2;
355            }
356    
357            /**
358             * @param adminCode2
359             *            the adminCode2 to set
360             */
361            public void setAdminCode2(String adminCode2) {
362                    this.adminCode2 = adminCode2;
363            }
364    
365            /**
366             * @return the adminCode3
367             */
368            public String getAdminCode3() throws InsufficientStyleException {
369                    if (adminCode3 == null && style != null
370                                    && Style.LONG.compareTo(style) > 0) {
371                            throw new InsufficientStyleException(
372                                            "adminCode3 not supported by style " + style.name());
373                    }
374                    return adminCode3;
375            }
376    
377            /**
378             * @param adminCode3
379             *            the adminCode3 to set
380             */
381            public void setAdminCode3(String adminCode3) {
382                    this.adminCode3 = adminCode3;
383            }
384    
385            /**
386             * @return the adminCode4
387             */
388            public String getAdminCode4() throws InsufficientStyleException {
389                    if (adminCode4 == null && style != null
390                                    && Style.LONG.compareTo(style) > 0) {
391                            throw new InsufficientStyleException(
392                                            "adminCode4 not supported by style " + style.name());
393                    }
394                    return adminCode4;
395            }
396    
397            /**
398             * @param adminCode4
399             *            the adminCode4 to set
400             */
401            public void setAdminCode4(String adminCode4) {
402                    this.adminCode4 = adminCode4;
403            }
404    
405            /**
406             * @return the timezone
407             */
408            public Timezone getTimezone() throws InsufficientStyleException {
409                    if (timezone == null && style != null
410                                    && Style.LONG.compareTo(style) > 0) {
411                            throw new InsufficientStyleException(
412                                            "alternateNames not supported by style " + style.name());
413                    }
414                    return timezone;
415            }
416    
417            /**
418             * @param timezone
419             *            the timezone to set
420             */
421            public void setTimezone(Timezone timezone) {
422                    this.timezone = timezone;
423            }
424    
425            /**
426             * @return the adminName1
427             */
428            public String getAdminName1() throws InsufficientStyleException {
429                    if (adminName1 == null && style != null
430                                    && Style.LONG.compareTo(style) > 0) {
431                            throw new InsufficientStyleException(
432                                            "adminName1 not supported by style " + style.name());
433                    }
434                    return adminName1;
435            }
436    
437            /**
438             * @param adminName1
439             *            the adminName1 to set
440             */
441            public void setAdminName1(String adminName1) {
442                    this.adminName1 = adminName1;
443            }
444    
445            /**
446             * @return the adminName2
447             */
448            public String getAdminName2() throws InsufficientStyleException {
449                    if (adminName2 == null && style != null
450                                    && Style.LONG.compareTo(style) > 0) {
451                            throw new InsufficientStyleException(
452                                            "adminName2 not supported by style " + style.name());
453                    }
454                    return adminName2;
455            }
456    
457            /**
458             * @param adminName2
459             *            the adminName2 to set
460             */
461            public void setAdminName2(String adminName2) {
462                    this.adminName2 = adminName2;
463            }
464    
465            /**
466             * @return the style used when calling the web service that returned this
467             *         toponym.
468             */
469            public Style getStyle() {
470                    return style;
471            }
472    
473            /**
474             * @param style
475             *            the style to set
476             */
477            public void setStyle(Style style) {
478                    this.style = style;
479            }
480    
481    }