source: josm/trunk/src/org/openstreetmap/josm/data/validation/util/AgregatePrimitivesVisitor.java@ 3775

Last change on this file since 3775 was 3671, checked in by bastiK, 13 years ago

adapt coding style (to some degree); there shouldn't be any semantic changes in this commit

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1// License: GPL. See LICENSE file for details.
2package org.openstreetmap.josm.data.validation.util;
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;
12import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor;
13
14/**
15 * A visitor that aggregates all primitives it visits.
16 * <p>
17 * The primitives are sorted according to their type: first nodes, then ways.
18 *
19 * @author frsantos
20 */
21public class AgregatePrimitivesVisitor extends AbstractVisitor {
22 /** Aggregated data */
23 final Collection<OsmPrimitive> aggregatedData = new HashSet<OsmPrimitive>();
24
25 /**
26 * Visits a collection of primitives
27 * @param data The collection of primitives
28 * @return The aggregated primitives
29 */
30 public Collection<OsmPrimitive> visit(Collection<OsmPrimitive> data) {
31 for (OsmPrimitive osm : data) {
32 osm.visit(this);
33 }
34
35 return aggregatedData;
36 }
37
38 @Override
39 public void visit(Node n) {
40 if (!aggregatedData.contains(n)) {
41 aggregatedData.add(n);
42 }
43 }
44
45 @Override
46 public void visit(Way w) {
47 if (!aggregatedData.contains(w)) {
48 aggregatedData.add(w);
49 for (Node n : w.getNodes()) {
50 visit(n);
51 }
52 }
53 }
54
55 @Override
56 public void visit(Relation r) {
57 if (!aggregatedData.contains(r)) {
58 aggregatedData.add(r);
59 for (RelationMember m : r.getMembers()) {
60 m.getMember().visit(this);
61 }
62 }
63 }
64}
Note: See TracBrowser for help on using the repository browser.