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

Last change on this file since 7005 was 7005, checked in by Don-vip, 10 years ago

see #8465 - use diamond operator where applicable

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
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<>();
24
25 /**
26 * Nodes have only itself as nodes.
27 */
28 @Override
29 public void visit(Node n) {
30 nodes.add(n);
31 }
32
33 /**
34 * Ways have their way nodes.
35 */
36 @Override
37 public void visit(Way w) {
38 if (w.isIncomplete()) return;
39 for (Node n : w.getNodes())
40 visit(n);
41 }
42
43 /**
44 * Relations may have any number of nodes.
45 * FIXME: do we want to collect nodes from segs/ways that are relation members?
46 * if so, use AutomatchVisitor!
47 */
48 @Override
49 public void visit(Relation e) {
50 for (RelationMember m : e.getMembers())
51 if (m.isNode()) visit(m.getNode());
52 }
53
54 /**
55 * Replies all nodes contained by the given primitives
56 * @param osms The OSM primitives to inspect
57 * @return All nodes the given primitives have.
58 */
59 public static Collection<Node> getAllNodes(Collection<? extends OsmPrimitive> osms) {
60 AllNodesVisitor v = new AllNodesVisitor();
61 for (OsmPrimitive osm : osms)
62 osm.accept(v);
63 return v.nodes;
64 }
65}
Note: See TracBrowser for help on using the repository browser.