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

Last change on this file since 159 was 159, checked in by imi, 18 years ago
  • moved translations into plugins
  • added main menu control to main
  • added ImageProvider access to plugins
File size: 1.2 KB
Line 
1package org.openstreetmap.josm.data.osm.visitor;
2
3import java.util.Collection;
4import java.util.HashSet;
5
6import org.openstreetmap.josm.data.osm.Segment;
7import org.openstreetmap.josm.data.osm.Node;
8import org.openstreetmap.josm.data.osm.OsmPrimitive;
9import org.openstreetmap.josm.data.osm.Way;
10
11/**
12 * Collect all nodes a specific osm primitive has.
13 *
14 * @author imi
15 */
16public class AllNodesVisitor implements Visitor {
17
18 /**
19 * The resulting nodes collected so far.
20 */
21 public Collection<Node> nodes = new HashSet<Node>();
22
23 /**
24 * Nodes have only itself as nodes.
25 */
26 public void visit(Node n) {
27 nodes.add(n);
28 }
29
30 /**
31 * Line segments have exactly two nodes: from and to.
32 */
33 public void visit(Segment ls) {
34 if (!ls.incomplete) {
35 visit(ls.from);
36 visit(ls.to);
37 }
38 }
39
40 /**
41 * Ways have all nodes from their segments.
42 */
43 public void visit(Way w) {
44 for (Segment ls : w.segments)
45 visit(ls);
46 }
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.