From: Scott Crosby <[email protected]>

---
 .../me/parabola/splitter/DensityMapCollector.java  |   12 +----
 src/uk/me/parabola/splitter/MapProcessor.java      |   32 +----------
 src/uk/me/parabola/splitter/NodeCollector.java     |   11 +----
 src/uk/me/parabola/splitter/OSMParser.java         |   10 ++--
 src/uk/me/parabola/splitter/SplitProcessor.java    |   58 ++++++++------------
 5 files changed, 32 insertions(+), 91 deletions(-)

diff --git a/src/uk/me/parabola/splitter/DensityMapCollector.java 
b/src/uk/me/parabola/splitter/DensityMapCollector.java
index ef13a01..b4a5953 100644
--- a/src/uk/me/parabola/splitter/DensityMapCollector.java
+++ b/src/uk/me/parabola/splitter/DensityMapCollector.java
@@ -56,29 +56,19 @@ class DensityMapCollector implements MapCollector {
        }
 
        @Override
-       public void startWay(int id) {}
-
-       @Override
        public void startRelation(int id) {}
 
-
-       @Override
-       public void wayTag(String key, String value) {}
-
        @Override
        public void relationTag(String key, String value) {}
 
        @Override
-       public void wayNode(int nodeId) {}
-
-       @Override
        public void relationNode(int nodeId, String role) {}
 
        @Override
        public void relationWay(int wayId, String role) {}
 
        @Override
-       public void endWay() {}
+       public void processWay(Way w) {}
 
        @Override
        public void endRelation() {}
