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 import java.io.UnsupportedEncodingException;
020 import java.net.URLEncoder;
021 import java.util.Comparator;
022
023 /**
024 * a wikipedia article
025 *
026 * @author marc@geonames
027 *
028 */
029 public class WikipediaArticle {
030
031 private String language;
032
033 private String title;
034
035 private String summary;
036
037 private String wikipediaUrl;
038
039 private String feature;
040
041 private int population;
042
043 private Integer elevation;
044
045 private double latitude;
046
047 private double longitude;
048
049 private String thumbnailImg;
050
051 private int rank;
052
053 /**
054 * @return Returns the elevation.
055 */
056 public Integer getElevation() {
057 return elevation;
058 }
059
060 /**
061 * @param elevation
062 * The elevation to set.
063 */
064 public void setElevation(int elevation) {
065 this.elevation = elevation;
066 }
067
068 /**
069 * @return Returns the feature.
070 */
071 public String getFeature() {
072 return feature;
073 }
074
075 /**
076 * @param feature
077 * The feature to set.
078 */
079 public void setFeature(String feature) {
080 this.feature = feature;
081 }
082
083 /**
084 * @return Returns the language.
085 */
086 public String getLanguage() {
087 return language;
088 }
089
090 /**
091 * @param language
092 * The language to set.
093 */
094 public void setLanguage(String language) {
095 this.language = language;
096 }
097
098 /**
099 * @return Returns the latitude.
100 */
101 public double getLatitude() {
102 return latitude;
103 }
104
105 /**
106 * @param latitude
107 * The latitude to set.
108 */
109 public void setLatitude(double latitude) {
110 this.latitude = latitude;
111 }
112
113 /**
114 * @return Returns the longitude.
115 */
116 public double getLongitude() {
117 return longitude;
118 }
119
120 /**
121 * @param longitude
122 * The longitude to set.
123 */
124 public void setLongitude(double longitude) {
125 this.longitude = longitude;
126 }
127
128 /**
129 * @return Returns the population.
130 */
131 public int getPopulation() {
132 return population;
133 }
134
135 /**
136 * @param population
137 * The population to set.
138 */
139 public void setPopulation(int population) {
140 this.population = population;
141 }
142
143 /**
144 * @return Returns the summary.
145 */
146 public String getSummary() {
147 return summary;
148 }
149
150 /**
151 * @param summary
152 * The summary to set.
153 */
154 public void setSummary(String summary) {
155 this.summary = summary;
156 }
157
158 /**
159 * @return Returns the title.
160 */
161 public String getTitle() {
162 return title;
163 }
164
165 /**
166 * @param title
167 * The title to set.
168 */
169 public void setTitle(String title) {
170 this.title = title;
171 }
172
173 /**
174 * @return Returns the wikipediaUrl.
175 */
176 public String getWikipediaUrl() {
177 if (wikipediaUrl == null || WebService.isAndroid()) {
178 String urlTitle = title.replace(' ', '_');
179 try {
180 urlTitle = URLEncoder.encode(urlTitle, "UTF8");
181 } catch (UnsupportedEncodingException ex) {
182 }
183 String lang = language;
184 if (WebService.isAndroid()) {
185 lang += ".m";
186 }
187 return "http://" + lang + ".wikipedia.org/wiki/" + urlTitle;
188 }
189 return wikipediaUrl;
190 }
191
192 /**
193 * @param wikipediaUrl
194 * The wikipediaUrl to set.
195 */
196 public void setWikipediaUrl(String wikipediaURL) {
197 this.wikipediaUrl = wikipediaURL;
198 }
199
200 /**
201 * @return the thumbnailImg
202 */
203 public String getThumbnailImg() {
204 return thumbnailImg;
205 }
206
207 /**
208 * @param thumbnailImg
209 * the thumbnailImg to set
210 */
211 public void setThumbnailImg(String thumbnailImg) {
212 this.thumbnailImg = thumbnailImg;
213 }
214
215 /**
216 * @return the rank
217 */
218 public int getRank() {
219 return rank;
220 }
221
222 /**
223 * @param rank
224 * the rank to set
225 */
226 public void setRank(int rank) {
227 this.rank = rank;
228 }
229
230 public final static Comparator ELEVATION_ORDER = new Comparator<WikipediaArticle>() {
231 public int compare(WikipediaArticle o1, WikipediaArticle o2) {
232 return Double.compare(o2.elevation, o1.elevation);
233 }
234 };
235
236 public final static Comparator RANK_ORDER = new Comparator<WikipediaArticle>() {
237 public int compare(WikipediaArticle o1, WikipediaArticle o2) {
238 return Double.compare(o2.rank, o1.rank);
239 }
240 };
241 }