From 5bbd882e47fc857f09afe1f2ae36a23e075d22ff Mon Sep 17 00:00:00 2001 From: Pavol Zibrita Date: Wed, 26 Sep 2012 18:27:51 +0200 Subject: [PATCH] Fixed null pointer exception --- .../src/net/osmand/data/Ring.java | 41 ++++++------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/DataExtractionOSM/src/net/osmand/data/Ring.java b/DataExtractionOSM/src/net/osmand/data/Ring.java index fe97f3d6d7..d295fb0948 100644 --- a/DataExtractionOSM/src/net/osmand/data/Ring.java +++ b/DataExtractionOSM/src/net/osmand/data/Ring.java @@ -111,39 +111,22 @@ public class Ring implements Comparable { if ((w.getNodes() == null || w.getNodes().size() == 0) && !unInitializedNodes) continue; - Way newWay = null; - Way addedTo = null; - // merge the Way w with the first borderway suitable; - for (Way borderWay : borderWays) { - newWay = combineTwoWaysIfHasPoints(w, borderWay); - if(newWay != null) { - addedTo = borderWay; - } - } - if (newWay == null) { - // no suitable borderWay has been found, add this way as one of the boundaries - borderWays.add(w); - } else { - // ways are combined, remove the original borderway - borderWays.remove(addedTo); - addedTo = null; - // search if it can be combined with something else + // merge the Way w with the first borderway suitable, repeat until nothing can be merged + Way wayToMerge = w; + Way newWay; + do { + newWay = null; for (Way borderWay : borderWays) { - newWay = combineTwoWaysIfHasPoints(newWay, borderWay); + newWay = combineTwoWaysIfHasPoints(wayToMerge, borderWay); if(newWay != null) { - addedTo = borderWay; + wayToMerge = newWay; + borderWays.remove(borderWay); + break; } } - - if (addedTo != null) { - // newWay has enlarged a second time - borderWays.remove(addedTo); - } - // newWay is now a concatenation of 2 or 3 ways, needs to be added to the borderWays - borderWays.add(newWay); - - } - + } while (newWay != null); + //no suitable borderWay has been found, add this way as one of the boundaries + borderWays.add(wayToMerge); } if (borderWays.size() != 1) {