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 {
TIntLongHashMap offsets = new TIntLongHashMap();
String query = req.nameQuery.toLowerCase();
String query = normalizeSearchPoiByNameQuery(req.nameQuery);
CollatorStringMatcher matcher = new CollatorStringMatcher(query,
StringMatcherMode.CHECK_STARTS_FROM_SPACE);
long time = System.currentTimeMillis();

View file

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