Formatting

This commit is contained in:
Roman Inflianskas 2016-06-02 11:05:03 +03:00
parent 2db86a7b45
commit a0c9e60c5a
2 changed files with 40 additions and 38 deletions

View file

@ -276,9 +276,13 @@ public class BinaryMapPoiReaderAdapter {
} }
} }
private String normalizeSearchPoiByNameQuery(String query) {
return query.replace("\"", "").toLowerCase();
}
protected void searchPoiByName(PoiRegion region, SearchRequest<Amenity> req) throws IOException { protected void searchPoiByName(PoiRegion region, SearchRequest<Amenity> req) throws IOException {
TIntLongHashMap offsets = new TIntLongHashMap(); TIntLongHashMap offsets = new TIntLongHashMap();
String query = req.nameQuery.toLowerCase(); String query = normalizeSearchPoiByNameQuery(req.nameQuery);
CollatorStringMatcher matcher = new CollatorStringMatcher(query, CollatorStringMatcher matcher = new CollatorStringMatcher(query,
StringMatcherMode.CHECK_STARTS_FROM_SPACE); StringMatcherMode.CHECK_STARTS_FROM_SPACE);
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();

View file

@ -37,8 +37,8 @@ import org.apache.commons.logging.Log;
public class RegionAddressRepositoryBinary implements RegionAddressRepository { public class RegionAddressRepositoryBinary implements RegionAddressRepository {
private static final Log log = PlatformUtil.getLog(RegionAddressRepositoryBinary.class); private static final Log log = PlatformUtil.getLog(RegionAddressRepositoryBinary.class);
private BinaryMapIndexReader file; private BinaryMapIndexReader file;
private LinkedHashMap<Long, City> cities = new LinkedHashMap<Long, City>(); private LinkedHashMap<Long, City> cities = new LinkedHashMap<Long, City>();
private int ZOOM_QTREE = 10; private int ZOOM_QTREE = 10;
private QuadTree<City> citiesQtree = new QuadTree<City>(new QuadRect(0, 0, 1 << (ZOOM_QTREE + 1), private QuadTree<City> citiesQtree = new QuadTree<City>(new QuadRect(0, 0, 1 << (ZOOM_QTREE + 1),
@ -48,48 +48,48 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
private String fileName; private String fileName;
private ResourceManager mgr; private ResourceManager mgr;
private OsmandPreference<String> langSetting; private OsmandPreference<String> langSetting;
public RegionAddressRepositoryBinary(ResourceManager mgr, BinaryMapIndexReader file, String fileName) { public RegionAddressRepositoryBinary(ResourceManager mgr, BinaryMapIndexReader file, String fileName) {
this.mgr = mgr; this.mgr = mgr;
langSetting = mgr.getContext().getSettings().MAP_PREFERRED_LOCALE; langSetting = mgr.getContext().getSettings().MAP_PREFERRED_LOCALE;
this.file = file; this.file = file;
this.fileName = fileName; this.fileName = fileName;
this.collator = OsmAndCollator.primaryCollator(); this.collator = OsmAndCollator.primaryCollator();
this.postCodes = new TreeMap<String, City>(OsmAndCollator.primaryCollator()); this.postCodes = new TreeMap<String, City>(OsmAndCollator.primaryCollator());
} }
@Override @Override
public void close(){ public void close() {
this.file = null; this.file = null;
} }
@Override @Override
public BinaryMapIndexReader getFile() { public BinaryMapIndexReader getFile() {
return file; return file;
} }
@Override @Override
public synchronized List<GeocodingResult> justifyReverseGeocodingSearch(GeocodingResult r, double minBuildingDistance, final ResultMatcher<GeocodingResult> result) { public synchronized List<GeocodingResult> justifyReverseGeocodingSearch(GeocodingResult r, double minBuildingDistance, final ResultMatcher<GeocodingResult> result) {
try { try {
return new GeocodingUtilities().justifyReverseGeocodingSearch(r, file, minBuildingDistance, result); return new GeocodingUtilities().justifyReverseGeocodingSearch(r, file, minBuildingDistance, result);
} catch(IOException e) { } catch (IOException e) {
log.error("Disk operation failed", e); //$NON-NLS-1$ log.error("Disk operation failed", e); //$NON-NLS-1$
} }
return Collections.emptyList(); return Collections.emptyList();
} }
@Override @Override
public synchronized void preloadCities(ResultMatcher<City> resultMatcher) { public synchronized void preloadCities(ResultMatcher<City> resultMatcher) {
if (cities.isEmpty()) { if (cities.isEmpty()) {
try { try {
List<City> cs = file.getCities(BinaryMapIndexReader.buildAddressRequest(resultMatcher), List<City> cs = file.getCities(BinaryMapIndexReader.buildAddressRequest(resultMatcher),
BinaryMapAddressReaderAdapter.CITY_TOWN_TYPE); BinaryMapAddressReaderAdapter.CITY_TOWN_TYPE);
LinkedHashMap<Long, City> ncities = new LinkedHashMap<Long, City>(); LinkedHashMap<Long, City> ncities = new LinkedHashMap<Long, City>();
for (City c : cs) { for (City c : cs) {
ncities.put(c.getId(), c); ncities.put(c.getId(), c);
LatLon loc = c.getLocation(); LatLon loc = c.getLocation();
if(loc != null) { if (loc != null) {
int y31 = MapUtils.get31TileNumberY(loc.getLatitude()); int y31 = MapUtils.get31TileNumberY(loc.getLatitude());
int x31 = MapUtils.get31TileNumberX(loc.getLongitude()); int x31 = MapUtils.get31TileNumberX(loc.getLongitude());
int dz = (31 - ZOOM_QTREE); int dz = (31 - ZOOM_QTREE);
@ -102,7 +102,7 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
} }
} }
} }
public City getClosestCity(LatLon l, List<City> cache) { public City getClosestCity(LatLon l, List<City> cache) {
City closest = null; City closest = null;
if (l != null) { if (l != null) {
@ -131,16 +131,16 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
@Override @Override
public synchronized void preloadBuildings(Street street, ResultMatcher<Building> resultMatcher) { public synchronized void preloadBuildings(Street street, ResultMatcher<Building> resultMatcher) {
if(street.getBuildings().isEmpty() && street.getIntersectedStreets().isEmpty()){ if (street.getBuildings().isEmpty() && street.getIntersectedStreets().isEmpty()) {
try { try {
file.preloadBuildings(street, BinaryMapIndexReader.buildAddressRequest(resultMatcher)); file.preloadBuildings(street, BinaryMapIndexReader.buildAddressRequest(resultMatcher));
street.sortBuildings(); street.sortBuildings();
} catch (IOException e) { } catch (IOException e) {
log.error("Disk operation failed" , e); //$NON-NLS-1$ log.error("Disk operation failed", e); //$NON-NLS-1$
} }
} }
} }
@Override @Override
public void addCityToPreloadedList(City city) { public void addCityToPreloadedList(City city) {
if (!cities.containsKey(city.getId())) { if (!cities.containsKey(city.getId())) {
@ -149,29 +149,29 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
cities = ncities; cities = ncities;
} }
} }
@Override @Override
public List<City> getLoadedCities(){ public List<City> getLoadedCities() {
return new ArrayList<City>(cities.values()); return new ArrayList<City>(cities.values());
} }
@Override @Override
public synchronized void preloadStreets(City o, ResultMatcher<Street> resultMatcher) { public synchronized void preloadStreets(City o, ResultMatcher<Street> resultMatcher) {
Collection<Street> streets = o.getStreets(); Collection<Street> streets = o.getStreets();
if(!streets.isEmpty()){ if (!streets.isEmpty()) {
return; return;
} }
try { try {
file.preloadStreets(o, BinaryMapIndexReader.buildAddressRequest(resultMatcher)); file.preloadStreets(o, BinaryMapIndexReader.buildAddressRequest(resultMatcher));
} catch (IOException e) { } catch (IOException e) {
log.error("Disk operation failed" , e); //$NON-NLS-1$ log.error("Disk operation failed", e); //$NON-NLS-1$
} }
} }
// // not use ccontains It is really slow, takes about 10 times more than other steps // // not use ccontains It is really slow, takes about 10 times more than other steps
// private StringMatcherMode[] streetsCheckMode = new StringMatcherMode[] {StringMatcherMode.CHECK_ONLY_STARTS_WITH, // private StringMatcherMode[] streetsCheckMode = new StringMatcherMode[] {StringMatcherMode.CHECK_ONLY_STARTS_WITH,
// StringMatcherMode.CHECK_STARTS_FROM_SPACE_NOT_BEGINNING}; // StringMatcherMode.CHECK_STARTS_FROM_SPACE_NOT_BEGINNING};
@Override @Override
public synchronized List<MapObject> searchMapObjectsByName(String name, ResultMatcher<MapObject> resultMatcher) { public synchronized List<MapObject> searchMapObjectsByName(String name, ResultMatcher<MapObject> resultMatcher) {
SearchRequest<MapObject> req = BinaryMapIndexReader.buildAddressByNameRequest(resultMatcher, name); SearchRequest<MapObject> req = BinaryMapIndexReader.buildAddressByNameRequest(resultMatcher, name);
@ -188,9 +188,10 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
List<City> result = new ArrayList<City>(); List<City> result = new ArrayList<City>();
List<City> foundCities = file.getCities(BinaryMapIndexReader.buildAddressRequest(new ResultMatcher<City>() { List<City> foundCities = file.getCities(BinaryMapIndexReader.buildAddressRequest(new ResultMatcher<City>() {
List<City> cache = new ArrayList<City>(); List<City> cache = new ArrayList<City>();
@Override @Override
public boolean publish(City c) { public boolean publish(City c) {
if(c.getLocation() != null) { if (c.getLocation() != null) {
City ct = getClosestCity(c.getLocation(), cache); City ct = getClosestCity(c.getLocation(), cache);
c.setClosestCity(ct); c.setClosestCity(ct);
} }
@ -247,8 +248,8 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
if (/*name.length() >= 2 && Algorithms.containsDigit(name) && */searchVillages) { if (/*name.length() >= 2 && Algorithms.containsDigit(name) && */searchVillages) {
// also try to identify postcodes // also try to identify postcodes
String uName = name.toUpperCase(); String uName = name.toUpperCase();
List<City> foundCities = file.getCities(BinaryMapIndexReader.buildAddressRequest(resultMatcher), List<City> foundCities = file.getCities(BinaryMapIndexReader.buildAddressRequest(resultMatcher),
new CollatorStringMatcher(uName, StringMatcherMode.CHECK_CONTAINS), lang, new CollatorStringMatcher(uName, StringMatcherMode.CHECK_CONTAINS), lang,
BinaryMapAddressReaderAdapter.POSTCODES_TYPE); BinaryMapAddressReaderAdapter.POSTCODES_TYPE);
for (City code : foundCities) { for (City code : foundCities) {
citiesToFill.add(code); citiesToFill.add(code);
@ -292,7 +293,6 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
preloadBuildings(st, null); preloadBuildings(st, null);
return st.getIntersectedStreets(); return st.getIntersectedStreets();
} }
@Override @Override
public Building getBuildingByName(Street street, String name) { public Building getBuildingByName(Street street, String name) {
@ -309,17 +309,17 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
@Override @Override
public String getName() { public String getName() {
if(fileName.indexOf('.') != -1) { if (fileName.indexOf('.') != -1) {
return fileName.substring(0, fileName.indexOf('.')); return fileName.substring(0, fileName.indexOf('.'));
} }
return fileName; return fileName;
} }
@Override @Override
public String getFileName() { public String getFileName() {
return fileName; return fileName;
} }
@Override @Override
public String toString() { public String toString() {
return getName() + " repository"; return getName() + " repository";
@ -331,7 +331,7 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
// do not preload cities for that case // do not preload cities for that case
return null; return null;
} }
if(id < -1 && name != null){ if (id < -1 && name != null) {
name = name.toUpperCase(); name = name.toUpperCase();
} }
final String cmpName = name; final String cmpName = name;
@ -348,8 +348,8 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
@Override @Override
public boolean publish(City object) { public boolean publish(City object) {
if(id < -1) { if (id < -1) {
if(object.getName().toUpperCase().equals(cmpName)) { if (object.getName().toUpperCase().equals(cmpName)) {
addCityToPreloadedList(object); addCityToPreloadedList(object);
canceled = true; canceled = true;
} }
@ -372,7 +372,7 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
public Street getStreetByName(City o, String name) { public Street getStreetByName(City o, String name) {
name = name.toLowerCase(); name = name.toLowerCase();
preloadStreets(o, null); preloadStreets(o, null);
Collection<Street> streets = o.getStreets() ; Collection<Street> streets = o.getStreets();
String lang = getLang(); String lang = getLang();
for (Street s : streets) { for (Street s : streets) {
String sName = s.getName(lang).toLowerCase(); String sName = s.getName(lang).toLowerCase();
@ -388,7 +388,7 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
cities = new LinkedHashMap<Long, City>(); cities = new LinkedHashMap<Long, City>();
citiesQtree.clear(); citiesQtree.clear();
postCodes.clear(); postCodes.clear();
} }
@Override @Override
@ -396,6 +396,4 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
return file.getRegionCenter(); return file.getRegionCenter();
} }
} }