diff --git a/src/uk/me/parabola/splitter/MapProcessor.java 
b/src/uk/me/parabola/splitter/MapProcessor.java
index 536bcb1..b179d85 100644
--- a/src/uk/me/parabola/splitter/MapProcessor.java
+++ b/src/uk/me/parabola/splitter/MapProcessor.java
@@ -34,12 +34,6 @@ public interface MapProcessor {
        void boundTag(Area bounds);
 
        /**
-        * Called when a way is encountered.
-        * @param id the way's ID.
-        */
-       void startWay(int id);
-
-       /**
         * Called when a relation is encountered.
         * @param id the relation's ID.
         */
@@ -52,15 +46,6 @@ public interface MapProcessor {
        void processNode(Node n);
 
        /**
-        * Called when a tag is encountered on a way. This method will be
-        * called for every tag associated with the way that was specified
-        * in the most recent call to {...@link #startWay(int)}.
-        * @param key the tag's key.
-        * @param value the tag's value.
-        */
-       void wayTag(String key, String value);
-
-       /**
         * Called when a tag is encountered on a relation. This method will
         * be called for every tag associated with the relation that was
         * specified in the most recent call to {...@link #startRelation(int)}.
@@ -70,14 +55,6 @@ public interface MapProcessor {
        void relationTag(String key, String value);
 
        /**
-        * Called when a reference to a node is encountered within a way. This
-        * method will be called for every node associated with the way that was
-        * specified in the most recent call to {...@link #startWay(int)} .
-        * @param nodeId the ID of the node.
-        */
-       void wayNode(int nodeId);
-
-       /**
         * Called when a reference to a node is encountered within a relation.
         * This method will be called for every node that is associated with the
         * relation that was specified in the most recent call to {...@link 
#startRelation(int)} .
@@ -93,13 +70,8 @@ public interface MapProcessor {
         */
        void relationWay(int wayId, String role);
 
-       /**
-        * Called when processing is complete for a way. This method will be 
called once
-        * there is no further data available for the way specified in the most 
recent
-        * call to {...@link #startWay(int)}.
-        */
-       void endWay();
-
+       void processWay(Way w);
+       
        /**
         * Called when processing is complete for a relation. This method will 
be called once
         * there is no further data available for the relation specified in the 
most recent
diff --git a/src/uk/me/parabola/splitter/NodeCollector.java 
b/src/uk/me/parabola/splitter/NodeCollector.java
index 6556ee6..2607d18 100644
--- a/src/uk/me/parabola/splitter/NodeCollector.java
+++ b/src/uk/me/parabola/splitter/NodeCollector.java
@@ -49,28 +49,19 @@ class NodeCollector implements MapCollector {
        }
 
        @Override
-       public void startWay(int id) {}
-
-       @Override
        public void startRelation(int id) {}
 
        @Override
-       public void wayTag(String key, String value) {}
-
-       @Override
        public void relationTag(String key, String value) {}
 
        @Override
-       public void wayNode(int nodeId) {}
-
-       @Override
        public void relationNode(int nodeId, String role) {}
 
        @Override
        public void relationWay(int wayId, String role) {}
 
        @Override
-       public void endWay() {}
+       public void processWay(Way w) {}
 
        @Override
        public void endRelation() {}
diff --git a/src/uk/me/parabola/splitter/OSMParser.java 
b/src/uk/me/parabola/splitter/OSMParser.java
index 80f0c29..081bc83 100644
--- a/src/uk/me/parabola/splitter/OSMParser.java
+++ b/src/uk/me/parabola/splitter/OSMParser.java
@@ -30,6 +30,7 @@ class OSMParser extends AbstractXppParser implements 
MapReader {
        }
 
        private Node currentNode = new Node();  
+       private Way currentWay = new Way();     
 
        private final MapProcessor processor;
 
@@ -147,7 +148,8 @@ class OSMParser extends AbstractXppParser implements 
MapReader {
        }
 
        private void startWay() {
-               processor.startWay(getIntAttr("id"));
+               currentWay = new Way();
+               currentWay.set(getIntAttr("id"));
                state = State.Way;
        }
 
@@ -164,9 +166,9 @@ class OSMParser extends AbstractXppParser implements 
MapReader {
 
        private void processWay(CharSequence name) {
                if (name.equals("nd")) {
-                       processor.wayNode(getIntAttr("ref"));
+                       currentWay.addRef(getIntAttr("ref"));
                } else if (name.equals("tag")) {
-                       processor.wayTag(getAttr("k"), getAttr("v"));
+                       currentWay.addTag(getAttr("k"), getAttr("v"));
                }
        }
 
@@ -248,7 +250,7 @@ class OSMParser extends AbstractXppParser implements 
MapReader {
                } else if (state == State.Way) {
                        if (name.equals("way")) {
                                if (!startNodeOnly)
-                                       processor.endWay();
+                                       processor.processWay(currentWay);
                                state = State.None;
                                wayCount++;
                                if (wayCount % WAY_STATUS_UPDATE_THRESHOLD == 
0) {
diff --git a/src/uk/me/parabola/splitter/SplitProcessor.java 
b/src/uk/me/parabola/splitter/SplitProcessor.java
index f02c1af..693ebc5 100644
--- a/src/uk/me/parabola/splitter/SplitProcessor.java
+++ b/src/uk/me/parabola/splitter/SplitProcessor.java
@@ -34,8 +34,6 @@ class SplitProcessor implements MapProcessor {
        private final ArrayList<Thread> workerThreads;
 
        private int currentNodeAreaSet;
-
-       private Way currentWay = new Way();
        private BitSet currentWayAreaSet;
 
        private Relation currentRelation = new Relation();
@@ -76,45 +74,16 @@ class SplitProcessor implements MapProcessor {
        }
 
        @Override
-       public void startWay(int id) {
-               currentWay.set(id);
-       }
-
-       @Override
        public void startRelation(int id) {
                currentRelation.set(id);
        }
 
        @Override
-       public void wayTag(String key, String value) {
-               currentWay.addTag(key, value);
-       }
-
-       @Override
        public void relationTag(String key, String value) {
                currentRelation.addTag(key, value);
        }
 
        @Override
-       public void wayNode(int id) {
-               // Get the list of areas that the node is in.  A node may be in
-               // more than one area because of overlap.
-               int set = coords.get(id);
-
-               // add the list of areas to the currentWayAreaSet
-               if (set != 0) {
-                       int mask = 0xff;
-                       for (int slot = 0; slot < 4; slot++, mask <<= 8) {
-                               int val = (set & mask) >>> (slot * 8);
-                               if (val == 0)
-                                       break;
-                               currentWayAreaSet.set(val - 1);
-                       }
-               }
-               currentWay.addRef(id);
-       }
-
-       @Override
        public void relationNode(int id, String role) {
                {
                        currentRelation.addMember("node", id, role);
@@ -171,13 +140,30 @@ class SplitProcessor implements MapProcessor {
        }
 
        @Override
-       public void endWay() {
+       public void processWay(Way w) {
+
+               for (int id: w.getRefs().asArray()) {
+                       // Get the list of areas that the node is in.  A node 
may be in
+                       // more than one area because of overlap.
+                       int set = coords.get(id);
+
+                       // add the list of areas to the currentWayAreaSet
+                       if (set != 0) {
+                               int mask = 0xff;
+                               for (int slot = 0; slot < 4; slot++, mask <<= 
8) {
+                                       int val = (set & mask) >>> (slot * 8);
+                               if (val == 0)
+                                       break;
+                               currentWayAreaSet.set(val - 1);
+                               }
+                       }
+               }
+               
                try {
-                       writeWay();
-                       currentWay = new Way();
+                       writeWay(w);
                        currentWayAreaSet.clear();
                } catch (IOException e) {
-                       throw new RuntimeException("failed to write way " + 
currentWay.getId(), e);
+                       throw new RuntimeException("failed to write way " + 
w.getId(), e);
                }
        }
 
@@ -237,7 +223,7 @@ class SplitProcessor implements MapProcessor {
 
        private boolean seenWay;
 
-       private void writeWay() throws IOException {
+       private void writeWay(Way currentWay) throws IOException {
                if (!seenWay) {
                        seenWay = true;
                        System.out.println("Writing ways " + new Date());
-- 
1.7.2.3

_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Reply via email to