@Test public void testFindAddressOfSquareCityMainStreet() throws IOException { Collection<Place> mainStreetAddr = getSubject().findAddress(null, "squareCityMainStreet", "squareCity", null, null); assertNotNull(mainStreetAddr); assertEquals(1, mainStreetAddr.size()); Place mainStreetAddrPlace = mainStreetAddr.iterator().next(); assertNotNull(mainStreetAddrPlace); assertNotNull(mainStreetAddrPlace.getResult()); }
public Collection<Place> findAddress(final String pHouseNr, final String pStreet, final String pCity, final String pZipCode, final String pCountry) { LOG.log(Level.FINEST, "call findAddress" + " ( HouseNr = " + (pHouseNr != null ? pHouseNr : "null") + ", Street = " + (pStreet != null ? pStreet : "null") + ", City = " + (pCity != null ? pCity : "null") + ", ZipCode = " + (pZipCode != null ? pZipCode : "null") + ", Country = " + (pCountry != null ? pCountry : "null") + ")"); Collection<Place> retval = new LinkedList<Place>(); if (pCity != null && pCity.trim().length() > 0) { ResultSet cities = null; try { cities = getDatabase().executeStreamingQuery( "SELECT * FROM city WHERE defaultName like '" + NameHelper.buildNameSearchSQLMatch(pCity) + "'"); while (cities.next()) { long id = cities.getLong("id"); int idType = cities.getInt("idType"); try { LOG.log(Level.FINEST, "found a matching city id=" + id + " type=" + idType + ". Looking for streets..."); CityBounds cityBounds = getPlaceBounds(idType, id); if (cityBounds == null) { LOG.log(Level.SEVERE, "Cannot load bounds of city id=" + id + " type=" + idType + ". ignoring it."); continue; } Collection<CityBounds> suburbs = getSuburbs(cityBounds); LOG.log(Level.FINEST, "found a matching city id=" + id + " type=" + idType + " with " + suburbs.size() + " suburbs. cityBounds=" + cityBounds); Iterator<Way> streets = null; if (pStreet != null && pStreet.length() > 0) { streets = myMap.getWaysByName(pStreet, cityBounds); } else { if (suburbs != null && suburbs.size() > 0) { for (CityBounds bounds : suburbs) { retval.add(new CityPlace(this, cityBounds, bounds)); } } else { retval.add(new CityPlace(this, cityBounds)); } streets = null; } while (streets != null && streets.hasNext()) { Way street = streets.next(); try { LOG.log(Level.FINEST, "found a matching city id=" + id + " type=" + idType + " with a matching street id=" + street.getId()); String subUrbName = null; for (CityBounds suburb : suburbs) { for (WayNode wayNode : street.getWayNodes()) { Node node = myMap.getNodeByID(wayNode.getNodeId()); if (node != null) { if (suburb.contains(node.getLatitude(), node.getLongitude())) { subUrbName = suburb.getName(); break; } } } if (subUrbName != null) break; } retval.add(new AddressPlace(this, street, cityBounds.getName(), subUrbName)); if (retval.size() > MAXRESULTS) break; } catch (Exception e) { LOG.log(Level.SEVERE, "Cannot load way for city id=" + id + " type=" + idType + " named '" + pCity + "' - ignoring this way", e); } } if (retval.size() > MAXRESULTS) break; } catch (Exception e) { LOG.log(Level.SEVERE, "Cannot load a city named '" + pCity + "' - ignoring this city", e); } } } catch (Exception e) { LOG.log(Level.SEVERE, "Cannot load all cities named '" + pCity + "'", e); } finally { if (cities != null) { try { cities.getStatement().close(); } catch (SQLException e) { LOG.log(Level.WARNING, "Cannot close statement after loading all cities named '" + pCity + "'", e); } try { cities.close(); } catch (SQLException e) { LOG.log(Level.WARNING, "Cannot close resultset after loading all cities named '" + pCity + "'", e); } } } } else { Iterator<Way> streets = myMap.getWaysByName(pStreet, null); while (streets.hasNext()) { Way street = streets.next(); try { retval.add(new AddressPlace(this, street, getCityNameForWay(street), getSuburbNameForWay(street))); } catch (RuntimeException e) { LOG.log(Level.WARNING, "Exception while adding a search-result for the way with id=" + street.getId(), e); } } } return retval; }
AddressDBPlaceFinder implements IAddressDBPlaceFinder { public Collection<Place> findAddress(final String pHouseNr, final String pStreet, final String pCity, final String pZipCode, final String pCountry) { LOG.log(Level.FINEST, "call findAddress" + " ( HouseNr = " + (pHouseNr != null ? pHouseNr : "null") + ", Street = " + (pStreet != null ? pStreet : "null") + ", City = " + (pCity != null ? pCity : "null") + ", ZipCode = " + (pZipCode != null ? pZipCode : "null") + ", Country = " + (pCountry != null ? pCountry : "null") + ")"); Collection<Place> retval = new LinkedList<Place>(); if (pCity != null && pCity.trim().length() > 0) { ResultSet cities = null; try { cities = getDatabase().executeStreamingQuery( "SELECT * FROM city WHERE defaultName like '" + NameHelper.buildNameSearchSQLMatch(pCity) + "'"); while (cities.next()) { long id = cities.getLong("id"); int idType = cities.getInt("idType"); try { LOG.log(Level.FINEST, "found a matching city id=" + id + " type=" + idType + ". Looking for streets..."); CityBounds cityBounds = getPlaceBounds(idType, id); if (cityBounds == null) { LOG.log(Level.SEVERE, "Cannot load bounds of city id=" + id + " type=" + idType + ". ignoring it."); continue; } Collection<CityBounds> suburbs = getSuburbs(cityBounds); LOG.log(Level.FINEST, "found a matching city id=" + id + " type=" + idType + " with " + suburbs.size() + " suburbs. cityBounds=" + cityBounds); Iterator<Way> streets = null; if (pStreet != null && pStreet.length() > 0) { streets = myMap.getWaysByName(pStreet, cityBounds); } else { if (suburbs != null && suburbs.size() > 0) { for (CityBounds bounds : suburbs) { retval.add(new CityPlace(this, cityBounds, bounds)); } } else { retval.add(new CityPlace(this, cityBounds)); } streets = null; } while (streets != null && streets.hasNext()) { Way street = streets.next(); try { LOG.log(Level.FINEST, "found a matching city id=" + id + " type=" + idType + " with a matching street id=" + street.getId()); String subUrbName = null; for (CityBounds suburb : suburbs) { for (WayNode wayNode : street.getWayNodes()) { Node node = myMap.getNodeByID(wayNode.getNodeId()); if (node != null) { if (suburb.contains(node.getLatitude(), node.getLongitude())) { subUrbName = suburb.getName(); break; } } } if (subUrbName != null) break; } retval.add(new AddressPlace(this, street, cityBounds.getName(), subUrbName)); if (retval.size() > MAXRESULTS) break; } catch (Exception e) { LOG.log(Level.SEVERE, "Cannot load way for city id=" + id + " type=" + idType + " named '" + pCity + "' - ignoring this way", e); } } if (retval.size() > MAXRESULTS) break; } catch (Exception e) { LOG.log(Level.SEVERE, "Cannot load a city named '" + pCity + "' - ignoring this city", e); } } } catch (Exception e) { LOG.log(Level.SEVERE, "Cannot load all cities named '" + pCity + "'", e); } finally { if (cities != null) { try { cities.getStatement().close(); } catch (SQLException e) { LOG.log(Level.WARNING, "Cannot close statement after loading all cities named '" + pCity + "'", e); } try { cities.close(); } catch (SQLException e) { LOG.log(Level.WARNING, "Cannot close resultset after loading all cities named '" + pCity + "'", e); } } } } else { Iterator<Way> streets = myMap.getWaysByName(pStreet, null); while (streets.hasNext()) { Way street = streets.next(); try { retval.add(new AddressPlace(this, street, getCityNameForWay(street), getSuburbNameForWay(street))); } catch (RuntimeException e) { LOG.log(Level.WARNING, "Exception while adding a search-result for the way with id=" + street.getId(), e); } } } return retval; } }
AddressDBPlaceFinder implements IAddressDBPlaceFinder { public Collection<Place> findAddress(final String pHouseNr, final String pStreet, final String pCity, final String pZipCode, final String pCountry) { LOG.log(Level.FINEST, "call findAddress" + " ( HouseNr = " + (pHouseNr != null ? pHouseNr : "null") + ", Street = " + (pStreet != null ? pStreet : "null") + ", City = " + (pCity != null ? pCity : "null") + ", ZipCode = " + (pZipCode != null ? pZipCode : "null") + ", Country = " + (pCountry != null ? pCountry : "null") + ")"); Collection<Place> retval = new LinkedList<Place>(); if (pCity != null && pCity.trim().length() > 0) { ResultSet cities = null; try { cities = getDatabase().executeStreamingQuery( "SELECT * FROM city WHERE defaultName like '" + NameHelper.buildNameSearchSQLMatch(pCity) + "'"); while (cities.next()) { long id = cities.getLong("id"); int idType = cities.getInt("idType"); try { LOG.log(Level.FINEST, "found a matching city id=" + id + " type=" + idType + ". Looking for streets..."); CityBounds cityBounds = getPlaceBounds(idType, id); if (cityBounds == null) { LOG.log(Level.SEVERE, "Cannot load bounds of city id=" + id + " type=" + idType + ". ignoring it."); continue; } Collection<CityBounds> suburbs = getSuburbs(cityBounds); LOG.log(Level.FINEST, "found a matching city id=" + id + " type=" + idType + " with " + suburbs.size() + " suburbs. cityBounds=" + cityBounds); Iterator<Way> streets = null; if (pStreet != null && pStreet.length() > 0) { streets = myMap.getWaysByName(pStreet, cityBounds); } else { if (suburbs != null && suburbs.size() > 0) { for (CityBounds bounds : suburbs) { retval.add(new CityPlace(this, cityBounds, bounds)); } } else { retval.add(new CityPlace(this, cityBounds)); } streets = null; } while (streets != null && streets.hasNext()) { Way street = streets.next(); try { LOG.log(Level.FINEST, "found a matching city id=" + id + " type=" + idType + " with a matching street id=" + street.getId()); String subUrbName = null; for (CityBounds suburb : suburbs) { for (WayNode wayNode : street.getWayNodes()) { Node node = myMap.getNodeByID(wayNode.getNodeId()); if (node != null) { if (suburb.contains(node.getLatitude(), node.getLongitude())) { subUrbName = suburb.getName(); break; } } } if (subUrbName != null) break; } retval.add(new AddressPlace(this, street, cityBounds.getName(), subUrbName)); if (retval.size() > MAXRESULTS) break; } catch (Exception e) { LOG.log(Level.SEVERE, "Cannot load way for city id=" + id + " type=" + idType + " named '" + pCity + "' - ignoring this way", e); } } if (retval.size() > MAXRESULTS) break; } catch (Exception e) { LOG.log(Level.SEVERE, "Cannot load a city named '" + pCity + "' - ignoring this city", e); } } } catch (Exception e) { LOG.log(Level.SEVERE, "Cannot load all cities named '" + pCity + "'", e); } finally { if (cities != null) { try { cities.getStatement().close(); } catch (SQLException e) { LOG.log(Level.WARNING, "Cannot close statement after loading all cities named '" + pCity + "'", e); } try { cities.close(); } catch (SQLException e) { LOG.log(Level.WARNING, "Cannot close resultset after loading all cities named '" + pCity + "'", e); } } } } else { Iterator<Way> streets = myMap.getWaysByName(pStreet, null); while (streets.hasNext()) { Way street = streets.next(); try { retval.add(new AddressPlace(this, street, getCityNameForWay(street), getSuburbNameForWay(street))); } catch (RuntimeException e) { LOG.log(Level.WARNING, "Exception while adding a search-result for the way with id=" + street.getId(), e); } } } return retval; } AddressDBPlaceFinder(); }
AddressDBPlaceFinder implements IAddressDBPlaceFinder { public Collection<Place> findAddress(final String pHouseNr, final String pStreet, final String pCity, final String pZipCode, final String pCountry) { LOG.log(Level.FINEST, "call findAddress" + " ( HouseNr = " + (pHouseNr != null ? pHouseNr : "null") + ", Street = " + (pStreet != null ? pStreet : "null") + ", City = " + (pCity != null ? pCity : "null") + ", ZipCode = " + (pZipCode != null ? pZipCode : "null") + ", Country = " + (pCountry != null ? pCountry : "null") + ")"); Collection<Place> retval = new LinkedList<Place>(); if (pCity != null && pCity.trim().length() > 0) { ResultSet cities = null; try { cities = getDatabase().executeStreamingQuery( "SELECT * FROM city WHERE defaultName like '" + NameHelper.buildNameSearchSQLMatch(pCity) + "'"); while (cities.next()) { long id = cities.getLong("id"); int idType = cities.getInt("idType"); try { LOG.log(Level.FINEST, "found a matching city id=" + id + " type=" + idType + ". Looking for streets..."); CityBounds cityBounds = getPlaceBounds(idType, id); if (cityBounds == null) { LOG.log(Level.SEVERE, "Cannot load bounds of city id=" + id + " type=" + idType + ". ignoring it."); continue; } Collection<CityBounds> suburbs = getSuburbs(cityBounds); LOG.log(Level.FINEST, "found a matching city id=" + id + " type=" + idType + " with " + suburbs.size() + " suburbs. cityBounds=" + cityBounds); Iterator<Way> streets = null; if (pStreet != null && pStreet.length() > 0) { streets = myMap.getWaysByName(pStreet, cityBounds); } else { if (suburbs != null && suburbs.size() > 0) { for (CityBounds bounds : suburbs) { retval.add(new CityPlace(this, cityBounds, bounds)); } } else { retval.add(new CityPlace(this, cityBounds)); } streets = null; } while (streets != null && streets.hasNext()) { Way street = streets.next(); try { LOG.log(Level.FINEST, "found a matching city id=" + id + " type=" + idType + " with a matching street id=" + street.getId()); String subUrbName = null; for (CityBounds suburb : suburbs) { for (WayNode wayNode : street.getWayNodes()) { Node node = myMap.getNodeByID(wayNode.getNodeId()); if (node != null) { if (suburb.contains(node.getLatitude(), node.getLongitude())) { subUrbName = suburb.getName(); break; } } } if (subUrbName != null) break; } retval.add(new AddressPlace(this, street, cityBounds.getName(), subUrbName)); if (retval.size() > MAXRESULTS) break; } catch (Exception e) { LOG.log(Level.SEVERE, "Cannot load way for city id=" + id + " type=" + idType + " named '" + pCity + "' - ignoring this way", e); } } if (retval.size() > MAXRESULTS) break; } catch (Exception e) { LOG.log(Level.SEVERE, "Cannot load a city named '" + pCity + "' - ignoring this city", e); } } } catch (Exception e) { LOG.log(Level.SEVERE, "Cannot load all cities named '" + pCity + "'", e); } finally { if (cities != null) { try { cities.getStatement().close(); } catch (SQLException e) { LOG.log(Level.WARNING, "Cannot close statement after loading all cities named '" + pCity + "'", e); } try { cities.close(); } catch (SQLException e) { LOG.log(Level.WARNING, "Cannot close resultset after loading all cities named '" + pCity + "'", e); } } } } else { Iterator<Way> streets = myMap.getWaysByName(pStreet, null); while (streets.hasNext()) { Way street = streets.next(); try { retval.add(new AddressPlace(this, street, getCityNameForWay(street), getSuburbNameForWay(street))); } catch (RuntimeException e) { LOG.log(Level.WARNING, "Exception while adding a search-result for the way with id=" + street.getId(), e); } } } return retval; } AddressDBPlaceFinder(); ConfigurationSection getSettings(); void indexDatabase(final IDataSet aMap); void indexNode(final Node city); void indexWay(final Way city); final void addPropertyChangeListener(final PropertyChangeListener listener); final void addPropertyChangeListener(
                                                final String propertyName,
                                                final PropertyChangeListener listener); final void removePropertyChangeListener(
                                                   final String propertyName,
                                                   final PropertyChangeListener listener); synchronized void removePropertyChangeListener(
                                                          final PropertyChangeListener listener); String toString(); Collection<Place> findAddress(final String pHouseNr, final String pStreet,
            final String pCity, final String pZipCode,
            final String pCountry); Collection<Place> findPlaces(final String pSearchExpression); void setMap(final IDataSet pMap); String getCityNameForWay(final Way street); String getSuburbNameForWay(final Way street); String getZipCodeNameForWay(final Way pWay); IDataSet getMap(); void checkpointDB(); static void shutdown(); Collection<CityPlace> findPlaces(final Rectangle2D aSearchArea); }
