source: josm/trunk/src/org/openstreetmap/josm/data/validation/util/AggregatePrimitivesVisitor.java

Last change on this file was 18960, checked in by GerdP, 3 months ago

fix #23397: Improve the results of partial validations

  • pass also parent ways and relations of uploaded/selected objects to the testers, child objects are already added, this allows to find e.g. overlapping polygons problems with tags in members of relations
  • let CrossingWays find a problem if at least one of the crossing ways is in the partial selection.
  • let DuplicatWays find a problem if at least one of the duplicated ways is in the partial selection
  • add code to filter the detected issues so that those issues which are clearly not related to the original list of objects are removed. A few issues from mapcss tests may remain.
  • add new preference validator.partial.add.parents to disable the addition of parent objects, default is enabled
  • add new preference validator.partial.removeIrrelevant to disable the filtering of irrelevant errors, default is enabled
  • duplicated code to call AggregatePrimitivesVisitor was moved to ValidationTask
  • 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.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.OsmPrimitiveVisitor;
13
14/**
15 * A visitor that aggregates all primitives it visits.
16 * <p>
17 *
18 * @author frsantos
19 */
20public class AggregatePrimitivesVisitor implements OsmPrimitiveVisitor {
21 /** Aggregated data */
22 private final Collection<OsmPrimitive> aggregatedData = new HashSet<>();
23
24 /**
25 * Visits a collection of primitives
26 * @param data The collection of primitives in no specific order.
27 * @return The aggregated primitives
28 */
29 public Collection<OsmPrimitive> visit(Collection<OsmPrimitive> data) {
30 for (OsmPrimitive osm : data) {
31 osm.accept(this);
32 }
33
34 return aggregatedData;
35 }
36
37 @Override
38 public void visit(Node n) {
39 if (!aggregatedData.contains(n)) {
40 aggregatedData.add(n);
41 }
42 }
43
44 @Override
45 public void visit(Way w) {
46 if (!aggregatedData.contains(w)) {
47 aggregatedData.add(w);
48 for (Node n : w.getNodes()) {
49 visit(n);
50 }
51 }
52 }
53
54 @Override
55 public void visit(Relation r) {
56 if (!aggregatedData.contains(r)) {
57 aggregatedData.add(r);
58 for (RelationMember m : r.getMembers()) {
59 m.getMember().accept(this);
60 }
61 }
62 }
63}
Note: See TracBrowser for help on using the repository browser.