Changeset 6475 in josm
- Timestamp:
- 2013-12-16T01:02:37+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/validation/tests
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/Coastlines.java
r6336 r6475 8 8 import java.util.Collection; 9 9 import java.util.Collections; 10 import java.util.Iterator; 10 11 import java.util.LinkedList; 11 12 import java.util.List; … … 218 219 public Command fixError(TestError testError) { 219 220 if (isFixable(testError)) { 220 Way way = (Way) testError.getPrimitives().iterator().next(); 221 Way newWay = new Way(way); 222 223 List<Node> nodesCopy = newWay.getNodes(); 224 Collections.reverse(nodesCopy); 225 newWay.setNodes(nodesCopy); 226 227 return new ChangeCommand(way, newWay); 221 // primitives list can be empty if all primitives have been purged 222 Iterator<? extends OsmPrimitive> it = testError.getPrimitives().iterator(); 223 if (it.hasNext()) { 224 Way way = (Way) it.next(); 225 Way newWay = new Way(way); 226 227 List<Node> nodesCopy = newWay.getNodes(); 228 Collections.reverse(nodesCopy); 229 newWay.setNodes(nodesCopy); 230 231 return new ChangeCommand(way, newWay); 232 } 228 233 } 229 234 return null; -
trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicatedWayNodes.java
r6241 r6475 6 6 import java.util.Arrays; 7 7 import java.util.Collections; 8 import java.util.Iterator; 8 9 9 10 import org.openstreetmap.josm.command.ChangeCommand; 10 11 import org.openstreetmap.josm.command.Command; 11 12 import org.openstreetmap.josm.data.osm.Node; 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 12 14 import org.openstreetmap.josm.data.osm.Way; 13 15 import org.openstreetmap.josm.data.validation.Severity; … … 49 51 } 50 52 51 @Override public Command fixError(TestError testError) { 52 Way w = (Way) testError.getPrimitives().iterator().next(); 53 Way wnew = new Way(w); 54 wnew.setNodes(null); 55 Node lastN = null; 56 for (Node n : w.getNodes()) { 57 if (lastN == null) { 58 wnew.addNode(n); 59 } else if (n == lastN) { 60 // Skip this node 61 } else { 62 wnew.addNode(n); 53 @Override 54 public Command fixError(TestError testError) { 55 // primitives list can be empty if all primitives have been purged 56 Iterator<? extends OsmPrimitive> it = testError.getPrimitives().iterator(); 57 if (it.hasNext()) { 58 Way w = (Way) it.next(); 59 Way wnew = new Way(w); 60 wnew.setNodes(null); 61 Node lastN = null; 62 for (Node n : w.getNodes()) { 63 if (lastN == null) { 64 wnew.addNode(n); 65 } else if (n == lastN) { 66 // Skip this node 67 } else { 68 wnew.addNode(n); 69 } 70 lastN = n; 63 71 } 64 lastN = n; 72 if (wnew.getNodesCount() < 2) 73 // Empty way, delete 74 return deletePrimitivesIfNeeded(Collections.singleton(w)); 75 else 76 return new ChangeCommand(w, wnew); 65 77 } 66 if (wnew.getNodesCount() < 2) 67 // Empty way, delete 68 return deletePrimitivesIfNeeded(Collections.singleton(w)); 69 else 70 return new ChangeCommand(w, wnew); 78 return null; 71 79 } 72 80 73 @Override public boolean isFixable(TestError testError) { 81 @Override 82 public boolean isFixable(TestError testError) { 74 83 return testError.getTester() instanceof DuplicatedWayNodes; 75 84 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/Highways.java
r6434 r6475 8 8 import java.util.HashMap; 9 9 import java.util.HashSet; 10 import java.util.Iterator; 10 11 import java.util.List; 11 12 import java.util.Map; … … 30 31 protected static final int WRONG_ROUNDABOUT_HIGHWAY = 2701; 31 32 protected static final int MISSING_PEDESTRIAN_CROSSING = 2702; 32 33 33 34 /** 34 35 * Classified highways in order of importance 35 36 */ 36 37 protected static final List<String> CLASSIFIED_HIGHWAYS = Arrays.asList( 37 "motorway", "motorway_link", 38 "trunk", "trunk_link", 39 "primary", "primary_link", 38 "motorway", "motorway_link", 39 "trunk", "trunk_link", 40 "primary", "primary_link", 40 41 "secondary", "secondary_link", 41 42 "tertiary", "tertiary_link", … … 50 51 int cyclistWays = 0; 51 52 int carsWays = 0; 52 53 53 54 /** 54 55 * Constructs a new {@code Highways} test. … … 61 62 62 63 public final String correctValue; 63 64 64 65 public WrongRoundaboutHighway(Way w, String key) { 65 super(Highways.this, Severity.WARNING, 66 tr("Incorrect roundabout (highway: {0} instead of {1})", w.get("highway"), key), 66 super(Highways.this, Severity.WARNING, 67 tr("Incorrect roundabout (highway: {0} instead of {1})", w.get("highway"), key), 67 68 WRONG_ROUNDABOUT_HIGHWAY, w); 68 69 this.correctValue = key; 69 70 } 70 71 } 71 72 72 73 @Override 73 74 public void visit(Node n) { … … 116 117 } 117 118 } 118 119 119 120 private void testMissingPedestrianCrossing(Node n) { 120 121 leftByPedestrians = false; … … 124 125 cyclistWays = 0; 125 126 carsWays = 0; 126 127 127 128 for (Way w : OsmPrimitive.getFilteredList(n.getReferrers(), Way.class)) { 128 129 String highway = w.get("highway"); … … 172 173 } 173 174 } 174 175 175 176 @Override 176 177 public boolean isFixable(TestError testError) { … … 181 182 public Command fixError(TestError testError) { 182 183 if (testError instanceof WrongRoundaboutHighway) { 183 return new ChangePropertyCommand(testError.getPrimitives().iterator().next(), 184 "highway", ((WrongRoundaboutHighway) testError).correctValue); 184 // primitives list can be empty if all primitives have been purged 185 Iterator<? extends OsmPrimitive> it = testError.getPrimitives().iterator(); 186 if (it.hasNext()) { 187 return new ChangePropertyCommand(it.next(), 188 "highway", ((WrongRoundaboutHighway) testError).correctValue); 189 } 185 190 } 186 191 return null; -
trunk/src/org/openstreetmap/josm/data/validation/tests/PowerLines.java
r6295 r6475 8 8 import java.util.Collection; 9 9 import java.util.HashMap; 10 import java.util.Iterator; 10 11 import java.util.List; 11 12 import java.util.Map; … … 31 32 */ 32 33 public class PowerLines extends Test { 33 34 34 35 protected static final int POWER_LINES = 2501; 35 36 36 37 /** Values for {@code power} key interpreted as power lines */ 37 38 public static final Collection<String> POWER_LINE_TAGS = Arrays.asList("line", "minor_line"); … … 42 43 /** Values for {@code power} key interpreted as allowed power items */ 43 44 public static final Collection<String> POWER_ALLOWED_TAGS = Arrays.asList("switch", "transformer", "busbar", "generator"); 44 45 45 46 private final Map<Way, String> towerPoleTagMap = new HashMap<Way, String>(); 46 47 47 48 private final List<PowerLineError> potentialErrors = new ArrayList<PowerLineError>(); 48 49 … … 55 56 super(tr("Power lines"), tr("Checks for nodes in power lines that do not have a power=tower/pole tag.")); 56 57 } 57 58 58 59 @Override 59 60 public void visit(Way w) { … … 86 87 } 87 88 } 88 89 89 90 @Override 90 91 public void visit(Relation r) { … … 92 93 powerStations.add(r); 93 94 } 94 } 95 } 95 96 96 97 @Override 97 98 public void endTest() { 98 99 for (PowerLineError e : potentialErrors) { 99 if (!isInPowerStation(e.getNode())) { 100 Node n = e.getNode(); 101 if (n != null && !isInPowerStation(n)) { 100 102 errors.add(e); 101 103 } … … 103 105 super.endTest(); 104 106 } 105 107 106 108 protected final boolean isInPowerStation(Node n) { 107 109 for (OsmPrimitive station : powerStations) { … … 129 131 public Command fixError(TestError testError) { 130 132 if (testError instanceof PowerLineError && isFixable(testError)) { 131 return new ChangePropertyCommand( 132 testError.getPrimitives().iterator().next(), 133 "power", towerPoleTagMap.get(((PowerLineError)testError).line)); 133 // primitives list can be empty if all primitives have been purged 134 Iterator<? extends OsmPrimitive> it = testError.getPrimitives().iterator(); 135 if (it.hasNext()) { 136 return new ChangePropertyCommand(it.next(), 137 "power", towerPoleTagMap.get(((PowerLineError)testError).line)); 138 } 134 139 } 135 140 return null; … … 140 145 return testError instanceof PowerLineError && towerPoleTagMap.containsKey(((PowerLineError)testError).line); 141 146 } 142 147 143 148 /** 144 149 * Determines if the specified way denotes a power line. … … 167 172 return isPowerIn(n, POWER_TOWER_TAGS); 168 173 } 169 174 170 175 /** 171 176 * Determines if the specified node denotes a power infrastructure allowed on a power line. … … 176 181 return isPowerIn(n, POWER_ALLOWED_TAGS); 177 182 } 178 183 179 184 /** 180 185 * Helper function to check if power tags is a certain value. … … 187 192 return v != null && values != null && values.contains(v); 188 193 } 189 194 190 195 protected class PowerLineError extends TestError { 191 196 private final Way line; 192 197 public PowerLineError(Node n, Way line) { 193 super(PowerLines.this, Severity.WARNING, 198 super(PowerLines.this, Severity.WARNING, 194 199 tr("Missing power tower/pole within power line"), POWER_LINES, n); 195 200 this.line = line; 196 201 } 197 202 public final Node getNode() { 198 return (Node) getPrimitives().iterator().next(); 203 // primitives list can be empty if all primitives have been purged 204 Iterator<? extends OsmPrimitive> it = getPrimitives().iterator(); 205 return it.hasNext() ? (Node) it.next() : null; 199 206 } 200 207 }
Note:
See TracChangeset
for help on using the changeset viewer.