From 651814bea085df7cb5c89ebfee4d17cdbc9c79ef Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 19 Aug 2017 11:18:49 +0200 Subject: [PATCH 1/2] Add method --- .../osmand/binary/BinaryMapDataObject.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapDataObject.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapDataObject.java index ef6c9a30c1..2455481ab2 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapDataObject.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapDataObject.java @@ -1,11 +1,12 @@ package net.osmand.binary; -import java.util.LinkedHashMap; -import java.util.Map; - - import gnu.trove.list.array.TIntArrayList; import gnu.trove.map.hash.TIntObjectHashMap; + +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Map; + import net.osmand.binary.BinaryMapIndexReader.MapIndex; import net.osmand.render.RenderingRulesStorage; @@ -184,5 +185,17 @@ public class BinaryMapDataObject { return coordinates[2 * ind]; } - + public boolean compareBinary(BinaryMapDataObject thatObj) { + if (this.objectType == thatObj.objectType + && Arrays.equals(this.types, thatObj.types) + && this.area == thatObj.area + && Arrays.equals(this.additionalTypes, thatObj.additionalTypes) + && Arrays.equals(this.polygonInnerCoordinates, thatObj.polygonInnerCoordinates) + && Arrays.equals(this.coordinates, thatObj.coordinates) + && this.id == thatObj.id + && Arrays.equals(this.objectNames.values(), thatObj.objectNames.values())) { + return true; + } + return false; + } } From a5a9cb9738b59a20cacb69f012d5da08a15323a7 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 19 Aug 2017 12:45:06 +0200 Subject: [PATCH 2/2] Add proper compare --- .../osmand/binary/BinaryMapDataObject.java | 89 ++++++++++++++++--- 1 file changed, 79 insertions(+), 10 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapDataObject.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapDataObject.java index 2455481ab2..3d18a662f5 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapDataObject.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapDataObject.java @@ -6,8 +6,10 @@ import gnu.trove.map.hash.TIntObjectHashMap; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.Map; +import java.util.TreeSet; import net.osmand.binary.BinaryMapIndexReader.MapIndex; +import net.osmand.binary.BinaryMapIndexReader.TagValuePair; import net.osmand.render.RenderingRulesStorage; public class BinaryMapDataObject { @@ -28,12 +30,17 @@ public class BinaryMapDataObject { public BinaryMapDataObject(){ } - public BinaryMapDataObject(int[] coordinates, int[] types, int[][] polygonInnerCoordinates, long id){ + + + public BinaryMapDataObject(long id, int[] coordinates, int[][] polygonInnerCoordinates, int objectType, boolean area, + int[] types, int[] additionalTypes){ this.polygonInnerCoordinates = polygonInnerCoordinates; this.coordinates = coordinates; - this.additionalTypes = new int[0]; + this.additionalTypes = additionalTypes; this.types = types; this.id = id; + this.objectType = objectType; + this.area = area; } protected void setCoordinates(int[] coordinates) { @@ -185,17 +192,79 @@ public class BinaryMapDataObject { return coordinates[2 * ind]; } + public boolean compareBinary(BinaryMapDataObject thatObj) { - if (this.objectType == thatObj.objectType - && Arrays.equals(this.types, thatObj.types) - && this.area == thatObj.area - && Arrays.equals(this.additionalTypes, thatObj.additionalTypes) - && Arrays.equals(this.polygonInnerCoordinates, thatObj.polygonInnerCoordinates) - && Arrays.equals(this.coordinates, thatObj.coordinates) + if(this.objectType == thatObj.objectType && this.id == thatObj.id - && Arrays.equals(this.objectNames.values(), thatObj.objectNames.values())) { - return true; + && this.area == thatObj.area + && Arrays.equals(this.polygonInnerCoordinates, thatObj.polygonInnerCoordinates) + && Arrays.equals(this.coordinates, thatObj.coordinates) ) { + boolean equals = true; + if(equals) { + if(types == null || thatObj.types == null) { + equals = types == thatObj.types; + } else if(types.length != thatObj.types.length){ + equals = false; + } else { + for(int i = 0; i < types.length && equals; i++) { + TagValuePair o = mapIndex.decodeType(types[i]); + TagValuePair s = thatObj.mapIndex.decodeType(thatObj.types[i]); + equals = o.equals(s); + } + } + } + if(equals) { + if(additionalTypes == null || thatObj.additionalTypes == null) { + equals = additionalTypes == thatObj.additionalTypes; + } else if(additionalTypes.length != thatObj.additionalTypes.length){ + equals = false; + } else { + for(int i = 0; i < additionalTypes.length && equals; i++) { + TagValuePair o = mapIndex.decodeType(additionalTypes[i]); + TagValuePair s = thatObj.mapIndex.decodeType(thatObj.additionalTypes[i]); + equals = o.equals(s); + } + } + } + if(equals) { + if(namesOrder == null || thatObj.namesOrder == null) { + equals = namesOrder == thatObj.namesOrder; + } else if(namesOrder.size() != thatObj.namesOrder.size()){ + equals = false; + } else { + for(int i = 0; i < namesOrder.size() && equals; i++) { + TagValuePair o = mapIndex.decodeType(namesOrder.get(i)); + TagValuePair s = thatObj.mapIndex.decodeType(thatObj.namesOrder.get(i)); + equals = o.equals(s); + } + } + } + if(equals) { + // here we now that name indexes are equal & it is enough to check the value sets + if(objectNames == null || thatObj.objectNames == null) { + equals = objectNames == thatObj.objectNames; + } else if(objectNames.size() != thatObj.objectNames.size()){ + equals = false; + } else { + TreeSet st = new TreeSet(Arrays.asList(objectNames.values())); + TreeSet ot = new TreeSet(Arrays.asList(thatObj.objectNames.values())); + equals = st.equals(ot); + } + } + + return equals; } + return false; } + + + public int[] getCoordinates() { + return coordinates; + } + + + public int getObjectType() { + return objectType; + } }