--- dao/DaoAdresseService/src/dk/daoas/daoadresseservice/AdressSearch.java 2015/02/21 13:51:38 2333 +++ dao/DaoAdresseService/src/dk/daoas/daoadresseservice/AdressSearch.java 2015/02/23 14:39:49 2346 @@ -1,8 +1,10 @@ package dk.daoas.daoadresseservice; import java.sql.SQLException; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -11,7 +13,9 @@ import java.util.concurrent.ConcurrentHashMap; import dk.daoas.daoadresseservice.AddressUtils.SplitResult; +import dk.daoas.daoadresseservice.admin.ServiceConfig; import dk.daoas.daoadresseservice.beans.Address; +import dk.daoas.daoadresseservice.beans.DataStatisticsBean; import dk.daoas.daoadresseservice.beans.ExtendedBean; import dk.daoas.daoadresseservice.beans.HundredePctBean; import dk.daoas.daoadresseservice.beans.SearchResult; @@ -27,9 +31,10 @@ private Map helperCache; + private DataStatisticsBean stats = new DataStatisticsBean(); - public SearchResult search(String postnrStr, String adresse) { + public SearchResult search(ServiceConfig config, String postnrStr, String adresse) { int postnr=0; boolean google = false; @@ -66,29 +71,33 @@ if ( gadeident == null) { - String googleVej = GeocodeHelper.googleHelper(postnr, split.vej ); - google = true; - - if (googleVej != null) { - String googleVasket = AddressUtils.vaskVejnavn( googleVej ); - gadeident = postnrVeje.get(googleVasket); + if (config.useGoogle) { + String googleVej = GeocodeHelper.googleHelper(postnr, split.vej ); + google = true; - if (gadeident != null) { - helperCache.put(helperSearchKey, gadeident); + if (googleVej != null) { + String googleVasket = AddressUtils.vaskVejnavn( googleVej ); + gadeident = postnrVeje.get(googleVasket); + + if (gadeident != null) { + helperCache.put(helperSearchKey, gadeident); + } } } } if ( gadeident == null) { - String osmVej = GeocodeHelper.openstreetmapHelper(postnr, split.vej ); - osm = true; - - if (osmVej != null) { - String osmVasket = AddressUtils.vaskVejnavn( osmVej ); - gadeident = postnrVeje.get(osmVasket); + if (config.useOpenStreetMaps) { + String osmVej = GeocodeHelper.openstreetmapHelper(postnr, split.vej ); + osm = true; - if (gadeident != null) { - helperCache.put(helperSearchKey, gadeident); + if (osmVej != null) { + String osmVasket = AddressUtils.vaskVejnavn( osmVej ); + gadeident = postnrVeje.get(osmVasket); + + if (gadeident != null) { + helperCache.put(helperSearchKey, gadeident); + } } } } @@ -260,38 +269,48 @@ long stop = System.currentTimeMillis(); System.out.println("Build, stage3 elapsed: " + (stop-start3) ); System.out.println("Build -- Gathering statistics"); - - int direkteCount = 0; - int extendedCount = 0; - int hundredePctCount = 0; - int ikkeDaekketCount = 0; - + for (Address addr : alleAdresser) { switch (addr.daekningsType) { case DAEKNING_DIREKTE: - direkteCount++; + stats.direkteCount++; break; case DAEKNING_UDVIDET: - extendedCount++; + stats.extendedCount++; break; case DAEKNING_100PCT: - hundredePctCount++; + stats.hundredePctCount++; break; default: - ikkeDaekketCount++; + stats.ikkeDaekketCount++; } - } + } - System.out.println("Build: direkteCount: " + direkteCount); - System.out.println("Build: extendedCount: " + extendedCount); - System.out.println("Build: hundredePctCount: " + hundredePctCount); - System.out.println("Build: ikkeDaekketCount: " + ikkeDaekketCount); + + stats.elapsed = stop-start1; + stats.buildTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format( new Date() ); + + System.out.println("Build: direkteCount: " + stats.direkteCount); + System.out.println("Build: extendedCount: " + stats.extendedCount); + System.out.println("Build: hundredePctCount: " + stats.hundredePctCount); + System.out.println("Build: ikkeDaekketCount: " + stats.ikkeDaekketCount); System.out.println("Build: Total Elapsed: " + (stop-start1) ); System.out.println("Build Completed"); } + public DataStatisticsBean getStatistics() { + return stats; + } + + public void clear() { + searchPostnrVejnavnGadeid.clear(); + searchGadeidentAdresser.clear(); + alleAdresser.clear(); + helperCache.clear(); + } + private String calculateExtendedDaoRoute(ExtendedBean eb, Address orgAddress, Address targetAddress) {