source: josm/trunk/src/org/openstreetmap/josm/data/osm/visitor/AllNodesVisitor.java@ 1523

Last change on this file since 1523 was 1523, checked in by framm, 15 years ago
  • Major redesign of how JOSM talks to the OSM server. Connections now all go through a new OsmApi class that finds out which version the server uses. JOSM should now be able to handle 0.5 and 0.6 without configuration change. Config options osm-server.version and osm-server.additional-versions now obsolete. Handling of error and cancel situations might still need some improvement.
  • Property svn:eol-style set to native
File size: 1.5 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.data.osm.visitor;
3
4import java.util.Collection;
5import java.util.HashSet;
6
7import org.openstreetmap.josm.data.osm.Relation;
8import org.openstreetmap.josm.data.osm.RelationMember;
9import org.openstreetmap.josm.data.osm.Node;
10import org.openstreetmap.josm.data.osm.OsmPrimitive;
11import org.openstreetmap.josm.data.osm.Way;
12
13/**
14 * Collect all nodes a specific osm primitive has.
15 *
16 * @author imi
17 */
18public class AllNodesVisitor extends AbstractVisitor {
19
20 /**
21 * The resulting nodes collected so far.
22 */
23 public Collection<Node> nodes = new HashSet<Node>();
24
25 /**
26 * Nodes have only itself as nodes.
27 */
28 public void visit(Node n) {
29 nodes.add(n);
30 }
31
32 /**
33 * Ways have their way nodes.
34 */
35 public void visit(Way w) {
36 w.visitNodes(this);
37 }
38
39 /**
40 * Relations may have any number of nodes.
41 * FIXME: do we want to collect nodes from segs/ways that are relation members?
42 * if so, use AutomatchVisitor!
43 */
44 public void visit(Relation e) {
45 for (RelationMember m : e.members)
46 if (m.member instanceof Node) visit((Node)m.member);
47 }
48 /**
49 * @return All nodes the given primitive has.
50 */
51 public static Collection<Node> getAllNodes(Collection<? extends OsmPrimitive> osms) {
52 AllNodesVisitor v = new AllNodesVisitor();
53 for (OsmPrimitive osm : osms)
54 osm.visit(v);
55 return v.nodes;
56 }
57}
Note: See TracBrowser for help on using the repository browser.