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 */ 017package org.geonames; 018 019import java.util.HashSet; 020import java.util.Set; 021 022/** 023 * search criteria for web services returning toponyms. 024 * 025 * The string parameters do not have to be utf8 encoded. The encoding is done 026 * transparently in the call to the web service. 027 * 028 * The main parameter for the search over all fields is the 'q' parameter. 029 * 030 * @see WebService#search 031 * 032 * @see <a href="http://www.geonames.org/export/geonames-search.html">search 033 * webservice documentation< /a> 034 * 035 * @author marc@geonames 036 * 037 */ 038public class ToponymSearchCriteria { 039 040 private String q; 041 042 private String countryCode; 043 044 private Set<String> countryCodes; 045 046 private String countryBias; 047 048 private String continentCode; 049 050 private String name; 051 052 private String nameEquals; 053 054 private String nameStartsWith; 055 056 private String tag; 057 058 private String language; 059 060 private Style style; 061 062 private FeatureClass featureClass; 063 064 private String[] featureCodes; 065 066 private String adminCode1; 067 068 private String adminCode2; 069 070 private String adminCode3; 071 072 private String adminCode4; 073 074 private int maxRows; 075 076 private int startRow; 077 078 private double fuzzy = 1.0; 079 080 private BoundingBox boundingBox; 081 082 /** 083 * @return Returns the ISO 3166-1-alpha-2 countryCode. 084 */ 085 public String getCountryCode() { 086 return countryCode; 087 } 088 089 /** 090 * @param countryCode 091 * The ISO 3166-1-alpha-2 countryCode to set. 092 */ 093 public void setCountryCode(String countryCode) 094 throws InvalidParameterException { 095 if (countryCode != null && countryCode.length() != 2) { 096 throw new InvalidParameterException("invalid country code " 097 + countryCode); 098 } 099 this.countryCode = countryCode; 100 } 101 102 /** 103 * @param countryCode 104 * The ISO 3166-1-alpha-2 countryCode to set. 105 */ 106 public void addCountryCode(String countryCode) 107 throws InvalidParameterException { 108 if (countryCode != null && countryCode.length() != 2) { 109 throw new InvalidParameterException("invalid country code " 110 + countryCode); 111 } 112 if (this.countryCodes == null) { 113 this.countryCodes = new HashSet<String>(); 114 } 115 this.countryCodes.add(countryCode); 116 } 117 118 /** 119 * @return the countryCodes 120 */ 121 public Set<String> getCountryCodes() { 122 return countryCodes; 123 } 124 125 /** 126 * @param countryCodes 127 * the countryCodes to set 128 */ 129 public void setCountryCodes(Set<String> countryCodes) { 130 this.countryCodes = countryCodes; 131 } 132 133 /** 134 * @return the countryBias 135 */ 136 public String getCountryBias() { 137 return countryBias; 138 } 139 140 /** 141 * @param countryBias 142 * the countryBias to set 143 */ 144 public void setCountryBias(String countryBias) { 145 this.countryBias = countryBias; 146 } 147 148 /** 149 * @return the continentCode 150 */ 151 public String getContinentCode() { 152 return continentCode; 153 } 154 155 /** 156 * @param continentCode 157 * the continentCode to set 158 */ 159 public void setContinentCode(String continentCode) { 160 this.continentCode = continentCode; 161 } 162 163 /** 164 * @return Returns the nameEquals. 165 */ 166 public String getNameEquals() { 167 return nameEquals; 168 } 169 170 /** 171 * @param nameEquals 172 * The nameEquals to set. 173 */ 174 public void setNameEquals(String exactName) { 175 this.nameEquals = exactName; 176 } 177 178 /** 179 * @return Returns the featureCodes. 180 */ 181 public String[] getFeatureCodes() { 182 return featureCodes; 183 } 184 185 /** 186 * @param featureCodes 187 * The featureCodes to set. 188 */ 189 public void setFeatureCodes(String[] featureCodes) { 190 this.featureCodes = featureCodes; 191 } 192 193 public void setFeatureCode(String featureCode) { 194 this.featureCodes = new String[] { featureCode }; 195 } 196 197 /** 198 * @return Returns the language. 199 */ 200 public String getLanguage() { 201 return language; 202 } 203 204 /** 205 * @param language 206 * The language to set. 207 */ 208 public void setLanguage(String language) { 209 this.language = language; 210 } 211 212 /** 213 * @return Returns the maxRows. 214 */ 215 public int getMaxRows() { 216 return maxRows; 217 } 218 219 /** 220 * @param maxRows 221 * The maxRows to set. 222 */ 223 public void setMaxRows(int maxRows) { 224 this.maxRows = maxRows; 225 } 226 227 /** 228 * @return Returns the name. 229 */ 230 public String getName() { 231 return name; 232 } 233 234 /** 235 * search over the name field only. 236 * 237 * @param name 238 * The name to set. 239 */ 240 public void setName(String name) { 241 this.name = name; 242 } 243 244 /** 245 * @return Returns the q. 246 */ 247 public String getQ() { 248 return q; 249 } 250 251 /** 252 * The main search term. The search is executed over all fields (place name, 253 * country name, admin names, etc) 254 * 255 * @param q 256 * The q to set. 257 */ 258 public void setQ(String q) { 259 this.q = q; 260 } 261 262 /** 263 * @return Returns the startRow. 264 */ 265 public int getStartRow() { 266 return startRow; 267 } 268 269 /** 270 * @param startRow 271 * The startRow to set. 272 */ 273 public void setStartRow(int startRow) { 274 this.startRow = startRow; 275 } 276 277 /** 278 * @return Returns the style. 279 */ 280 public Style getStyle() { 281 return style; 282 } 283 284 /** 285 * @param style 286 * The style to set. 287 */ 288 public void setStyle(Style style) { 289 this.style = style; 290 } 291 292 /** 293 * @return Returns the tag. 294 */ 295 public String getTag() { 296 return tag; 297 } 298 299 /** 300 * @param tag 301 * The tag to set. 302 */ 303 public void setTag(String tag) { 304 this.tag = tag; 305 } 306 307 /** 308 * @return Returns the nameStartsWith. 309 */ 310 public String getNameStartsWith() { 311 return nameStartsWith; 312 } 313 314 /** 315 * @param nameStartsWith 316 * The nameStartsWith to set. 317 */ 318 public void setNameStartsWith(String nameStartsWith) { 319 this.nameStartsWith = nameStartsWith; 320 } 321 322 /** 323 * @return the featureClass 324 */ 325 public FeatureClass getFeatureClass() { 326 return featureClass; 327 } 328 329 /** 330 * @param featureClass 331 * the featureClass to set 332 */ 333 public void setFeatureClass(FeatureClass featureClass) { 334 this.featureClass = featureClass; 335 } 336 337 /** 338 * @return the adminCode1 339 */ 340 public String getAdminCode1() { 341 return adminCode1; 342 } 343 344 /** 345 * @param adminCode1 346 * the adminCode1 to set 347 */ 348 public void setAdminCode1(String adminCode1) { 349 this.adminCode1 = adminCode1; 350 } 351 352 /** 353 * @return the adminCode2 354 */ 355 public String getAdminCode2() { 356 return adminCode2; 357 } 358 359 /** 360 * @param adminCode2 361 * the adminCode2 to set 362 */ 363 public void setAdminCode2(String adminCode2) { 364 this.adminCode2 = adminCode2; 365 } 366 367 /** 368 * @return the adminCode3 369 */ 370 public String getAdminCode3() { 371 return adminCode3; 372 } 373 374 /** 375 * @param adminCode3 376 * the adminCode3 to set 377 */ 378 public void setAdminCode3(String adminCode3) { 379 this.adminCode3 = adminCode3; 380 } 381 382 public String getAdminCode4() { 383 return adminCode4; 384 } 385 386 public void setAdminCode4(String adminCode4) { 387 this.adminCode4 = adminCode4; 388 } 389 390 /** 391 * @return the fuzzy 392 */ 393 public double getFuzzy() { 394 return fuzzy; 395 } 396 397 /** 398 * @param fuzzy the fuzzy to set 399 */ 400 public void setFuzzy(double fuzzy) { 401 this.fuzzy = fuzzy; 402 } 403 404 /** 405 * @return the boundingBox 406 */ 407 public BoundingBox getBoundingBox() { 408 return boundingBox; 409 } 410 411 /** 412 * @param boundingBox 413 * the boundingBox to set 414 */ 415 public void setBoundingBox(BoundingBox boundingBox) { 416 this.boundingBox = boundingBox; 417 } 418 419}