Refactoring

This commit is contained in:
Roman Inflianskas 2016-05-25 11:22:53 +03:00
parent cde96e5848
commit 61bfbdc3ed

View file

@ -37,7 +37,7 @@ public class BinaryMapPoiReaderAdapter {
private static final Log LOG = PlatformUtil.getLog(BinaryMapPoiReaderAdapter.class); private static final Log LOG = PlatformUtil.getLog(BinaryMapPoiReaderAdapter.class);
public static final int SHIFT_BITS_CATEGORY = 7; public static final int SHIFT_BITS_CATEGORY = 7;
private static final int CATEGORY_MASK = (1 << SHIFT_BITS_CATEGORY) - 1 ; private static final int CATEGORY_MASK = (1 << SHIFT_BITS_CATEGORY) - 1;
private static final int ZOOM_TO_SKIP_FILTER_READ = 6; private static final int ZOOM_TO_SKIP_FILTER_READ = 6;
private static final int ZOOM_TO_SKIP_FILTER = 3; private static final int ZOOM_TO_SKIP_FILTER = 3;
private static final int BUCKET_SEARCH_BY_NAME = 5; private static final int BUCKET_SEARCH_BY_NAME = 5;
@ -52,7 +52,7 @@ public class BinaryMapPoiReaderAdapter {
public static class PoiRegion extends BinaryIndexPart { public static class PoiRegion extends BinaryIndexPart {
List<String> categories = new ArrayList<String>(); List<String> categories = new ArrayList<String>();
List<PoiCategory> categoriesType = new ArrayList<PoiCategory>(); List<PoiCategory> categoriesType = new ArrayList<PoiCategory>();
List<List<String> > subcategories = new ArrayList<List<String> >(); List<List<String>> subcategories = new ArrayList<List<String>>();
List<PoiSubType> subTypes = new ArrayList<PoiSubType>(); List<PoiSubType> subTypes = new ArrayList<PoiSubType>();
double leftLongitude; double leftLongitude;
@ -75,14 +75,14 @@ public class BinaryMapPoiReaderAdapter {
public PoiSubType getSubtypeFromId(int id, StringBuilder returnValue) { public PoiSubType getSubtypeFromId(int id, StringBuilder returnValue) {
int tl; int tl;
int sl; int sl;
if(id % 2 == 0) { if (id % 2 == 0) {
tl = (id >> 1) & ((1 << 5) -1); tl = (id >> 1) & ((1 << 5) - 1);
sl = id >> 6; sl = id >> 6;
} else { } else {
tl = (id >> 1) & ((1 << 16) -1); tl = (id >> 1) & ((1 << 16) - 1);
sl = id >> 16; sl = id >> 16;
} }
if(subTypes.size() > tl) { if (subTypes.size() > tl) {
PoiSubType st = subTypes.get(tl); PoiSubType st = subTypes.get(tl);
if (st.text) { if (st.text) {
return st; return st;
@ -112,7 +112,7 @@ public class BinaryMapPoiReaderAdapter {
private MapPoiTypes poiTypes; private MapPoiTypes poiTypes;
protected BinaryMapPoiReaderAdapter(BinaryMapIndexReader map){ protected BinaryMapPoiReaderAdapter(BinaryMapIndexReader map) {
this.codedIS = map.codedIS; this.codedIS = map.codedIS;
this.map = map; this.map = map;
this.poiTypes = MapPoiTypes.getDefault(); this.poiTypes = MapPoiTypes.getDefault();
@ -127,7 +127,7 @@ public class BinaryMapPoiReaderAdapter {
} }
private void readPoiBoundariesIndex(PoiRegion region) throws IOException { private void readPoiBoundariesIndex(PoiRegion region) throws IOException {
while(true){ while (true) {
int t = codedIS.readTag(); int t = codedIS.readTag();
int tag = WireFormat.getTagFieldNumber(t); int tag = WireFormat.getTagFieldNumber(t);
switch (tag) { switch (tag) {
@ -152,17 +152,16 @@ public class BinaryMapPoiReaderAdapter {
} }
} }
protected void readPoiIndex(PoiRegion region, boolean readCategories) throws IOException { protected void readPoiIndex(PoiRegion region, boolean readCategories) throws IOException {
int length; int length;
int oldLimit; int oldLimit;
while(true){ while (true) {
int t = codedIS.readTag(); int t = codedIS.readTag();
int tag = WireFormat.getTagFieldNumber(t); int tag = WireFormat.getTagFieldNumber(t);
switch (tag) { switch (tag) {
case 0: case 0:
return; return;
case OsmandOdb.OsmAndPoiIndex.NAME_FIELD_NUMBER : case OsmandOdb.OsmAndPoiIndex.NAME_FIELD_NUMBER:
region.name = codedIS.readString(); region.name = codedIS.readString();
break; break;
case OsmandOdb.OsmAndPoiIndex.BOUNDARIES_FIELD_NUMBER: case OsmandOdb.OsmAndPoiIndex.BOUNDARIES_FIELD_NUMBER:
@ -171,8 +170,8 @@ public class BinaryMapPoiReaderAdapter {
readPoiBoundariesIndex(region); readPoiBoundariesIndex(region);
codedIS.popLimit(oldLimit); codedIS.popLimit(oldLimit);
break; break;
case OsmandOdb.OsmAndPoiIndex.CATEGORIESTABLE_FIELD_NUMBER : case OsmandOdb.OsmAndPoiIndex.CATEGORIESTABLE_FIELD_NUMBER:
if(!readCategories){ if (!readCategories) {
codedIS.skipRawBytes(codedIS.getBytesUntilLimit()); codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
return; return;
} }
@ -181,8 +180,8 @@ public class BinaryMapPoiReaderAdapter {
readCategory(region); readCategory(region);
codedIS.popLimit(oldLimit); codedIS.popLimit(oldLimit);
break; break;
case OsmandOdb.OsmAndPoiIndex.SUBTYPESTABLE_FIELD_NUMBER : case OsmandOdb.OsmAndPoiIndex.SUBTYPESTABLE_FIELD_NUMBER:
if(!readCategories){ if (!readCategories) {
codedIS.skipRawBytes(codedIS.getBytesUntilLimit()); codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
return; return;
} }
@ -191,7 +190,7 @@ public class BinaryMapPoiReaderAdapter {
readSubtypes(region); readSubtypes(region);
codedIS.popLimit(oldLimit); codedIS.popLimit(oldLimit);
break; break;
case OsmandOdb.OsmAndPoiIndex.BOXES_FIELD_NUMBER : case OsmandOdb.OsmAndPoiIndex.BOXES_FIELD_NUMBER:
codedIS.skipRawBytes(codedIS.getBytesUntilLimit()); codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
return; return;
default: default:
@ -202,19 +201,19 @@ public class BinaryMapPoiReaderAdapter {
} }
private void readCategory(PoiRegion region) throws IOException { private void readCategory(PoiRegion region) throws IOException {
while(true){ while (true) {
int t = codedIS.readTag(); int t = codedIS.readTag();
int tag = WireFormat.getTagFieldNumber(t); int tag = WireFormat.getTagFieldNumber(t);
switch (tag) { switch (tag) {
case 0: case 0:
return; return;
case OsmandOdb.OsmAndCategoryTable.CATEGORY_FIELD_NUMBER : case OsmandOdb.OsmAndCategoryTable.CATEGORY_FIELD_NUMBER:
String cat = codedIS.readString().intern(); String cat = codedIS.readString().intern();
region.categories.add(cat); region.categories.add(cat);
region.categoriesType.add(poiTypes.getPoiCategoryByName(cat.toLowerCase())); region.categoriesType.add(poiTypes.getPoiCategoryByName(cat.toLowerCase()));
region.subcategories.add(new ArrayList<String>()); region.subcategories.add(new ArrayList<String>());
break; break;
case OsmandOdb.OsmAndCategoryTable.SUBCATEGORIES_FIELD_NUMBER : case OsmandOdb.OsmAndCategoryTable.SUBCATEGORIES_FIELD_NUMBER:
region.subcategories.get(region.subcategories.size() - 1).add(codedIS.readString().intern()); region.subcategories.get(region.subcategories.size() - 1).add(codedIS.readString().intern());
break; break;
default: default:
@ -225,27 +224,27 @@ public class BinaryMapPoiReaderAdapter {
} }
private void readSubtypes(PoiRegion region) throws IOException { private void readSubtypes(PoiRegion region) throws IOException {
while(true){ while (true) {
int outT = codedIS.readTag(); int outT = codedIS.readTag();
int outTag = WireFormat.getTagFieldNumber(outT); int outTag = WireFormat.getTagFieldNumber(outT);
switch(outTag) { switch (outTag) {
case 0: case 0:
return; return;
case OsmandOdb.OsmAndSubtypesTable.SUBTYPES_FIELD_NUMBER : case OsmandOdb.OsmAndSubtypesTable.SUBTYPES_FIELD_NUMBER:
int length = codedIS.readRawVarint32(); int length = codedIS.readRawVarint32();
int oldLimit = codedIS.pushLimit(length); int oldLimit = codedIS.pushLimit(length);
PoiSubType st = new PoiSubType(); PoiSubType st = new PoiSubType();
cycle: while(true){ cycle: while(true){
int inT = codedIS.readTag(); int inT = codedIS.readTag();
int inTag = WireFormat.getTagFieldNumber(inT); int inTag = WireFormat.getTagFieldNumber(inT);
switch(inTag) { switch (inTag) {
case 0: case 0:
break cycle; break cycle;
case OsmandOdb.OsmAndPoiSubtype.NAME_FIELD_NUMBER: case OsmandOdb.OsmAndPoiSubtype.NAME_FIELD_NUMBER:
st.name = codedIS.readString().intern(); st.name = codedIS.readString().intern();
break; break;
case OsmandOdb.OsmAndPoiSubtype.SUBTYPEVALUE_FIELD_NUMBER: case OsmandOdb.OsmAndPoiSubtype.SUBTYPEVALUE_FIELD_NUMBER:
if(st.possibleValues == null) { if (st.possibleValues == null) {
st.possibleValues = new ArrayList<String>(); st.possibleValues = new ArrayList<String>();
} }
st.possibleValues.add(codedIS.readString().intern()); st.possibleValues.add(codedIS.readString().intern());
@ -269,7 +268,7 @@ public class BinaryMapPoiReaderAdapter {
} }
public void initCategories(PoiRegion region) throws IOException { public void initCategories(PoiRegion region) throws IOException {
if(region.categories.isEmpty()) { if (region.categories.isEmpty()) {
codedIS.seek(region.filePointer); codedIS.seek(region.filePointer);
int oldLimit = codedIS.pushLimit(region.length); int oldLimit = codedIS.pushLimit(region.length);
readPoiIndex(region, true); readPoiIndex(region, true);
@ -277,15 +276,15 @@ public class BinaryMapPoiReaderAdapter {
} }
} }
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 = req.nameQuery.toLowerCase();
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();
int indexOffset = codedIS.getTotalBytesRead(); int indexOffset = codedIS.getTotalBytesRead();
while(true){ while (true) {
if(req.isCancelled()){ if (req.isCancelled()) {
return; return;
} }
int t = codedIS.readTag(); int t = codedIS.readTag();
@ -293,14 +292,14 @@ public class BinaryMapPoiReaderAdapter {
switch (tag) { switch (tag) {
case 0: case 0:
return; return;
case OsmandOdb.OsmAndPoiIndex.NAMEINDEX_FIELD_NUMBER : case OsmandOdb.OsmAndPoiIndex.NAMEINDEX_FIELD_NUMBER:
int length = readInt(); int length = readInt();
int oldLimit = codedIS.pushLimit(length); int oldLimit = codedIS.pushLimit(length);
// here offsets are sorted by distance // here offsets are sorted by distance
offsets = readPoiNameIndex(matcher.getCollator(), query, req); offsets = readPoiNameIndex(matcher.getCollator(), query, req);
codedIS.popLimit(oldLimit); codedIS.popLimit(oldLimit);
break; break;
case OsmandOdb.OsmAndPoiIndex.POIDATA_FIELD_NUMBER : case OsmandOdb.OsmAndPoiIndex.POIDATA_FIELD_NUMBER:
// also offsets can be randomly skipped by limit // also offsets can be randomly skipped by limit
Integer[] offKeys = new Integer[offsets.size()]; Integer[] offKeys = new Integer[offsets.size()];
if (offsets.size() > 0) { if (offsets.size() > 0) {
@ -315,9 +314,9 @@ public class BinaryMapPoiReaderAdapter {
return Double.compare(foffsets.get(object1), foffsets.get(object2)); return Double.compare(foffsets.get(object1), foffsets.get(object2));
} }
}); });
int p = BUCKET_SEARCH_BY_NAME * 3 ; int p = BUCKET_SEARCH_BY_NAME * 3;
if (p < offKeys.length) { if (p < offKeys.length) {
for (int i = p + BUCKET_SEARCH_BY_NAME;; i += BUCKET_SEARCH_BY_NAME) { for (int i = p + BUCKET_SEARCH_BY_NAME; ; i += BUCKET_SEARCH_BY_NAME) {
if (i > offKeys.length) { if (i > offKeys.length) {
Arrays.sort(offKeys, p, offKeys.length); Arrays.sort(offKeys, p, offKeys.length);
break; break;
@ -330,19 +329,19 @@ public class BinaryMapPoiReaderAdapter {
} }
LOG.info("Searched poi structure in "+(System.currentTimeMillis() - time) + LOG.info("Searched poi structure in " + (System.currentTimeMillis() - time) +
"ms. Found " + offKeys.length +" subtrees"); "ms. Found " + offKeys.length + " subtrees");
for (int j = 0; j < offKeys.length; j++) { for (int j = 0; j < offKeys.length; j++) {
codedIS.seek(offKeys[j] + indexOffset); codedIS.seek(offKeys[j] + indexOffset);
int len = readInt(); int len = readInt();
int oldLim = codedIS.pushLimit(len); int oldLim = codedIS.pushLimit(len);
readPoiData(matcher, req, region); readPoiData(matcher, req, region);
codedIS.popLimit(oldLim); codedIS.popLimit(oldLim);
if(req.isCancelled() || req.limitExceeded()){ if (req.isCancelled() || req.limitExceeded()) {
return; return;
} }
} }
LOG.info("Whole poi by name search is done in "+(System.currentTimeMillis() - time) + LOG.info("Whole poi by name search is done in " + (System.currentTimeMillis() - time) +
"ms. Found " + req.getSearchResults().size()); "ms. Found " + req.getSearchResults().size());
codedIS.skipRawBytes(codedIS.getBytesUntilLimit()); codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
return; return;
@ -357,22 +356,23 @@ public class BinaryMapPoiReaderAdapter {
TIntLongHashMap offsets = new TIntLongHashMap(); TIntLongHashMap offsets = new TIntLongHashMap();
TIntArrayList dataOffsets = null; TIntArrayList dataOffsets = null;
int offset = 0; int offset = 0;
while(true){ while (true) {
int t = codedIS.readTag(); int t = codedIS.readTag();
int tag = WireFormat.getTagFieldNumber(t); int tag = WireFormat.getTagFieldNumber(t);
switch (tag) { switch (tag) {
case 0: case 0:
return offsets; return offsets;
case OsmandOdb.OsmAndPoiNameIndex.TABLE_FIELD_NUMBER : { case OsmandOdb.OsmAndPoiNameIndex.TABLE_FIELD_NUMBER: {
int length = readInt(); int length = readInt();
int oldLimit = codedIS.pushLimit(length); int oldLimit = codedIS.pushLimit(length);
dataOffsets = new TIntArrayList(); dataOffsets = new TIntArrayList();
offset = codedIS.getTotalBytesRead(); offset = codedIS.getTotalBytesRead();
map.readIndexedStringTable(instance, query, "", dataOffsets, 0); map.readIndexedStringTable(instance, query, "", dataOffsets, 0);
codedIS.popLimit(oldLimit); codedIS.popLimit(oldLimit);
break; } break;
case OsmandOdb.OsmAndPoiNameIndex.DATA_FIELD_NUMBER : { }
if(dataOffsets != null){ case OsmandOdb.OsmAndPoiNameIndex.DATA_FIELD_NUMBER: {
if (dataOffsets != null) {
dataOffsets.sort(); // 1104125 dataOffsets.sort(); // 1104125
for (int i = 0; i < dataOffsets.size(); i++) { for (int i = 0; i < dataOffsets.size(); i++) {
codedIS.seek(dataOffsets.get(i) + offset); codedIS.seek(dataOffsets.get(i) + offset);
@ -387,7 +387,8 @@ public class BinaryMapPoiReaderAdapter {
} }
} }
codedIS.skipRawBytes(codedIS.getBytesUntilLimit()); codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
return offsets; } return offsets;
}
default: default:
skipUnknownField(t); skipUnknownField(t);
break; break;
@ -397,13 +398,13 @@ public class BinaryMapPoiReaderAdapter {
} }
private void readPoiNameIndexData(TIntLongHashMap offsets, SearchRequest<Amenity> req) throws IOException { private void readPoiNameIndexData(TIntLongHashMap offsets, SearchRequest<Amenity> req) throws IOException {
while(true){ while (true) {
int t = codedIS.readTag(); int t = codedIS.readTag();
int tag = WireFormat.getTagFieldNumber(t); int tag = WireFormat.getTagFieldNumber(t);
switch (tag) { switch (tag) {
case 0: case 0:
return; return;
case OsmAndPoiNameIndexData.ATOMS_FIELD_NUMBER : case OsmAndPoiNameIndexData.ATOMS_FIELD_NUMBER:
int len = codedIS.readRawVarint32(); int len = codedIS.readRawVarint32();
int oldLim = codedIS.pushLimit(len); int oldLim = codedIS.pushLimit(len);
readPoiNameIndexDataAtom(offsets, req); readPoiNameIndexDataAtom(offsets, req);
@ -414,29 +415,28 @@ public class BinaryMapPoiReaderAdapter {
break; break;
} }
} }
} }
private void readPoiNameIndexDataAtom(TIntLongHashMap offsets, SearchRequest<Amenity> req) throws IOException { private void readPoiNameIndexDataAtom(TIntLongHashMap offsets, SearchRequest<Amenity> req) throws IOException {
int x = 0; int x = 0;
int y = 0; int y = 0;
int zoom = 15; int zoom = 15;
while(true){ while (true) {
int t = codedIS.readTag(); int t = codedIS.readTag();
int tag = WireFormat.getTagFieldNumber(t); int tag = WireFormat.getTagFieldNumber(t);
switch (tag) { switch (tag) {
case 0: case 0:
return; return;
case OsmandOdb.OsmAndPoiNameIndexDataAtom.X_FIELD_NUMBER : case OsmandOdb.OsmAndPoiNameIndexDataAtom.X_FIELD_NUMBER:
x = codedIS.readUInt32(); x = codedIS.readUInt32();
break; break;
case OsmandOdb.OsmAndPoiNameIndexDataAtom.Y_FIELD_NUMBER : case OsmandOdb.OsmAndPoiNameIndexDataAtom.Y_FIELD_NUMBER:
y = codedIS.readUInt32(); y = codedIS.readUInt32();
break; break;
case OsmandOdb.OsmAndPoiNameIndexDataAtom.ZOOM_FIELD_NUMBER : case OsmandOdb.OsmAndPoiNameIndexDataAtom.ZOOM_FIELD_NUMBER:
zoom = codedIS.readUInt32(); zoom = codedIS.readUInt32();
break; break;
case OsmandOdb.OsmAndPoiNameIndexDataAtom.SHIFTTO_FIELD_NUMBER : case OsmandOdb.OsmAndPoiNameIndexDataAtom.SHIFTTO_FIELD_NUMBER:
int x31 = (x << (31 - zoom)); int x31 = (x << (31 - zoom));
int y31 = (y << (31 - zoom)); int y31 = (y << (31 - zoom));
int shift = readInt(); int shift = readInt();
@ -458,14 +458,14 @@ public class BinaryMapPoiReaderAdapter {
int indexOffset = codedIS.getTotalBytesRead(); int indexOffset = codedIS.getTotalBytesRead();
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
TLongHashSet skipTiles = null; TLongHashSet skipTiles = null;
if(req.zoom >= 0 && req.zoom < 16){ if (req.zoom >= 0 && req.zoom < 16) {
skipTiles = new TLongHashSet(); skipTiles = new TLongHashSet();
} }
int length ; int length;
int oldLimit ; int oldLimit;
TIntLongHashMap offsetsMap = new TIntLongHashMap(); TIntLongHashMap offsetsMap = new TIntLongHashMap();
while(true){ while (true) {
if(req.isCancelled()){ if (req.isCancelled()) {
return; return;
} }
int t = codedIS.readTag(); int t = codedIS.readTag();
@ -473,17 +473,17 @@ public class BinaryMapPoiReaderAdapter {
switch (tag) { switch (tag) {
case 0: case 0:
return; return;
case OsmandOdb.OsmAndPoiIndex.BOXES_FIELD_NUMBER : case OsmandOdb.OsmAndPoiIndex.BOXES_FIELD_NUMBER:
length = readInt(); length = readInt();
oldLimit = codedIS.pushLimit(length); oldLimit = codedIS.pushLimit(length);
readBoxField(left31, right31, top31, bottom31, 0, 0, 0, offsetsMap, skipTiles, req, region); readBoxField(left31, right31, top31, bottom31, 0, 0, 0, offsetsMap, skipTiles, req, region);
codedIS.popLimit(oldLimit); codedIS.popLimit(oldLimit);
break; break;
case OsmandOdb.OsmAndPoiIndex.POIDATA_FIELD_NUMBER : case OsmandOdb.OsmAndPoiIndex.POIDATA_FIELD_NUMBER:
int[] offsets = offsetsMap.keys(); int[] offsets = offsetsMap.keys();
// also offsets can be randomly skipped by limit // also offsets can be randomly skipped by limit
Arrays.sort(offsets); Arrays.sort(offsets);
if(skipTiles != null){ if (skipTiles != null) {
skipTiles.clear(); skipTiles.clear();
} }
LOG.info("Searched poi structure in " + (System.currentTimeMillis() - time) + " ms. Found " LOG.info("Searched poi structure in " + (System.currentTimeMillis() - time) + " ms. Found "
@ -503,12 +503,12 @@ public class BinaryMapPoiReaderAdapter {
int len = readInt(); int len = readInt();
int oldLim = codedIS.pushLimit(len); int oldLim = codedIS.pushLimit(len);
boolean read = readPoiData(left31, right31, top31, bottom31, req, region, skipTiles, boolean read = readPoiData(left31, right31, top31, bottom31, req, region, skipTiles,
req.zoom == -1 ? 31 : req.zoom + ZOOM_TO_SKIP_FILTER ); req.zoom == -1 ? 31 : req.zoom + ZOOM_TO_SKIP_FILTER);
if(read && skipVal != -1 && skipTiles != null) { if (read && skipVal != -1 && skipTiles != null) {
skipTiles.add(skipVal); skipTiles.add(skipVal);
} }
codedIS.popLimit(oldLim); codedIS.popLimit(oldLim);
if(req.isCancelled()){ if (req.isCancelled()) {
return; return;
} }
} }
@ -525,8 +525,8 @@ public class BinaryMapPoiReaderAdapter {
int x = 0; int x = 0;
int y = 0; int y = 0;
int zoom = 0; int zoom = 0;
while(true){ while (true) {
if(req.isCancelled() || req.limitExceeded()){ if (req.isCancelled() || req.limitExceeded()) {
return; return;
} }
int t = codedIS.readTag(); int t = codedIS.readTag();
@ -534,13 +534,13 @@ public class BinaryMapPoiReaderAdapter {
switch (tag) { switch (tag) {
case 0: case 0:
return; return;
case OsmandOdb.OsmAndPoiBoxData.X_FIELD_NUMBER : case OsmandOdb.OsmAndPoiBoxData.X_FIELD_NUMBER:
x = codedIS.readUInt32(); x = codedIS.readUInt32();
break; break;
case OsmandOdb.OsmAndPoiBoxData.ZOOM_FIELD_NUMBER : case OsmandOdb.OsmAndPoiBoxData.ZOOM_FIELD_NUMBER:
zoom = codedIS.readUInt32(); zoom = codedIS.readUInt32();
break; break;
case OsmandOdb.OsmAndPoiBoxData.Y_FIELD_NUMBER : case OsmandOdb.OsmAndPoiBoxData.Y_FIELD_NUMBER:
y = codedIS.readUInt32(); y = codedIS.readUInt32();
break; break;
case OsmandOdb.OsmAndPoiBoxData.POIDATA_FIELD_NUMBER: case OsmandOdb.OsmAndPoiBoxData.POIDATA_FIELD_NUMBER:
@ -552,9 +552,9 @@ public class BinaryMapPoiReaderAdapter {
boolean matches = matcher.matches(am.getName().toLowerCase()) || boolean matches = matcher.matches(am.getName().toLowerCase()) ||
matcher.matches(am.getEnName(true).toLowerCase()); matcher.matches(am.getEnName(true).toLowerCase());
if (!matches) { if (!matches) {
for(String s : am.getAllNames()) { for (String s : am.getAllNames()) {
matches = matcher.matches(s.toLowerCase()); matches = matcher.matches(s.toLowerCase());
if(matches) { if (matches) {
break; break;
} }
} }
@ -566,7 +566,7 @@ public class BinaryMapPoiReaderAdapter {
} }
} }
} }
if(matches) { if (matches) {
req.publish(am); req.publish(am);
} }
} }
@ -584,8 +584,8 @@ public class BinaryMapPoiReaderAdapter {
int y = 0; int y = 0;
int zoom = 0; int zoom = 0;
boolean read = false; boolean read = false;
while(true){ while (true) {
if(req.isCancelled()){ if (req.isCancelled()) {
return read; return read;
} }
int t = codedIS.readTag(); int t = codedIS.readTag();
@ -593,13 +593,13 @@ public class BinaryMapPoiReaderAdapter {
switch (tag) { switch (tag) {
case 0: case 0:
return read; return read;
case OsmandOdb.OsmAndPoiBoxData.X_FIELD_NUMBER : case OsmandOdb.OsmAndPoiBoxData.X_FIELD_NUMBER:
x = codedIS.readUInt32(); x = codedIS.readUInt32();
break; break;
case OsmandOdb.OsmAndPoiBoxData.ZOOM_FIELD_NUMBER : case OsmandOdb.OsmAndPoiBoxData.ZOOM_FIELD_NUMBER:
zoom = codedIS.readUInt32(); zoom = codedIS.readUInt32();
break; break;
case OsmandOdb.OsmAndPoiBoxData.Y_FIELD_NUMBER : case OsmandOdb.OsmAndPoiBoxData.Y_FIELD_NUMBER:
y = codedIS.readUInt32(); y = codedIS.readUInt32();
break; break;
case OsmandOdb.OsmAndPoiBoxData.POIDATA_FIELD_NUMBER: case OsmandOdb.OsmAndPoiBoxData.POIDATA_FIELD_NUMBER:
@ -614,16 +614,16 @@ public class BinaryMapPoiReaderAdapter {
long valSkip = (((long) xp) << zSkip) | yp; long valSkip = (((long) xp) << zSkip) | yp;
if (!toSkip.contains(valSkip)) { if (!toSkip.contains(valSkip)) {
boolean publish = req.publish(am); boolean publish = req.publish(am);
if(publish) { if (publish) {
read = true; read = true;
toSkip.add(valSkip); toSkip.add(valSkip);
} }
} else if(zSkip <= zoom){ } else if (zSkip <= zoom) {
codedIS.skipRawBytes(codedIS.getBytesUntilLimit()); codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
return read; return read;
} }
} else { } else {
if(req.publish(am)) { if (req.publish(am)) {
read = true; read = true;
} }
} }
@ -659,6 +659,7 @@ public class BinaryMapPoiReaderAdapter {
} }
return arp; return arp;
} }
private Amenity readPoiPoint(int left31, int right31, int top31, int bottom31, private Amenity readPoiPoint(int left31, int right31, int top31, int bottom31,
int px, int py, int zoom, SearchRequest<Amenity> req, PoiRegion region, boolean checkBounds) throws IOException { int px, int py, int zoom, SearchRequest<Amenity> req, PoiRegion region, boolean checkBounds) throws IOException {
Amenity am = null; Amenity am = null;
@ -667,10 +668,10 @@ public class BinaryMapPoiReaderAdapter {
StringBuilder retValue = new StringBuilder(); StringBuilder retValue = new StringBuilder();
PoiCategory amenityType = null; PoiCategory amenityType = null;
LinkedList<String> textTags = null; LinkedList<String> textTags = null;
while(true){ while (true) {
int t = codedIS.readTag(); int t = codedIS.readTag();
int tag = WireFormat.getTagFieldNumber(t); int tag = WireFormat.getTagFieldNumber(t);
if(amenityType == null && (tag > OsmandOdb.OsmAndPoiBoxDataAtom.CATEGORIES_FIELD_NUMBER || tag == 0)) { if (amenityType == null && (tag > OsmandOdb.OsmAndPoiBoxDataAtom.CATEGORIES_FIELD_NUMBER || tag == 0)) {
codedIS.skipRawBytes(codedIS.getBytesUntilLimit()); codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
return null; return null;
} }
@ -684,17 +685,17 @@ public class BinaryMapPoiReaderAdapter {
return null; return null;
} }
AmenityRoutePoint arp = dist(am.getLocation(), locs, req.radius); AmenityRoutePoint arp = dist(am.getLocation(), locs, req.radius);
if (arp == null){ if (arp == null) {
return null; return null;
} else { } else {
am.setRoutePoint(arp); am.setRoutePoint(arp);
} }
} }
return am; return am;
case OsmandOdb.OsmAndPoiBoxDataAtom.DX_FIELD_NUMBER : case OsmandOdb.OsmAndPoiBoxDataAtom.DX_FIELD_NUMBER:
x = (codedIS.readSInt32() + (px << (24 - zoom))) << 7; x = (codedIS.readSInt32() + (px << (24 - zoom))) << 7;
break; break;
case OsmandOdb.OsmAndPoiBoxDataAtom.DY_FIELD_NUMBER : case OsmandOdb.OsmAndPoiBoxDataAtom.DY_FIELD_NUMBER:
y = (codedIS.readSInt32() + (py << (24 - zoom))) << 7; y = (codedIS.readSInt32() + (py << (24 - zoom))) << 7;
req.numberOfVisitedObjects++; req.numberOfVisitedObjects++;
if (checkBounds) { if (checkBounds) {
@ -706,32 +707,32 @@ public class BinaryMapPoiReaderAdapter {
am = new Amenity(); am = new Amenity();
am.setLocation(MapUtils.get31LatitudeY(y), MapUtils.get31LongitudeX(x)); am.setLocation(MapUtils.get31LatitudeY(y), MapUtils.get31LongitudeX(x));
break; break;
case OsmandOdb.OsmAndPoiBoxDataAtom.SUBCATEGORIES_FIELD_NUMBER : case OsmandOdb.OsmAndPoiBoxDataAtom.SUBCATEGORIES_FIELD_NUMBER:
int subtypev = codedIS.readUInt32(); int subtypev = codedIS.readUInt32();
retValue.setLength(0); retValue.setLength(0);
PoiSubType st = region.getSubtypeFromId(subtypev, retValue); PoiSubType st = region.getSubtypeFromId(subtypev, retValue);
if(st != null) { if (st != null) {
am.setAdditionalInfo(st.name, retValue.toString()); am.setAdditionalInfo(st.name, retValue.toString());
} }
break; break;
case OsmandOdb.OsmAndPoiBoxDataAtom.TEXTCATEGORIES_FIELD_NUMBER : case OsmandOdb.OsmAndPoiBoxDataAtom.TEXTCATEGORIES_FIELD_NUMBER:
int texttypev = codedIS.readUInt32(); int texttypev = codedIS.readUInt32();
retValue.setLength(0); retValue.setLength(0);
PoiSubType textt = region.getSubtypeFromId(texttypev, retValue); PoiSubType textt = region.getSubtypeFromId(texttypev, retValue);
if(textt != null && textt.text) { if (textt != null && textt.text) {
if(textTags == null) { if (textTags == null) {
textTags = new LinkedList<String>(); textTags = new LinkedList<String>();
} }
textTags.add(textt.name); textTags.add(textt.name);
} }
break; break;
case OsmandOdb.OsmAndPoiBoxDataAtom.TEXTVALUES_FIELD_NUMBER : case OsmandOdb.OsmAndPoiBoxDataAtom.TEXTVALUES_FIELD_NUMBER:
String str = codedIS.readString(); String str = codedIS.readString();
if(textTags != null && !textTags.isEmpty()) { if (textTags != null && !textTags.isEmpty()) {
am.setAdditionalInfo(textTags.poll(), str); am.setAdditionalInfo(textTags.poll(), str);
} }
break; break;
case OsmandOdb.OsmAndPoiBoxDataAtom.CATEGORIES_FIELD_NUMBER : case OsmandOdb.OsmAndPoiBoxDataAtom.CATEGORIES_FIELD_NUMBER:
int cat = codedIS.readUInt32(); int cat = codedIS.readUInt32();
int subcatId = cat >> SHIFT_BITS_CATEGORY; int subcatId = cat >> SHIFT_BITS_CATEGORY;
int catId = cat & CATEGORY_MASK; int catId = cat & CATEGORY_MASK;
@ -753,21 +754,20 @@ public class BinaryMapPoiReaderAdapter {
am.setSubType(am.getSubType() + ";" + subtype); am.setSubType(am.getSubType() + ";" + subtype);
} }
} }
break; break;
case OsmandOdb.OsmAndPoiBoxDataAtom.ID_FIELD_NUMBER : case OsmandOdb.OsmAndPoiBoxDataAtom.ID_FIELD_NUMBER:
am.setId(codedIS.readUInt64()); am.setId(codedIS.readUInt64());
break; break;
case OsmandOdb.OsmAndPoiBoxDataAtom.NAME_FIELD_NUMBER : case OsmandOdb.OsmAndPoiBoxDataAtom.NAME_FIELD_NUMBER:
am.setName(codedIS.readString()); am.setName(codedIS.readString());
break; break;
case OsmandOdb.OsmAndPoiBoxDataAtom.NAMEEN_FIELD_NUMBER : case OsmandOdb.OsmAndPoiBoxDataAtom.NAMEEN_FIELD_NUMBER:
am.setEnName(codedIS.readString()); am.setEnName(codedIS.readString());
break; break;
case OsmandOdb.OsmAndPoiBoxDataAtom.OPENINGHOURS_FIELD_NUMBER : case OsmandOdb.OsmAndPoiBoxDataAtom.OPENINGHOURS_FIELD_NUMBER:
am.setOpeningHours(codedIS.readString()); am.setOpeningHours(codedIS.readString());
break; break;
case OsmandOdb.OsmAndPoiBoxDataAtom.SITE_FIELD_NUMBER : case OsmandOdb.OsmAndPoiBoxDataAtom.SITE_FIELD_NUMBER:
am.setSite(codedIS.readString()); am.setSite(codedIS.readString());
break; break;
case OsmandOdb.OsmAndPoiBoxDataAtom.PHONE_FIELD_NUMBER: case OsmandOdb.OsmAndPoiBoxDataAtom.PHONE_FIELD_NUMBER:
@ -785,7 +785,7 @@ public class BinaryMapPoiReaderAdapter {
private boolean checkCategories(SearchRequest<Amenity> req, PoiRegion region) throws IOException { private boolean checkCategories(SearchRequest<Amenity> req, PoiRegion region) throws IOException {
StringBuilder subType = new StringBuilder(); StringBuilder subType = new StringBuilder();
while(true){ while (true) {
int t = codedIS.readTag(); int t = codedIS.readTag();
int tag = WireFormat.getTagFieldNumber(t); int tag = WireFormat.getTagFieldNumber(t);
switch (tag) { switch (tag) {
@ -808,18 +808,17 @@ public class BinaryMapPoiReaderAdapter {
int cat = codedIS.readUInt32(); int cat = codedIS.readUInt32();
int subcatId = cat >> SHIFT_BITS_CATEGORY; int subcatId = cat >> SHIFT_BITS_CATEGORY;
int catId = cat & CATEGORY_MASK; int catId = cat & CATEGORY_MASK;
if(catId < region.categoriesType.size()){ if (catId < region.categoriesType.size()) {
type = region.categoriesType.get(catId); type = region.categoriesType.get(catId);
List<String> subcats = region.subcategories.get(catId); List<String> subcats = region.subcategories.get(catId);
if(subcatId < subcats.size()){ if (subcatId < subcats.size()) {
subcat = subcats.get(subcatId); subcat = subcats.get(subcatId);
} }
} }
if(req.poiTypeFilter.accept(type, subcat)){ if (req.poiTypeFilter.accept(type, subcat)) {
codedIS.skipRawBytes(codedIS.getBytesUntilLimit()); codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
return true; return true;
} }
break; break;
default: default:
skipUnknownField(t); skipUnknownField(t);
@ -838,8 +837,8 @@ public class BinaryMapPoiReaderAdapter {
int zoom = pzoom; int zoom = pzoom;
int dy = py; int dy = py;
int dx = px; int dx = px;
while(true){ while (true) {
if(req.isCancelled()){ if (req.isCancelled()) {
return false; return false;
} }
int t = codedIS.readTag(); int t = codedIS.readTag();
@ -847,31 +846,30 @@ public class BinaryMapPoiReaderAdapter {
switch (tag) { switch (tag) {
case 0: case 0:
return existsCategories; return existsCategories;
case OsmandOdb.OsmAndPoiBox.ZOOM_FIELD_NUMBER : case OsmandOdb.OsmAndPoiBox.ZOOM_FIELD_NUMBER:
zoom = codedIS.readUInt32() + pzoom; zoom = codedIS.readUInt32() + pzoom;
break; break;
case OsmandOdb.OsmAndPoiBox.LEFT_FIELD_NUMBER : case OsmandOdb.OsmAndPoiBox.LEFT_FIELD_NUMBER:
dx = codedIS.readSInt32(); dx = codedIS.readSInt32();
break; break;
case OsmandOdb.OsmAndPoiBox.TOP_FIELD_NUMBER: case OsmandOdb.OsmAndPoiBox.TOP_FIELD_NUMBER:
dy = codedIS.readSInt32(); dy = codedIS.readSInt32();
break; break;
case OsmandOdb.OsmAndPoiBox.CATEGORIES_FIELD_NUMBER: case OsmandOdb.OsmAndPoiBox.CATEGORIES_FIELD_NUMBER:
if(req.poiTypeFilter == null){ if (req.poiTypeFilter == null) {
skipUnknownField(t); skipUnknownField(t);
} else { } else {
int length = codedIS.readRawVarint32(); int length = codedIS.readRawVarint32();
int oldLimit = codedIS.pushLimit(length); int oldLimit = codedIS.pushLimit(length);
boolean check = checkCategories(req, region); boolean check = checkCategories(req, region);
codedIS.popLimit(oldLimit); codedIS.popLimit(oldLimit);
if(!check){ if (!check) {
codedIS.skipRawBytes(codedIS.getBytesUntilLimit()); codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
return false; return false;
} }
existsCategories = true; existsCategories = true;
} }
break; break;
case OsmandOdb.OsmAndPoiBox.SUBBOXES_FIELD_NUMBER: { case OsmandOdb.OsmAndPoiBox.SUBBOXES_FIELD_NUMBER: {
int x = dx + (px << (zoom - pzoom)); int x = dx + (px << (zoom - pzoom));
int y = dy + (py << (zoom - pzoom)); int y = dy + (py << (zoom - pzoom));
@ -896,17 +894,18 @@ public class BinaryMapPoiReaderAdapter {
if (skipTiles != null && zoom >= zoomToSkip && exists) { if (skipTiles != null && zoom >= zoomToSkip && exists) {
long val = ((((long) x) >> (zoom - zoomToSkip)) << zoomToSkip) | (((long) y) >> (zoom - zoomToSkip)); long val = ((((long) x) >> (zoom - zoomToSkip)) << zoomToSkip) | (((long) y) >> (zoom - zoomToSkip));
if(skipTiles.contains(val)){ if (skipTiles.contains(val)) {
codedIS.skipRawBytes(codedIS.getBytesUntilLimit()); codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
return true; return true;
} }
} }
} break; }
break;
case OsmandOdb.OsmAndPoiBox.SHIFTTODATA_FIELD_NUMBER: { case OsmandOdb.OsmAndPoiBox.SHIFTTODATA_FIELD_NUMBER: {
int x = dx + (px << (zoom - pzoom)); int x = dx + (px << (zoom - pzoom));
int y = dy + (py << (zoom - pzoom)); int y = dy + (py << (zoom - pzoom));
boolean read = true; boolean read = true;
if(req.tiles != null) { if (req.tiles != null) {
long zx = x << (SearchRequest.ZOOM_TO_SEARCH_POI - zoom); long zx = x << (SearchRequest.ZOOM_TO_SEARCH_POI - zoom);
long zy = y << (SearchRequest.ZOOM_TO_SEARCH_POI - zoom); long zy = y << (SearchRequest.ZOOM_TO_SEARCH_POI - zoom);
read = req.tiles.contains((zx << SearchRequest.ZOOM_TO_SEARCH_POI) + zy); read = req.tiles.contains((zx << SearchRequest.ZOOM_TO_SEARCH_POI) + zy);
@ -922,7 +921,8 @@ public class BinaryMapPoiReaderAdapter {
offsetsMap.put(offset, -1); offsetsMap.put(offset, -1);
} }
} }
} break; }
break;
default: default:
skipUnknownField(t); skipUnknownField(t);
break; break;