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

Last change on this file since 3836 was 2578, checked in by jttt, 14 years ago

Encalupse OsmPrimitive.incomplete

  • Property svn:eol-style set to native
File size: 1.6 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.Node;
8import org.openstreetmap.josm.data.osm.OsmPrimitive;
9import org.openstreetmap.josm.data.osm.Relation;
10import org.openstreetmap.josm.data.osm.RelationMember;
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 if (w.isIncomplete()) return;
37 for (Node n : w.getNodes())
38 visit(n);
39 }
40
41 /**
42 * Relations may have any number of nodes.
43 * FIXME: do we want to collect nodes from segs/ways that are relation members?
44 * if so, use AutomatchVisitor!
45 */
46 public void visit(Relation e) {
47 for (RelationMember m : e.getMembers())
48 if (m.isNode()) visit(m.getNode());
49 }
50 /**
51 * @return All nodes the given primitive has.
52 */
53 public static Collection<Node> getAllNodes(Collection<? extends OsmPrimitive> osms) {
54 AllNodesVisitor v = new AllNodesVisitor();
55 for (OsmPrimitive osm : osms)
56 osm.visit(v);
57 return v.nodes;
58 }
59}
Note: See TracBrowser for help on using the repository browser.