From e50dbb58ea57e535ca8a1f7aec56e2d58d166f46 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 29 Aug 2017 20:53:01 +0200 Subject: [PATCH] Make sure objects are adopted --- .../src/net/osmand/binary/BinaryInspector.java | 4 ++-- .../net/osmand/binary/BinaryMapDataObject.java | 6 ++++++ .../osmand/binary/BinaryMapIndexReader.java | 18 +++++++++++------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java index b52e20c3b7..4fb72e4f4d 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java @@ -81,8 +81,8 @@ public class BinaryInspector { // "-vstreets", "-vbuildings", "-vintersections", // "-lang=ru", // "-bbox=30.4981,50.4424,30.5195,50.4351", - "-osm="+System.getProperty("maps.dir")+"/map_full.obf.osm", - System.getProperty("maps.dir")+"/2017_08_24_15_00.obf" +// "-osm="+System.getProperty("maps.dir")+"/map_full.obf.osm", + System.getProperty("maps.dir")+"/diff/2017_08_28_01_00.obf" // System.getProperty("maps.dir")+"../temp/kiev/Ukraine_kiev-city_europe_17_06_05.obf", // System.getProperty("maps.dir")+"Ukraine_kiev-city_europe_2.obf", }); diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapDataObject.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapDataObject.java index f6a2fe2640..23866e8f82 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapDataObject.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapDataObject.java @@ -202,6 +202,12 @@ public class BinaryMapDataObject { && this.area == thatObj.area && Arrays.equals(this.polygonInnerCoordinates, thatObj.polygonInnerCoordinates) && Arrays.equals(this.coordinates, thatObj.coordinates) ) { + if(mapIndex == null) { + throw new IllegalStateException("Illegal binary object: " + id); + } + if(thatObj.mapIndex == null) { + throw new IllegalStateException("Illegal binary object: " + thatObj.id); + } boolean equals = true; if(equals) { if(types == null || thatObj.types == null) { diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java index 1c87fef158..35f6b11a7d 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java @@ -1735,6 +1735,9 @@ public class BinaryMapIndexReader { public TIntHashSet positiveLayers = new TIntHashSet(2); public TIntHashSet negativeLayers = new TIntHashSet(2); + // to speed up comparision + private MapIndex referenceMapIndex; + public Integer getRule(String t, String v) { Map m = encodingRules.get(t); if (m != null) { @@ -1835,12 +1838,13 @@ public class BinaryMapIndexReader { } public BinaryMapDataObject adoptMapObject(BinaryMapDataObject o) { - if(o.mapIndex == this) { + if(o.mapIndex == this || o.mapIndex == referenceMapIndex) { return o; } if(encodingRules.isEmpty()) { encodingRules.putAll(o.mapIndex.encodingRules); decodingRules.putAll(o.mapIndex.decodingRules); + referenceMapIndex = o.mapIndex; return o; } TIntArrayList types = new TIntArrayList(); @@ -1852,8 +1856,8 @@ public class BinaryMapIndexReader { if(r != null) { types.add(r); } else { - int nid = decodingRules.size(); - initMapEncodingRule(tp.additionalAttribute, decodingRules.size(), tp.tag, tp.value); + int nid = decodingRules.size() + 1; + initMapEncodingRule(tp.additionalAttribute, nid, tp.tag, tp.value); types.add(nid); } } @@ -1865,8 +1869,8 @@ public class BinaryMapIndexReader { if(r != null) { additionalTypes.add(r); } else { - int nid = decodingRules.size(); - initMapEncodingRule(tp.additionalAttribute, decodingRules.size(), tp.tag, tp.value); + int nid = decodingRules.size() + 1; + initMapEncodingRule(tp.additionalAttribute, nid, tp.tag, tp.value); additionalTypes.add(nid); } } @@ -1887,8 +1891,8 @@ public class BinaryMapIndexReader { bm.namesOrder.add(r); bm.objectNames.put(r, name); } else { - int nid = decodingRules.size(); - initMapEncodingRule(tp.additionalAttribute, decodingRules.size(), tp.tag, tp.value); + int nid = decodingRules.size() + 1; + initMapEncodingRule(tp.additionalAttribute, nid, tp.tag, tp.value); additionalTypes.add(nid); bm.objectNames.put(nid, name); }