Formatting

This commit is contained in:
Roman Inflianskas 2016-06-07 17:04:51 +03:00
parent 7c9215454a
commit 0a09cfdc3b

View file

@ -60,9 +60,8 @@ public class OsmandRegions {
Map<String, LinkedList<BinaryMapDataObject>> countriesByDownloadName = new HashMap<String, LinkedList<BinaryMapDataObject>>();
QuadTree<String> quadTree ;
MapIndexFields mapIndexFields ;
QuadTree<String> quadTree;
MapIndexFields mapIndexFields;
RegionTranslation translator;
private class MapIndexFields {
@ -80,7 +79,7 @@ public class OsmandRegions {
Integer populationType = null;
public String get(Integer tp, BinaryMapDataObject object) {
if(tp == null) {
if (tp == null) {
return null;
}
return object.getNameByType(tp);
@ -93,7 +92,6 @@ public class OsmandRegions {
}
public void prepareFile(String fileName) throws IOException {
reader = new BinaryMapIndexReader(new RandomAccessFile(fileName, "r"), new File(fileName));
// final Collator clt = OsmAndCollator.primaryCollator();
@ -104,17 +102,17 @@ public class OsmandRegions {
public boolean publish(BinaryMapDataObject object) {
initTypes(object);
int[] types = object.getTypes();
for(int i = 0; i < types.length; i++ ) {
for (int i = 0; i < types.length; i++) {
TagValuePair tp = object.getMapIndex().decodeType(types[i]);
if("boundary".equals(tp.value)) {
if ("boundary".equals(tp.value)) {
return false;
}
}
WorldRegion rd = initRegionData(parentRelations, object);
if(rd == null) {
if (rd == null) {
return false;
}
if(rd.regionDownloadName != null) {
if (rd.regionDownloadName != null) {
downloadNamesToFullNames.put(rd.regionDownloadName, rd.regionFullName);
}
fullNamesToRegionData.put(rd.regionFullName, rd);
@ -128,20 +126,20 @@ public class OsmandRegions {
};
iterateOverAllObjects(resultMatcher);
// post process download names
for(Map.Entry<String, String> e : parentRelations.entrySet()) {
for (Map.Entry<String, String> e : parentRelations.entrySet()) {
String fullName = e.getKey();
String parentFullName = e.getValue();
// String parentParentFulName = parentRelations.get(parentFullName); // could be used for japan/russia
WorldRegion rd = fullNamesToRegionData.get(fullName);
WorldRegion parent = fullNamesToRegionData.get(parentFullName);
if(parent != null && rd != null) {
if (parent != null && rd != null) {
parent.addSubregion(rd);
}
}
structureWorldRegions(new ArrayList<WorldRegion>(fullNamesToRegionData.values()));
}
public boolean containsCountry(String name){
public boolean containsCountry(String name) {
return countriesByDownloadName.containsKey(name);
}
@ -157,20 +155,20 @@ public class OsmandRegions {
public String getLocaleNameByFullName(String fullName, boolean includingParent) {
WorldRegion rd = fullNamesToRegionData.get(fullName);
if(rd == null) {
if (rd == null) {
return fullName.replace('_', ' ');
}
if (includingParent && rd.getSuperregion() != null && rd.getSuperregion().getSuperregion() != null) {
WorldRegion parentParent = rd.getSuperregion().getSuperregion();
WorldRegion parent = rd.getSuperregion();
if(parentParent.getRegionId().equals(WorldRegion.WORLD) &&
if (parentParent.getRegionId().equals(WorldRegion.WORLD) &&
!parent.getRegionId().equals(WorldRegion.RUSSIA_REGION_ID)) {
return rd.getLocaleName();
}
if(parentParent.getRegionId().equals(WorldRegion.RUSSIA_REGION_ID)) {
if (parentParent.getRegionId().equals(WorldRegion.RUSSIA_REGION_ID)) {
return parentParent.getLocaleName() + " " + rd.getLocaleName();
}
if(parentParent.getRegionId().equals(WorldRegion.JAPAN_REGION_ID)) {
if (parentParent.getRegionId().equals(WorldRegion.JAPAN_REGION_ID)) {
return parentParent.getLocaleName() + " " + rd.getLocaleName();
}
return parent.getLocaleName() + " " + rd.getLocaleName();
@ -184,7 +182,7 @@ public class OsmandRegions {
}
public boolean isInitialized(){
public boolean isInitialized() {
return reader != null;
}
@ -204,15 +202,15 @@ public class OsmandRegions {
public boolean intersect(BinaryMapDataObject bo, int lx, int ty, int rx, int by) {
// 1. polygon in object
if(contain(bo, lx, ty)) {
if (contain(bo, lx, ty)) {
return true;
}
// 2. object in polygon
if(bo.getPointsLength() == 0) {
if (bo.getPointsLength() == 0) {
return false;
}
if(bo.getPoint31XTile(0) >= lx && bo.getPoint31XTile(0) <= rx &&
bo.getPoint31YTile(0) >= ty && bo.getPoint31YTile(0) <= by ){
if (bo.getPoint31XTile(0) >= lx && bo.getPoint31XTile(0) <= rx &&
bo.getPoint31YTile(0) >= ty && bo.getPoint31YTile(0) <= by) {
return true;
}
@ -222,17 +220,17 @@ public class OsmandRegions {
int x = bo.getPoint31XTile(i);
int py = bo.getPoint31YTile(i - 1);
int y = bo.getPoint31YTile(i);
if(x < lx && px < lx) {
if (x < lx && px < lx) {
continue;
} else if(x > rx && px > rx) {
} else if (x > rx && px > rx) {
continue;
} else if(y > by && py > by) {
} else if (y > by && py > by) {
continue;
} else if(y < ty && py < ty) {
} else if (y < ty && py < ty) {
continue;
}
long in = MapAlgorithms.calculateIntersection(px, py, x, y, lx, rx, by, ty);
if(in != -1) {
if (in != -1) {
return true;
}
}
@ -266,7 +264,7 @@ public class OsmandRegions {
public List<BinaryMapDataObject> query(final int tile31x, final int tile31y) throws IOException {
if(quadTree != null) {
if (quadTree != null) {
return getCountries(tile31x, tile31y);
}
return queryNoInit(tile31x, tile31y);
@ -301,7 +299,7 @@ public class OsmandRegions {
}
}
);
if(reader != null) {
if (reader != null) {
reader.searchMapIndex(sr);
}
return result;
@ -335,7 +333,7 @@ public class OsmandRegions {
}
);
sr.log = false;
if(reader != null) {
if (reader != null) {
reader.searchMapIndex(sr);
}
return result;
@ -370,7 +368,7 @@ public class OsmandRegions {
private WorldRegion initRegionData(final Map<String, String> parentRelations, BinaryMapDataObject object) {
String regionDownloadName = mapIndexFields.get(mapIndexFields.downloadNameType, object);
String regionFullName = mapIndexFields.get(mapIndexFields.fullNameType, object);
if(Algorithms.isEmpty(regionFullName)) {
if (Algorithms.isEmpty(regionFullName)) {
return null;
}
WorldRegion rd = new WorldRegion(regionFullName, regionDownloadName);
@ -380,14 +378,14 @@ public class OsmandRegions {
cx += object.getPoint31XTile(i);
cy += object.getPoint31YTile(i);
}
if(object.getPointsLength() > 0) {
if (object.getPointsLength() > 0) {
cx /= object.getPointsLength();
cy /= object.getPointsLength();
rd.regionCenter = new LatLon(MapUtils.get31LatitudeY((int) cy), MapUtils.get31LongitudeX((int) cx));
}
rd.regionParentFullName = mapIndexFields.get(mapIndexFields.parentFullName, object);
if(!Algorithms.isEmpty(rd.regionParentFullName)) {
if (!Algorithms.isEmpty(rd.regionParentFullName)) {
parentRelations.put(rd.regionFullName, rd.regionParentFullName);
}
rd.regionName = mapIndexFields.get(mapIndexFields.nameType, object);
@ -408,13 +406,13 @@ public class OsmandRegions {
MapIndex mi = object.getMapIndex();
TIntObjectIterator<String> it = object.getObjectNames().iterator();
StringBuilder ind = new StringBuilder();
while(it.hasNext()) {
while (it.hasNext()) {
it.advance();
TagValuePair tp = mi.decodeType(it.key());
if(tp.tag.startsWith("name") || tp.tag.equals("key_name")) {
if (tp.tag.startsWith("name") || tp.tag.equals("key_name")) {
final String vl = it.value().toLowerCase();
// if (!CollatorStringMatcher.ccontains(clt, ind.toString(), vl)) {
if(ind.indexOf(vl) == -1) {
if (ind.indexOf(vl) == -1) {
ind.append(" ").append(vl);
}
}
@ -423,13 +421,11 @@ public class OsmandRegions {
}
public boolean isDownloadOfType(BinaryMapDataObject object, String type) {
int[] addtypes = object.getAdditionalTypes();
for(int i = 0; i < addtypes.length; i++) {
for (int i = 0; i < addtypes.length; i++) {
TagValuePair tp = object.getMapIndex().decodeType(addtypes[i]);
if(type.equals(tp.tag) && "yes".equals(tp.value)) {
if (type.equals(tp.tag) && "yes".equals(tp.value)) {
return true;
}
}
@ -495,7 +491,7 @@ public class OsmandRegions {
return true;
}
}, resultMatcher);
if(reader != null) {
if (reader != null) {
reader.searchMapIndex(sr);
}
}
@ -508,7 +504,7 @@ public class OsmandRegions {
mapIndexFields.downloadNameType = object.getMapIndex().getRule(FIELD_DOWNLOAD_NAME, null);
mapIndexFields.nameType = object.getMapIndex().getRule(FIELD_NAME, null);
mapIndexFields.nameEnType = object.getMapIndex().getRule(FIELD_NAME_EN, null);
mapIndexFields.nameLocaleType = object.getMapIndex().getRule(FIELD_NAME+":"+locale, null);
mapIndexFields.nameLocaleType = object.getMapIndex().getRule(FIELD_NAME + ":" + locale, null);
mapIndexFields.parentFullName = object.getMapIndex().getRule(FIELD_REGION_PARENT_NAME, null);
mapIndexFields.fullNameType = object.getMapIndex().getRule(FIELD_REGION_FULL_NAME, null);
mapIndexFields.langType = object.getMapIndex().getRule(FIELD_LANG, null);
@ -530,10 +526,10 @@ public class OsmandRegions {
for (BinaryMapDataObject b : cs) {
String nm = b.getNameByType(or.mapIndexFields.nameEnType);
if(nm == null) {
if (nm == null) {
nm = b.getName();
}
if(or.isDownloadOfType(b, MAP_TYPE)) {
if (or.isDownloadOfType(b, MAP_TYPE)) {
found.add(nm.toLowerCase());
}
}
@ -568,7 +564,7 @@ public class OsmandRegions {
//testCountry(or, 15.8, 23.09, "chad");
testCountry(or, 52.10, 4.92, "the netherlands", "utrecht");
testCountry(or, 52.15, 7.50, "north rhine-westphalia");
testCountry(or, 28.8056, 29.9858, "egypt" );
testCountry(or, 28.8056, 29.9858, "egypt");
// testCountry(or, 40.0760, 9.2807, "italy", "sardinia");
testCountry(or, 35.7521, 139.7887, "japan");
testCountry(or, 46.5145, 102.2580, "mongolia");
@ -584,14 +580,14 @@ public class OsmandRegions {
private void initWorldRegion(WorldRegion world, String id) {
WorldRegion rg = new WorldRegion(id);
rg.regionParentFullName = world.regionFullName;
if(translator != null) {
if (translator != null) {
rg.regionName = translator.getTranslation(id);
}
world.addSubregion(rg);
}
public void structureWorldRegions(List<WorldRegion> loadedItems ) {
public void structureWorldRegions(List<WorldRegion> loadedItems) {
if (loadedItems.size() == 0) {
return;
}
@ -605,22 +601,22 @@ public class OsmandRegions {
initWorldRegion(world, WorldRegion.SOUTH_AMERICA_REGION_ID);
initWorldRegion(world, WorldRegion.AUSTRALIA_AND_OCEANIA_REGION_ID);
Iterator<WorldRegion> it = loadedItems.iterator();
while(it.hasNext()) {
while (it.hasNext()) {
WorldRegion region = it.next();
if(region.superregion == null) {
if (region.superregion == null) {
boolean found = false;
for(WorldRegion worldSubregion : world.subregions) {
if(worldSubregion.getRegionId().equalsIgnoreCase(region.regionFullName)) {
for(WorldRegion rg : region.subregions) {
for (WorldRegion worldSubregion : world.subregions) {
if (worldSubregion.getRegionId().equalsIgnoreCase(region.regionFullName)) {
for (WorldRegion rg : region.subregions) {
worldSubregion.addSubregion(rg);
}
found = true;
break;
}
}
if(found) {
if (found) {
it.remove();
} else if(region.getRegionId().contains("basemap")) {
} else if (region.getRegionId().contains("basemap")) {
it.remove();
}
} else {
@ -646,7 +642,6 @@ public class OsmandRegions {
}
private void sortSubregions(WorldRegion region, Comparator<WorldRegion> comparator) {
Collections.sort(region.subregions, comparator);
for (WorldRegion r : region.subregions) {
@ -656,5 +651,4 @@ public class OsmandRegions {
}
}
}