Changeset 6574 in josm for trunk/src/org
- Timestamp:
- 2013-12-31T11:34:53+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/OverlappingWays.java
r6494 r6574 6 6 import java.util.ArrayList; 7 7 import java.util.Collection; 8 import java.util.Collections; 9 import java.util.Comparator; 8 10 import java.util.HashMap; 9 11 import java.util.List; 10 12 import java.util.Map; 11 13 import java.util.Set; 12 14 import java.util.TreeSet; 15 16 import org.openstreetmap.josm.command.ChangeNodesCommand; 17 import org.openstreetmap.josm.command.Command; 13 18 import org.openstreetmap.josm.data.osm.Node; 14 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 17 22 import org.openstreetmap.josm.data.osm.Way; 18 23 import org.openstreetmap.josm.data.osm.WaySegment; 24 import org.openstreetmap.josm.data.validation.FixableTestError; 19 25 import org.openstreetmap.josm.data.validation.Severity; 20 26 import org.openstreetmap.josm.data.validation.Test; … … 41 47 protected static final int OVERLAPPING_WAY_AREA = 113; 42 48 protected static final int OVERLAPPING_AREA = 120; 49 protected static final int DUPLICATE_WAY_SEGMENT = 121; 43 50 44 51 /** Constructor */ … … 146 153 } 147 154 155 public static Command fixDuplicateWaySegment(Way w) { 156 // test for ticket #4959 157 Set<WaySegment> segments = new TreeSet<WaySegment>(new Comparator<WaySegment>() { 158 @Override 159 public int compare(WaySegment o1, WaySegment o2) { 160 return o1.way.getNode(o1.lowerIndex).compareTo(o2.way.getNode(o2.lowerIndex)); 161 } 162 }); 163 final Set<Integer> wayNodesToFix = new TreeSet<Integer>(Collections.reverseOrder()); 164 for (int i = 0; i < w.getNodesCount() - 1; i++) { 165 final boolean wasInSet = !segments.add(new WaySegment(w, i)); 166 if (wasInSet) { 167 wayNodesToFix.add(i); 168 } 169 } 170 if (!wayNodesToFix.isEmpty()) { 171 final List<Node> newNodes = new ArrayList<Node>(w.getNodes()); 172 for (final int i : wayNodesToFix) { 173 newNodes.remove(i); 174 } 175 return new ChangeNodesCommand(w, newNodes); 176 } else { 177 return null; 178 } 179 } 180 148 181 @Override 149 182 public void visit(Way w) { 183 184 final Command duplicateWaySegmentFix = fixDuplicateWaySegment(w); 185 if (duplicateWaySegmentFix != null) { 186 errors.add(new FixableTestError(this, Severity.ERROR, tr("Way contains segment twice"), 187 DUPLICATE_WAY_SEGMENT, w, duplicateWaySegmentFix)); 188 return; 189 } 190 150 191 Node lastN = null; 151 192 int i = -2;
Note:
See TracChangeset
for help on using the changeset viewer.