AddressDBPlaceFinder implements IAddressDBPlaceFinder { public Collection<Place> findAddress(final String pHouseNr, final String pStreet, final String pCity, final String pZipCode, final String pCountry) { LOG.log(Level.FINEST, "call findAddress" + " ( HouseNr = " + (pHouseNr != null ? pHouseNr : "null") + ", Street = " + (pStreet != null ? pStreet : "null") + ", City = " + (pCity != null ? pCity : "null") + ", ZipCode = " + (pZipCode != null ? pZipCode : "null") + ", Country = " + (pCountry != null ? pCountry : "null") + ")"); Collection<Place> retval = new LinkedList<Place>(); if (pCity != null && pCity.trim().length() > 0) { ResultSet cities = null; try { cities = getDatabase().executeStreamingQuery( "SELECT * FROM city WHERE defaultName like '" + NameHelper.buildNameSearchSQLMatch(pCity) + "'"); while (cities.next()) { long id = cities.getLong("id"); int idType = cities.getInt("idType"); try { LOG.log(Level.FINEST, "found a matching city id=" + id + " type=" + idType + ". Looking for streets..."); CityBounds cityBounds = getPlaceBounds(idType, id); if (cityBounds == null) { LOG.log(Level.SEVERE, "Cannot load bounds of city id=" + id + " type=" + idType + ". ignoring it."); continue; } Collection<CityBounds> suburbs = getSuburbs(cityBounds); LOG.log(Level.FINEST, "found a matching city id=" + id + " type=" + idType + " with " + suburbs.size() + " suburbs. cityBounds=" + cityBounds); Iterator<Way> streets = null; if (pStreet != null && pStreet.length() > 0) { streets = myMap.getWaysByName(pStreet, cityBounds); } else { if (suburbs != null && suburbs.size() > 0) { for (CityBounds bounds : suburbs) { retval.add(new CityPlace(this, cityBounds, bounds)); } } else { retval.add(new CityPlace(this, cityBounds)); } streets = null; } while (streets != null && streets.hasNext()) { Way street = streets.next(); try { LOG.log(Level.FINEST, "found a matching city id=" + id + " type=" + idType + " with a matching street id=" + street.getId()); String subUrbName = null; for (CityBounds suburb : suburbs) { for (WayNode wayNode : street.getWayNodes()) { Node node = myMap.getNodeByID(wayNode.getNodeId()); if (node != null) { if (suburb.contains(node.getLatitude(), node.getLongitude())) { subUrbName = suburb.getName(); break; } } } if (subUrbName != null) break; } retval.add(new AddressPlace(this, street, cityBounds.getName(), subUrbName)); if (retval.size() > MAXRESULTS) break; } catch (Exception e) { LOG.log(Level.SEVERE, "Cannot load way for city id=" + id + " type=" + idType + " named '" + pCity + "' - ignoring this way", e); } } if (retval.size() > MAXRESULTS) break; } catch (Exception e) { LOG.log(Level.SEVERE, "Cannot load a city named '" + pCity + "' - ignoring this city", e); } } } catch (Exception e) { LOG.log(Level.SEVERE, "Cannot load all cities named '" + pCity + "'", e); } finally { if (cities != null) { try { cities.getStatement().close(); } catch (SQLException e) { LOG.log(Level.WARNING, "Cannot close statement after loading all cities named '" + pCity + "'", e); } try { cities.close(); } catch (SQLException e) { LOG.log(Level.WARNING, "Cannot close resultset after loading all cities named '" + pCity + "'", e); } } } } else { Iterator<Way> streets = myMap.getWaysByName(pStreet, null); while (streets.hasNext()) { Way street = streets.next(); try { retval.add(new AddressPlace(this, street, getCityNameForWay(street), getSuburbNameForWay(street))); } catch (RuntimeException e) { LOG.log(Level.WARNING, "Exception while adding a search-result for the way with id=" + street.getId(), e); } } } return retval; } AddressDBPlaceFinder(); ConfigurationSection getSettings(); void indexDatabase(final IDataSet aMap); void indexNode(final Node city); void indexWay(final Way city); final void addPropertyChangeListener(final PropertyChangeListener listener); final void addPropertyChangeListener(
                                                final String propertyName,
                                                final PropertyChangeListener listener); final void removePropertyChangeListener(
                                                   final String propertyName,
                                                   final PropertyChangeListener listener); synchronized void removePropertyChangeListener(
                                                          final PropertyChangeListener listener); String toString(); Collection<Place> findAddress(final String pHouseNr, final String pStreet,
            final String pCity, final String pZipCode,
            final String pCountry); Collection<Place> findPlaces(final String pSearchExpression); void setMap(final IDataSet pMap); String getCityNameForWay(final Way street); String getSuburbNameForWay(final Way street); String getZipCodeNameForWay(final Way pWay); IDataSet getMap(); void checkpointDB(); static void shutdown(); Collection<CityPlace> findPlaces(final Rectangle2D aSearchArea);  }