Uups, I sent the wrong patch. I renamed one method of the new
FakeIdGenerator in this patch (makeFakeId instead of getFakeId).
WanMil
The Osm5XmlHandler creates fake ids for automatically generated
elements. The attached patch sources this out to the new FakeIdGenerator
which can also be used by other classes.
This will be necessary for the upcoming multipolygon patch. I also think
that some other classes might use fake ids (I haven't search the code
base yet). The class ensures that an id is used only once.
WanMil
Index: src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5XmlHandler.java
===================================================================
--- src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5XmlHandler.java
(revision 1479)
+++ src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5XmlHandler.java
(working copy)
@@ -46,6 +46,7 @@
import uk.me.parabola.mkgmap.general.RoadNetwork;
import uk.me.parabola.mkgmap.reader.osm.CoordPOI;
import uk.me.parabola.mkgmap.reader.osm.Element;
+import uk.me.parabola.mkgmap.reader.osm.FakeIdGenerator;
import uk.me.parabola.mkgmap.reader.osm.GeneralRelation;
import uk.me.parabola.mkgmap.reader.osm.MultiPolygonRelation;
import uk.me.parabola.mkgmap.reader.osm.Node;
@@ -92,8 +93,6 @@
private static final long CYCLEWAY_ID_OFFSET = 0x10000000;
- private static final long FAKE_ID_BASE = 1L << 62;
-
private Node currentNode;
private Way currentWay;
private Node currentNodeInWay;
@@ -106,8 +105,6 @@
private Area bbox;
private Runnable endTask;
- private long nextFakeId = 1;
-
private final boolean reportUndefinedNodes;
private final boolean makeOppositeCycleways;
private final boolean makeCycleways;
@@ -1054,14 +1051,6 @@
super.fatalError(e);
}
- public long makeFakeId() {
- return FAKE_ID_BASE + nextFakeId++;
- }
-
- public boolean isFakeId(long id) {
- return id >= FAKE_ID_BASE;
- }
-
private long idVal(String id) {
try {
// attempt to parse id as a number
@@ -1071,7 +1060,7 @@
// if that fails, fake a (hopefully) unique value
Long fakeIdVal = fakeIdMap.get(id);
if(fakeIdVal == null) {
- fakeIdVal = makeFakeId();
+ fakeIdVal = FakeIdGenerator.makeFakeId();
fakeIdMap.put(id, fakeIdVal);
}
//System.out.printf("%s = 0x%016x\n", id, fakeIdVal);
@@ -1096,7 +1085,7 @@
log.info("clipping " + segment);
toBeRemoved.add(segment);
for (List<Coord> pts : clipped) {
- long id = makeFakeId();
+ long id = FakeIdGenerator.makeFakeId();
Way shore = new Way(id, pts);
toBeAdded.add(shore);
}
@@ -1123,7 +1112,7 @@
// polygon so that the tile's background colour
will
// match the land colour on the tiles that do
contain
// some sea
- long landId = makeFakeId();
+ long landId = FakeIdGenerator.makeFakeId();
Way land = new Way(landId);
land.addPoint(nw);
land.addPoint(sw);
@@ -1137,7 +1126,7 @@
return;
}
- long multiId = makeFakeId();
+ long multiId = FakeIdGenerator.makeFakeId();
Relation seaRelation = null;
if(generateSeaUsingMP) {
seaRelation = new GeneralRelation(multiId);
@@ -1173,8 +1162,8 @@
if(generateSeaUsingMP)
seaRelation.addElement("inner", w);
else {
- if(!isFakeId(w.getId())) {
- Way w1 = new Way(makeFakeId());
+ if(!FakeIdGenerator.isFakeId(w.getId())) {
+ Way w1 = new
Way(FakeIdGenerator.makeFakeId());
w1.getPoints().addAll(w.getPoints());
// only copy the name tags
for(String tag : w)
@@ -1233,8 +1222,8 @@
if(generateSeaUsingMP)
seaRelation.addElement("inner",
w);
else {
- if(!isFakeId(w.getId())) {
- Way w1 = new
Way(makeFakeId());
+
if(!FakeIdGenerator.isFakeId(w.getId())) {
+ Way w1 = new
Way(FakeIdGenerator.makeFakeId());
w1.getPoints().addAll(w.getPoints());
// only copy the name
tags
for(String tag : w)
@@ -1247,7 +1236,7 @@
}
}
else if(allowSeaSectors) {
- seaId = makeFakeId();
+ seaId = FakeIdGenerator.makeFakeId();
sea = new Way(seaId);
sea.getPoints().addAll(points);
sea.addPoint(new
Coord(pEnd.getLatitude(), pStart.getLongitude()));
@@ -1273,7 +1262,7 @@
}
}
if (generateSeaBackground) {
- seaId = makeFakeId();
+ seaId = FakeIdGenerator.makeFakeId();
sea = new Way(seaId);
sea.addPoint(nw);
sea.addPoint(sw);
@@ -1290,7 +1279,7 @@
// now construct inner ways from these segments
NavigableSet<EdgeHit> hits = (NavigableSet<EdgeHit>)
hitMap.keySet();
while (!hits.isEmpty()) {
- long id = makeFakeId();
+ long id = FakeIdGenerator.makeFakeId();
Way w = new Way(id);
wayMap.put(id, w);
@@ -1350,8 +1339,8 @@
if(generateSeaUsingMP)
seaRelation.addElement("inner", w);
else {
- if(!isFakeId(w.getId())) {
- Way w1 = new Way(makeFakeId());
+ if(!FakeIdGenerator.isFakeId(w.getId())) {
+ Way w1 = new
Way(FakeIdGenerator.makeFakeId());
w1.getPoints().addAll(w.getPoints());
for(String tag : w)
if(tag.equals("name") ||
tag.endsWith(":name"))
@@ -1483,8 +1472,8 @@
log.info("merging: ", ways.size(),
w1.getId(), w2.getId());
List<Coord> points2 = w2.getPoints();
Way wm;
- if (!isFakeId(w1.getId())) {
- wm = new Way(makeFakeId());
+ if
(!FakeIdGenerator.isFakeId(w1.getId())) {
+ wm = new
Way(FakeIdGenerator.makeFakeId());
ways.remove(w1);
ways.add(wm);
wm.getPoints().addAll(points1);
Index: src/uk/me/parabola/mkgmap/reader/osm/FakeIdGenerator.java
===================================================================
--- src/uk/me/parabola/mkgmap/reader/osm/FakeIdGenerator.java (revision 0)
+++ src/uk/me/parabola/mkgmap/reader/osm/FakeIdGenerator.java (revision 0)
@@ -0,0 +1,24 @@
+package uk.me.parabola.mkgmap.reader.osm;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+public class FakeIdGenerator {
+
+ public static final long START_ID = 1L << 62;
+
+ private static final AtomicLong fakeId = new AtomicLong(START_ID);
+
+ /**
+ * Retrieves a unique id that can be used to fake OSM ids.
+ *
+ * @return a unique id
+ */
+ public static long makeFakeId() {
+ return fakeId.incrementAndGet();
+ }
+
+ public static boolean isFakeId(long id) {
+ return id >= START_ID;
+ }
+
+}
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev