From 7211a51b6443152d8bde94612e411666f9748dd0 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 30 Aug 2017 22:35:41 +0200 Subject: [PATCH] Fix issue with diff generation --- .../binary/BinaryMapRouteReaderAdapter.java | 96 ++++++++++++++++++- .../net/osmand/binary/RouteDataObject.java | 24 ++++- 2 files changed, 116 insertions(+), 4 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java index 11de0d4ae1..9e69c7b7bc 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java @@ -16,12 +16,14 @@ import java.util.List; import net.osmand.PlatformUtil; import net.osmand.ResultMatcher; import net.osmand.binary.BinaryMapIndexReader.SearchRequest; +import net.osmand.binary.BinaryMapIndexReader.TagValuePair; import net.osmand.binary.OsmandOdb.IdTable; import net.osmand.binary.OsmandOdb.OsmAndRoutingIndex.RouteDataBlock; import net.osmand.binary.OsmandOdb.OsmAndRoutingIndex.RouteDataBox; import net.osmand.binary.OsmandOdb.OsmAndRoutingIndex.RouteEncodingRule; import net.osmand.binary.OsmandOdb.RestrictionData; import net.osmand.binary.OsmandOdb.RouteData; +import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; import net.osmand.util.OpeningHoursParser; @@ -213,6 +215,7 @@ public class BinaryMapRouteReaderAdapter { int refTypeRule = -1; int destinationTypeRule = -1; int destinationRefTypeRule = -1; + private RouteRegion referenceRouteRegion; public String getPartName() { return "Routing"; @@ -223,6 +226,17 @@ public class BinaryMapRouteReaderAdapter { return OsmandOdb.OsmAndStructure.ROUTINGINDEX_FIELD_NUMBER; } + private int searchRouteEncodingRule(String tag, String value) { + // TODO cache; + for(int k = 0; k < routeEncodingRules.size(); k++) { + RouteTypeRule rt = routeEncodingRules.get(k); + if(Algorithms.objectEquals(rt.getTag(), tag) && Algorithms.objectEquals(rt.getValue(), value)) { + return k; + } + } + return -1; + } + public RouteTypeRule quickGetEncodingRule(int id) { return routeEncodingRules.get(id); } @@ -293,10 +307,86 @@ public class BinaryMapRouteReaderAdapter { } - public RouteDataObject adopt(RouteDataObject obj) { - // TODO Auto-generated method stub - return null; + public RouteDataObject adopt(RouteDataObject o) { + if(o.region == this || o.region == referenceRouteRegion) { + return o; + } + + if(routeEncodingRules.isEmpty()) { + routeEncodingRules.addAll(o.region.routeEncodingRules); + referenceRouteRegion= o.region; + return o; + } + RouteDataObject rdo = new RouteDataObject(this); + rdo.pointsX = o.pointsX; + rdo.pointsY = o.pointsY; + rdo.id = o.id; + rdo.restrictions = o.restrictions; + + if (o.types != null) { + rdo.types = new int[o.types.length]; + for (int i = 0; i < o.types.length; i++) { + RouteTypeRule tp = o.region.routeEncodingRules.get(o.types[i]); + int ruleId = searchRouteEncodingRule(tp.getTag(), tp.getValue()); + if(ruleId != -1) { + rdo.types[i] = ruleId; + } else { + ruleId = routeEncodingRules.size() ; + initRouteEncodingRule(ruleId, tp.getTag(), tp.getValue()); + rdo.types[i] = ruleId; + } + } + } + if (o.pointTypes != null) { + rdo.pointTypes = new int[o.pointTypes.length][]; + for (int i = 0; i < o.pointTypes.length; i++) { + if (o.pointTypes[i] != null) { + rdo.pointTypes[i] = new int[o.pointTypes[i].length]; + for (int j = 0; j < o.pointTypes[i].length; j++) { + RouteTypeRule tp = o.region.routeEncodingRules.get(o.pointTypes[i][j]); + int ruleId = searchRouteEncodingRule(tp.getTag(), tp.getValue()); + if(ruleId != -1) { + rdo.pointTypes[i][j] = ruleId; + } else { + ruleId = routeEncodingRules.size() ; + initRouteEncodingRule(ruleId, tp.getTag(), tp.getValue()); + rdo.pointTypes[i][j] = ruleId; + } + } + } + } + } + // TODO + // rdo.nameIds rdo.names; + // rdo.pointNameTypes rdo.pointNames +// BinaryMapDataObject bm = +// new BinaryMapDataObject(o.id, o.coordinates, o.polygonInnerCoordinates, o.objectType, o.area, +// types.toArray(), additionalTypes.isEmpty() ? null : additionalTypes.toArray()); +// if (o.namesOrder != null) { +// bm.objectNames = new TIntObjectHashMap<>(); +// bm.namesOrder = new TIntArrayList(); +// for (int i = 0; i < o.namesOrder.size(); i++) { +// int nameType = o.namesOrder.get(i); +// String name = o.objectNames.get(nameType); +// TagValuePair tp = o.mapIndex.decodeType(nameType); +// Integer r = getRule(tp); +// if(r != null) { +// bm.namesOrder.add(r); +// bm.objectNames.put(r, name); +// } else { +// int nid = decodingRules.size() + 1; +// initMapEncodingRule(tp.additionalAttribute, nid, tp.tag, tp.value); +// additionalTypes.add(nid); +// bm.objectNames.put(nid, name); +// } +// } +// } +// return bm; + return rdo; } + + + } // Used in C++ diff --git a/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java b/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java index 749e14c829..06d892ae95 100644 --- a/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java +++ b/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java @@ -112,7 +112,29 @@ public class RouteDataObject { } } } - + if (equals) { + if (this.pointTypes == null || thatObj.pointTypes == null) { + equals = this.pointTypes == thatObj.pointTypes; + } else if (pointTypes.length != thatObj.pointTypes.length) { + equals = false; + } else { + for (int i = 0; i < this.pointTypes.length && equals; i++) { + if (this.pointTypes[i] == null || thatObj.pointTypes[i] == null) { + equals = this.pointTypes[i] == thatObj.pointTypes[i]; + } else if (pointTypes[i].length != thatObj.pointTypes[i].length) { + equals = false; + } else { + for (int j = 0; j < this.pointTypes[i].length && equals; j++) { + String thisTag = region.routeEncodingRules.get(pointTypes[i][j]).getTag(); + String thisValue = region.routeEncodingRules.get(pointTypes[i][j]).getValue(); + String thatTag = thatObj.region.routeEncodingRules.get(thatObj.pointTypes[i][j]).getTag(); + String thatValue = thatObj.region.routeEncodingRules.get(thatObj.pointTypes[i][j]).getValue(); + equals = (Algorithms.objectEquals(thisTag, thatTag) && Algorithms.objectEquals(thisValue, thatValue)); + } + } + } + } + } if (equals) { if (this.pointNameTypes == null || thatObj.pointNameTypes == null) { equals = this.pointNameTypes == thatObj.pointNameTypes;