- Timestamp:
- 2010-11-25T09:45:38+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 38 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r3669 r3671 136 136 // FIXME: this should become an asynchronous task 137 137 // 138 for(UploadHook hook : uploadHooks) 139 if(!hook.checkUpload(apiData)) 138 for (UploadHook hook : uploadHooks) { 139 if (!hook.checkUpload(apiData)) 140 140 return false; 141 } 141 142 142 143 return true; -
trunk/src/org/openstreetmap/josm/actions/ValidateAction.java
r3669 r3671 34 34 */ 35 35 public class ValidateAction extends JosmAction { 36 36 37 /** Serializable ID */ 37 38 private static final long serialVersionUID = -2304521273582574603L; … … 84 85 } 85 86 } else { 86 if (lastSelection == null) 87 if (lastSelection == null) { 87 88 selection = Main.main.getCurrentDataSet().allNonDeletedPrimitives(); 88 else89 } else { 89 90 selection = lastSelection; 91 } 90 92 } 91 93 … … 104 106 * 105 107 */ 106 107 108 class ValidationTask extends PleaseWaitRunnable { 108 109 private Collection<Test> tests; … … 137 138 // 138 139 Runnable r = new Runnable() { 140 @Override 139 141 public void run() { 140 142 Main.map.validatorDialog.tree.setErrors(errors); … … 153 155 protected void realRun() throws SAXException, IOException, 154 156 OsmTransferException { 155 if (tests == null || tests.isEmpty()) return; 157 if (tests == null || tests.isEmpty()) 158 return; 156 159 errors = new ArrayList<TestError>(200); 157 160 getProgressMonitor().setTicksCount(tests.size() * validatedPrimitmives.size()); 158 161 int testCounter = 0; 159 162 for (Test test : tests) { 160 if (canceled) return; 163 if (canceled) 164 return; 161 165 testCounter++; 162 166 getProgressMonitor().setCustomText(tr("Test {0}/{1}: Starting {2}", testCounter, tests.size(),test.getName())); -
trunk/src/org/openstreetmap/josm/actions/upload/ValidateUploadHook.java
r3669 r3671 41 41 * Validate the modified data before uploading 42 42 */ 43 public boolean checkUpload(APIDataSet apiDataSet) 44 { 43 public boolean checkUpload(APIDataSet apiDataSet) { 44 45 45 Collection<Test> tests = OsmValidator.getEnabledTests(true); 46 46 if (tests.isEmpty()) … … 52 52 53 53 List<TestError> errors = new ArrayList<TestError>(30); 54 for(Test test : tests) 55 { 54 for (Test test : tests) { 56 55 test.setBeforeUpload(true); 57 56 test.setPartialSelection(true); … … 59 58 test.visit(selection); 60 59 test.endTest(); 61 if(Main.pref.getBoolean(ValidatorPreference.PREF_OTHER_UPLOAD, false)) 60 if (Main.pref.getBoolean(ValidatorPreference.PREF_OTHER_UPLOAD, false)) { 62 61 errors.addAll( test.getErrors() ); 63 else 64 { 65 for(TestError e : test.getErrors()) 66 { 67 if(e.getSeverity() != Severity.OTHER) 62 } 63 else { 64 for (TestError e : test.getErrors()) { 65 if (e.getSeverity() != Severity.OTHER) { 68 66 errors.add(e); 67 } 69 68 } 70 69 } 71 70 } 72 71 tests = null; 73 if(errors == null || errors.isEmpty()) 72 if (errors == null || errors.isEmpty()) 74 73 return true; 75 74 76 if(Main.pref.getBoolean(ValidatorPreference.PREF_USE_IGNORE, true)) 77 { 75 if (Main.pref.getBoolean(ValidatorPreference.PREF_USE_IGNORE, true)) { 78 76 int nume = 0; 79 for(TestError error : errors) 80 { 77 for (TestError error : errors) { 81 78 List<String> s = new ArrayList<String>(); 82 79 s.add(error.getIgnoreState()); 83 80 s.add(error.getIgnoreGroup()); 84 81 s.add(error.getIgnoreSubGroup()); 85 for(String state : s) 86 { 87 if(state != null && OsmValidator.hasIgnoredError(state)) 88 { 82 for (String state : s) { 83 if (state != null && OsmValidator.hasIgnoredError(state)) { 89 84 error.setIgnored(true); 90 85 } 91 86 } 92 if(!error.getIgnored()) 87 if (!error.getIgnored()) { 93 88 ++nume; 89 } 94 90 } 95 if(nume == 0) 91 if (nume == 0) 96 92 return true; 97 93 } … … 106 102 * if the user requested cancel. 107 103 */ 108 private boolean displayErrorScreen(List<TestError> errors) 109 { 104 private boolean displayErrorScreen(List<TestError> errors) { 110 105 JPanel p = new JPanel(new GridBagLayout()); 111 106 ValidatorTreePanel errorPanel = new ValidatorTreePanel(errors); … … 113 108 p.add(new JScrollPane(errorPanel), GBC.eol()); 114 109 115 int res = JOptionPane.showConfirmDialog(Main.parent, p, 116 tr("Data with errors. Upload anyway?"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); 117 if(res == JOptionPane.NO_OPTION) 118 { 110 int res = JOptionPane.showConfirmDialog(Main.parent, p, 111 tr("Data with errors. Upload anyway?"), 112 JOptionPane.YES_NO_OPTION, 113 JOptionPane.QUESTION_MESSAGE); 114 if (res == JOptionPane.NO_OPTION) { 119 115 OsmValidator.initializeErrorLayer(); 120 116 Main.map.validatorDialog.unfurlDialog(); -
trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java
r3669 r3671 47 47 import org.openstreetmap.josm.data.validation.tests.WronglyOrderedWays; 48 48 import org.openstreetmap.josm.data.validation.util.ValUtil; 49 import org.openstreetmap.josm.gui.MapFrame;50 49 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 51 50 import org.openstreetmap.josm.gui.dialogs.ValidatorDialog; … … 115 114 private void checkPluginDir() { 116 115 try { 117 File pathDir = new File(ValUtil.getPluginDir()); 118 if (!pathDir.exists()) 119 pathDir.mkdirs(); 116 File pathDir = new File(ValUtil.getPluginDir()); 117 if (!pathDir.exists()) { 118 pathDir.mkdirs(); 119 } 120 120 } catch (Exception e){ 121 121 e.printStackTrace(); … … 150 150 try { 151 151 final PrintWriter out = new PrintWriter(new FileWriter(ValUtil.getPluginDir() + "ignorederrors"), false); 152 for (String e : ignoredErrors) 152 for (String e : ignoredErrors) { 153 153 out.println(e); 154 } 154 155 out.close(); 155 156 } catch (final IOException e) { … … 221 222 Collection<Test> enabledTests = getTests(); 222 223 for (Test t : new ArrayList<Test>(enabledTests)) { 223 if (beforeUpload ? t.testBeforeUpload : t.enabled) 224 if (beforeUpload ? t.testBeforeUpload : t.enabled) { 224 225 continue; 226 } 225 227 enabledTests.remove(t); 226 228 } … … 243 245 */ 244 246 public void initializeGridDetail() { 245 if (Main.proj.toString().equals(new Epsg4326().toString())) 247 if (Main.proj.toString().equals(new Epsg4326().toString())) { 246 248 OsmValidator.griddetail = 10000; 247 else if (Main.proj.toString().equals(new Mercator().toString())) 249 } else if (Main.proj.toString().equals(new Mercator().toString())) { 248 250 OsmValidator.griddetail = 100000; 249 else if (Main.proj.toString().equals(new Lambert().toString())) 251 } else if (Main.proj.toString().equals(new Lambert().toString())) { 250 252 OsmValidator.griddetail = 0.1; 253 } 251 254 } 252 255 … … 275 278 /* interface LayerChangeListener */ 276 279 /* -------------------------------------------------------------------------- */ 277 public void activeLayerChange(Layer oldLayer, Layer newLayer) {} 278 279 public void layerAdded(Layer newLayer) {} 280 280 @Override 281 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 282 } 283 284 @Override 285 public void layerAdded(Layer newLayer) { 286 } 287 288 @Override 281 289 public void layerRemoved(Layer oldLayer) { 282 290 if (oldLayer instanceof OsmDataLayer && Main.map.mapView.getActiveLayer() == oldLayer) { -
trunk/src/org/openstreetmap/josm/data/validation/Severity.java
r3669 r3671 34 34 * @param color The color of this severity 35 35 */ 36 Severity(String message, String icon, Color color) 37 { 36 Severity(String message, String icon, Color color) { 38 37 this.message = message; 39 38 this.icon = icon; … … 42 41 43 42 @Override 44 public String toString() 45 { 43 public String toString() { 46 44 return message; 47 45 } … … 51 49 * @return the associated icon 52 50 */ 53 public String getIcon() 54 { 51 public String getIcon() { 55 52 return icon; 56 53 } … … 60 57 * @return The associated color 61 58 */ 62 public Color getColor() 63 { 59 public Color getColor() { 64 60 return color; 65 61 } -
trunk/src/org/openstreetmap/josm/data/validation/Test.java
r3669 r3671 67 67 * @param description Description of the test 68 68 */ 69 public Test(String name, String description) 70 { 69 public Test(String name, String description) { 71 70 this.name = name; 72 71 this.description = description; … … 77 76 * @param name Name of the test 78 77 */ 79 public Test(String name) 80 { 78 public Test(String name) { 81 79 this(name, null); 82 80 } … … 86 84 * @throws Exception When cannot initialize the test 87 85 */ 88 public void initialize() throws Exception {} 86 public void initialize() throws Exception { 87 } 89 88 90 89 /** … … 95 94 public void startTest(ProgressMonitor progressMonitor) { 96 95 if (progressMonitor == null) { 97 96 this.progressMonitor = NullProgressMonitor.INSTANCE; 98 97 } else { 99 98 this.progressMonitor = progressMonitor; 100 99 } 101 100 this.progressMonitor.beginTask(tr("Running test {0}", name)); … … 107 106 * @param partialSelection Whether the test is on a partial selection data 108 107 */ 109 public void setPartialSelection(boolean partialSelection) 110 { 108 public void setPartialSelection(boolean partialSelection) { 111 109 this.partialSelection = partialSelection; 112 110 } … … 116 114 * @return The list of errors 117 115 */ 118 public List<TestError> getErrors() 119 { 116 public List<TestError> getErrors() { 120 117 return errors; 121 118 } … … 136 133 * @param selection The primitives to be tested 137 134 */ 138 public void visit(Collection<OsmPrimitive> selection) 139 { 135 public void visit(Collection<OsmPrimitive> selection) { 140 136 progressMonitor.setTicksCount(selection.size()); 141 137 for (OsmPrimitive p : selection) { 142 if (p.isUsable())138 if (p.isUsable()) { 143 139 p.visit(this); 140 } 144 141 progressMonitor.worked(1); 145 142 } 146 143 } 147 144 145 @Override 148 146 public void visit(Node n) {} 149 147 148 @Override 150 149 public void visit(Way w) {} 151 150 151 @Override 152 152 public void visit(Relation r) {} 153 153 … … 156 156 * @param testPanel The panel to add any preferences component 157 157 */ 158 public void addGui(JPanel testPanel) 159 { 158 public void addGui(JPanel testPanel) { 160 159 checkEnabled = new JCheckBox(name, enabled); 161 160 checkEnabled.setToolTipText(description); … … 172 171 * Called when the used submits the preferences 173 172 */ 174 public boolean ok() 175 { 173 public boolean ok() { 176 174 enabled = checkEnabled.isSelected(); 177 175 testBeforeUpload = checkBeforeUpload.isSelected(); … … 180 178 181 179 /** 182 * Fixes the error with the appropiate command 180 * Fixes the error with the appropriate command 183 181 * 184 182 * @param testError 185 183 * @return The command to fix the error 186 184 */ 187 public Command fixError(TestError testError) 188 { 185 public Command fixError(TestError testError) { 189 186 return null; 190 187 } … … 196 193 * @return true if the error can be fixed 197 194 */ 198 public boolean isFixable(TestError testError) 199 { 195 public boolean isFixable(TestError testError) { 200 196 return false; 201 197 } … … 205 201 * @return true if this plugin must check the uploaded data before uploading 206 202 */ 207 public boolean testBeforeUpload() 208 { 203 public boolean testBeforeUpload() { 209 204 return testBeforeUpload; 210 205 } … … 214 209 * @param isUpload if true, the test is before upload 215 210 */ 216 public void setBeforeUpload(boolean isUpload) 217 { 211 public void setBeforeUpload(boolean isUpload) { 218 212 this.isBeforeUpload = isUpload; 219 213 } -
trunk/src/org/openstreetmap/josm/data/validation/TestError.java
r3669 r3671 157 157 return null; 158 158 String type = "u"; 159 if (o instanceof Way) 159 if (o instanceof Way) { 160 160 type = "w"; 161 else if (o instanceof Relation) 161 } else if (o instanceof Relation) { 162 162 type = "r"; 163 else if (o instanceof Node) 163 } else if (o instanceof Node) { 164 164 type = "n"; 165 } 165 166 strings.add(type + "_" + o.getId()); 166 167 } … … 173 174 public String getIgnoreSubGroup() { 174 175 String ignorestring = getIgnoreGroup(); 175 if (description_en != null) 176 if (description_en != null) { 176 177 ignorestring += "_" + description_en; 178 } 177 179 return ignorestring; 178 180 } … … 216 218 217 219 /** 218 * Fixes the error with the appropiate command 220 * Fixes the error with the appropriate command 219 221 * 220 222 * @return The command to fix the error … … 243 245 public void visitHighlighted(ValidatorVisitor v) { 244 246 for (Object o : highlighted) { 245 if (o instanceof OsmPrimitive) 247 if (o instanceof OsmPrimitive) { 246 248 v.visit((OsmPrimitive) o); 247 else if (o instanceof WaySegment) 249 } else if (o instanceof WaySegment) { 248 250 v.visit((WaySegment) o); 249 else if (o instanceof List<?>) { 251 } else if (o instanceof List<?>) { 250 252 v.visit((List<Node>)o); 251 253 } … … 273 275 } 274 276 277 @Override 275 278 public void visit(OsmPrimitive p) { 276 279 if (p.isUsable()) { … … 289 292 if (selected) { 290 293 g.fillOval(p.x - 5, p.y - 5, 10, 10); 291 } else 294 } else { 292 295 g.drawOval(p.x - 5, p.y - 5, 10, 10); 296 } 293 297 } 294 298 … … 301 305 int deg = (int) Math.toDegrees(t); 302 306 if (selected) { 303 int[] x = new int[] { (int) (p1.x + 5 * cosT), (int) (p2.x + 5 * cosT), (int) (p2.x - 5 * cosT),304 (int) (p1.x - 5 * cosT) }; 305 int[] y = new int[] { (int) (p1.y - 5 * sinT), (int) (p2.y - 5 * sinT), (int) (p2.y + 5 * sinT),306 (int) (p1.y + 5 * sinT) }; 307 int[] x = new int[] { (int) (p1.x + 5 * cosT), (int) (p2.x + 5 * cosT), 308 (int) (p2.x - 5 * cosT), (int) (p1.x - 5 * cosT) }; 309 int[] y = new int[] { (int) (p1.y - 5 * sinT), (int) (p2.y - 5 * sinT), 310 (int) (p2.y + 5 * sinT), (int) (p1.y + 5 * sinT) }; 307 311 g.fillPolygon(x, y, 4); 308 312 g.fillArc(p1.x - 5, p1.y - 5, 10, 10, deg, 180); 309 313 g.fillArc(p2.x - 5, p2.y - 5, 10, 10, deg, -180); 310 314 } else { 311 g.drawLine((int) (p1.x + 5 * cosT), (int) (p1.y - 5 * sinT), (int) (p2.x + 5 * cosT),312 (int) (p2.y - 5 * sinT)); 313 g.drawLine((int) (p1.x - 5 * cosT), (int) (p1.y + 5 * sinT), (int) (p2.x - 5 * cosT),314 (int) (p2.y + 5 * sinT)); 315 g.drawLine((int) (p1.x + 5 * cosT), (int) (p1.y - 5 * sinT), 316 (int) (p2.x + 5 * cosT), (int) (p2.y - 5 * sinT)); 317 g.drawLine((int) (p1.x - 5 * cosT), (int) (p1.y + 5 * sinT), 318 (int) (p2.x - 5 * cosT), (int) (p2.y + 5 * sinT)); 315 319 g.drawArc(p1.x - 5, p1.y - 5, 10, 10, deg, 180); 316 320 g.drawArc(p2.x - 5, p2.y - 5, 10, 10, deg, -180); … … 334 338 * @param n The node to draw. 335 339 */ 340 @Override 336 341 public void visit(Node n) { 337 if (isNodeVisible(n)) 342 if (isNodeVisible(n)) { 338 343 drawNode(n, severity.getColor()); 339 } 340 344 } 345 } 346 347 @Override 341 348 public void visit(Way w) { 342 349 visit(w.getNodes()); 343 350 } 344 351 352 @Override 345 353 public void visit(WaySegment ws) { 346 354 if (ws.lowerIndex < 0 || ws.lowerIndex + 1 >= ws.way.getNodesCount()) … … 352 360 } 353 361 362 @Override 354 363 public void visit(Relation r) { 355 364 /* No idea how to draw a relation. */ … … 387 396 } 388 397 398 @Override 389 399 public void visit(List<Node> nodes) { 390 400 Node lastN = null; -
trunk/src/org/openstreetmap/josm/data/validation/tests/ChangePropertyKeyCommand.java
r3669 r3671 50 50 } 51 51 52 @Override public boolean executeCommand() { 53 if (!super.executeCommand()) return false; // save old 52 @Override 53 public boolean executeCommand() { 54 if (!super.executeCommand()) 55 return false; // save old 54 56 for (OsmPrimitive osm : objects) { 55 if(osm.hasKeys()) 56 { 57 if (osm.hasKeys()) { 57 58 osm.setModified(true); 58 59 String oldValue = osm.get(key); … … 64 65 } 65 66 66 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 67 @Override 68 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 67 69 modified.addAll(objects); 68 70 } 69 71 70 @Override public JLabel getDescription() { 72 @Override 73 public JLabel getDescription() { 71 74 String text = tr( "Replace \"{0}\" by \"{1}\" for", key, newKey); 72 75 if (objects.size() == 1) { … … 74 77 objects.iterator().next().visit(v); 75 78 text += " "+tr(v.className)+" "+v.name; 76 } else 79 } else { 77 80 text += " "+objects.size()+" "+trn("object","objects",objects.size()); 81 } 78 82 return new JLabel(text, ImageProvider.get("data", "key"), JLabel.HORIZONTAL); 79 83 } 80 84 81 @Override public Collection<PseudoCommand> getChildren() { 85 @Override 86 public Collection<PseudoCommand> getChildren() { 82 87 if (objects.size() == 1) 83 88 return null; … … 88 93 osm.visit(v); 89 94 children.add(new PseudoCommand() { 90 @Override public JLabel getDescription() { 95 @Override 96 public JLabel getDescription() { 91 97 return v.toLabel(); 92 98 } 93 @Override public Collection<? extends OsmPrimitive> getParticipatingPrimitives() { 99 @Override 100 public Collection<? extends OsmPrimitive> getParticipatingPrimitives() { 94 101 return Collections.singleton(osm); 95 102 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/Coastlines.java
r3669 r3671 28 28 * @author Teemu Koskinen 29 29 */ 30 public class Coastlines extends Test 31 { 30 public class Coastlines extends Test { 31 32 32 protected static int UNORDERED_COASTLINE = 901; 33 33 protected static int REVERSED_COASTLINE = 902; … … 41 41 * Constructor 42 42 */ 43 public Coastlines() 44 { 43 public Coastlines() { 45 44 super(tr("Coastlines."), 46 45 tr("This test checks that coastlines are correct.")); … … 48 47 49 48 @Override 50 public void startTest(ProgressMonitor monitor) 51 { 49 public void startTest(ProgressMonitor monitor) { 50 52 51 super.startTest(monitor); 53 52 54 53 OsmDataLayer layer = Main.map.mapView.getEditLayer(); 55 54 56 if (layer != null) 55 if (layer != null) { 57 56 downloadedArea = layer.data.getDataSourceArea(); 57 } 58 58 59 59 coastlines = new LinkedList<Way>(); … … 61 61 62 62 @Override 63 public void endTest() 64 { 63 public void endTest() { 65 64 for (Way c1 : coastlines) { 66 65 Node head = c1.firstNode(); 67 66 Node tail = c1.lastNode(); 68 67 69 if (head.equals(tail)) 68 if (head.equals(tail)) { 70 69 continue; 70 } 71 71 72 72 int headWays = 0; … … 80 80 81 81 for (Way c2 : coastlines) { 82 if (c1 == c2) 82 if (c1 == c2) { 83 83 continue; 84 } 84 85 85 86 if (c2.containsNode(head)) { … … 87 88 next = c2; 88 89 89 if (head.equals(c2.firstNode())) 90 if (head.equals(c2.firstNode())) { 90 91 headReversed = true; 91 else if (!head.equals(c2.lastNode())) 92 } else if (!head.equals(c2.lastNode())) { 92 93 headUnordered = true; 94 } 93 95 } 94 96 … … 97 99 prev = c2; 98 100 99 if (tail.equals(c2.lastNode())) 101 if (tail.equals(c2.lastNode())) { 100 102 tailReversed = true; 101 else if (!tail.equals(c2.firstNode())) 103 } else if (!tail.equals(c2.firstNode())) { 102 104 tailUnordered = true; 103 } 104 } 105 105 } 106 } 107 } 106 108 107 109 List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(); … … 121 123 } 122 124 123 if (highlight.size() > 0) 125 if (highlight.size() > 0) { 124 126 errors.add(new TestError(this, Severity.ERROR, tr("Unconnected coastline"), 125 127 UNCONNECTED_COASTLINE, primitives, highlight)); 128 } 126 129 } 127 130 … … 129 132 boolean reversed = false; 130 133 131 if (headWays == 1 && headReversed && tailWays == 1 && tailReversed) 134 if (headWays == 1 && headReversed && tailWays == 1 && tailReversed) { 132 135 reversed = true; 133 134 if (headWays > 1 || tailWays > 1) 136 } 137 138 if (headWays > 1 || tailWays > 1) { 135 139 unordered = true; 136 else if (headUnordered || tailUnordered) 140 } else if (headUnordered || tailUnordered) { 137 141 unordered = true; 138 else if (reversed && next == prev) 142 } else if (reversed && next == prev) { 139 143 unordered = true; 144 } 140 145 141 146 if (unordered) { … … 168 173 169 174 @Override 170 public void visit(Way way) 171 { 175 public void visit(Way way) { 172 176 if (!way.isUsable()) 173 177 return; … … 192 196 return new ChangeCommand(way, newWay); 193 197 } 194 195 198 return null; 196 199 } … … 198 201 @Override 199 202 public boolean isFixable(TestError testError) { 200 if (testError.getTester() instanceof Coastlines) {203 if (testError.getTester() instanceof Coastlines) 201 204 return (testError.getCode() == REVERSED_COASTLINE); 202 }203 205 204 206 return false; -
trunk/src/org/openstreetmap/josm/data/validation/tests/CrossingWays.java
r3669 r3671 28 28 * @author frsantos 29 29 */ 30 public class CrossingWays extends Test 31 { 30 public class CrossingWays extends Test { 32 31 protected static int CROSSING_WAYS = 601; 33 32 … … 39 38 Map<List<Way>, List<WaySegment>> ways_seen; 40 39 41 42 40 /** 43 41 * Constructor 44 42 */ 45 public CrossingWays() 46 { 43 public CrossingWays() { 47 44 super(tr("Crossing ways."), 48 45 tr("This test checks if two roads, railways, waterways or buildings crosses in the same layer, but are not connected by a node.")); 49 46 } 50 47 51 52 48 @Override 53 public void startTest(ProgressMonitor monitor) 54 { 49 public void startTest(ProgressMonitor monitor) { 55 50 super.startTest(monitor); 56 51 cellSegments = new HashMap<Point2D,List<ExtendedSegment>>(1000); … … 60 55 61 56 @Override 62 public void endTest() 63 { 57 public void endTest() { 64 58 super.endTest(); 65 59 cellSegments = null; … … 69 63 70 64 @Override 71 public void visit(Way w) 72 { 73 if( !w.isUsable() ) 65 public void visit(Way w) { 66 if(!w.isUsable()) 74 67 return; 75 68 … … 81 74 boolean isBuilding = (w.get("building") != null); 82 75 83 if( w.get("highway") == null && w.get("waterway") == null && (railway1 == null || isSubway1 || isTram1) && !isCoastline1 && !isBuilding) 76 if (w.get("highway") == null && w.get("waterway") == null 77 && (railway1 == null || isSubway1 || isTram1) 78 && !isCoastline1 && !isBuilding) 84 79 return; 85 80 … … 91 86 ExtendedSegment es1 = new ExtendedSegment(ws, layer1, railway1, coastline1); 92 87 List<List<ExtendedSegment>> cellSegments = getSegments(es1.n1, es1.n2); 93 for( List<ExtendedSegment> segments : cellSegments) 94 { 95 for( ExtendedSegment es2 : segments) 96 { 88 for (List<ExtendedSegment> segments : cellSegments) { 89 for (ExtendedSegment es2 : segments) { 97 90 List<Way> prims; 98 91 List<WaySegment> highlight; … … 107 100 continue; 108 101 109 if (!es1.intersects(es2) ) continue;110 if (isSubway1 && "subway".equals(railway2)) continue;111 if (isTram1 && "tram".equals(railway2)) continue;102 if (!es1.intersects(es2) ) continue; 103 if (isSubway1 && "subway".equals(railway2)) continue; 104 if (isTram1 && "tram".equals(railway2)) continue; 112 105 113 106 boolean isCoastline2 = coastline2 != null && (coastline2.equals("water") || coastline2.equals("coastline")); 114 if( isCoastline1 != isCoastline2 ) continue; 115 116 if((es1.railway != null && es1.railway.equals("abandoned")) || (railway2 != null && railway2.equals("abandoned"))) continue; 107 if (isCoastline1 != isCoastline2) continue; 108 109 if ((es1.railway != null && es1.railway.equals("abandoned")) 110 || (railway2 != null && railway2.equals("abandoned"))) continue; 117 111 118 112 prims = Arrays.asList(es1.ws.way, es2.ws.way); 119 if ((highlight = ways_seen.get(prims)) == null) 120 { 113 if ((highlight = ways_seen.get(prims)) == null) { 121 114 highlight = new ArrayList<WaySegment>(); 122 115 highlight.add(es1.ws); … … 124 117 125 118 errors.add(new TestError(this, Severity.WARNING, 126 isBuilding ? tr("Crossing buildings") : tr("Crossing ways"), CROSSING_WAYS, prims, highlight)); 119 isBuilding ? tr("Crossing buildings") : tr("Crossing ways"), 120 CROSSING_WAYS, 121 prims, 122 highlight)); 127 123 ways_seen.put(prims, highlight); 128 } 129 else 130 { 124 } else { 131 125 highlight.add(es1.ws); 132 126 highlight.add(es2.ws); … … 146 140 * @return A list with all the cells the segment crosses 147 141 */ 148 public List<List<ExtendedSegment>> getSegments(Node n1, Node n2) 149 { 142 public List<List<ExtendedSegment>> getSegments(Node n1, Node n2) { 143 150 144 List<List<ExtendedSegment>> cells = new ArrayList<List<ExtendedSegment>>(); 151 for( Point2D cell : ValUtil.getSegmentCells(n1, n2, OsmValidator.griddetail) ) 152 { 153 List<ExtendedSegment> segments = cellSegments.get( cell ); 154 if( segments == null ) 155 { 145 for(Point2D cell : ValUtil.getSegmentCells(n1, n2, OsmValidator.griddetail)) { 146 List<ExtendedSegment> segments = cellSegments.get(cell); 147 if (segments == null) { 156 148 segments = new ArrayList<ExtendedSegment>(); 157 149 cellSegments.put(cell, segments); … … 159 151 cells.add(segments); 160 152 } 161 162 153 return cells; 163 154 } … … 167 158 * @author frsantos 168 159 */ 169 private static class ExtendedSegment 170 { 160 public static class ExtendedSegment { 171 161 public Node n1, n2; 172 162 … … 187 177 * @param layer The layer of the way this segment is in 188 178 * @param railway The railway type of the way this segment is in 189 * @param coastline The coastl yne typo of the way the segment is in179 * @param coastline The coastline typo of the way the segment is in 190 180 */ 191 public ExtendedSegment(WaySegment ws, String layer, String railway, String coastline) 192 { 181 public ExtendedSegment(WaySegment ws, String layer, String railway, String coastline) { 193 182 this.ws = ws; 194 183 this.n1 = ws.way.getNodes().get(ws.lowerIndex); … … 202 191 * Checks whether this segment crosses other segment 203 192 * @param s2 The other segment 204 * @return true if both seg ements crosses193 * @return true if both segments crosses 205 194 */ 206 public boolean intersects(ExtendedSegment s2) 207 { 208 if( n1.equals(s2.n1) || n2.equals(s2.n2) || 209 n1.equals(s2.n2) || n2.equals(s2.n1) ) 210 { 195 public boolean intersects(ExtendedSegment s2) { 196 if (n1.equals(s2.n1) || n2.equals(s2.n2) || 197 n1.equals(s2.n2) || n2.equals(s2.n1)) 211 198 return false; 212 }213 199 214 200 return Line2D.linesIntersect( -
trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateNode.java
r3669 r3671 58 58 private LatLon getLatLon(Object o) { 59 59 if (o instanceof Node) { 60 if (precision==0) {60 if (precision==0) 61 61 return ((Node) o).getCoor().getRoundedToOsmPrecision(); 62 } else { 63 return RoundCoord((Node) o); 64 } 62 return RoundCoord((Node) o); 65 63 } else if (o instanceof List<?>) { 66 if (precision==0) {64 if (precision==0) 67 65 return ((List<Node>) o).get(0).getCoor().getRoundedToOsmPrecision(); 68 } else { 69 return RoundCoord(((List<Node>) o).get(0)); 70 } 66 return RoundCoord(((List<Node>) o).get(0)); 71 67 } else { 72 68 throw new AssertionError(); … … 74 70 } 75 71 72 @Override 76 73 public boolean equals(Object k, Object t) { 77 74 return getLatLon(k).equals(getLatLon(t)); 78 75 } 79 76 77 @Override 80 78 public int getHashCode(Object k) { 81 79 return getLatLon(k).hashCode(); 82 80 } 83 84 81 } 85 82 … … 107 104 * Constructor 108 105 */ 109 public DuplicateNode() 110 { 106 public DuplicateNode() { 111 107 super(tr("Duplicated nodes")+".", 112 108 tr("This test checks that there are no nodes at the very same location.")); … … 132 128 // multiple nodes at the same position -> report errors 133 129 // 134 List<Node> nodes = (List<Node>)v; 130 List<Node> nodes = (List<Node>) v; 135 131 errors.addAll(buildTestErrors(this, nodes)); 136 132 } … … 154 150 // the same tag set 155 151 // 156 for (Iterator<Map<String,String>> it = bag.keySet().iterator(); it.hasNext(); 152 for (Iterator<Map<String,String>> it = bag.keySet().iterator(); it.hasNext();) { 157 153 Map<String,String> tagSet = it.next(); 158 154 if (bag.get(tagSet).size() > 1) { … … 177 173 } 178 174 } 179 if (!typed) typeMap.put("none", true); 175 if (!typed) { 176 typeMap.put("none", true); 177 } 180 178 } 181 179 } … … 186 184 int nbType=0; 187 185 for (String type: typeMap.keySet()) { 188 if (typeMap.get(type)) nbType++; 186 if (typeMap.get(type)) { 187 nbType++; 188 } 189 189 } 190 190 … … 303 303 it.remove(); 304 304 } 305 306 305 } 307 306 … … 359 358 */ 360 359 @Override 361 public Command fixError(TestError testError) 362 { 360 public Command fixError(TestError testError) { 363 361 Collection<OsmPrimitive> sel = new LinkedList<OsmPrimitive>(testError.getPrimitives()); 364 362 LinkedHashSet<Node> nodes = new LinkedHashSet<Node>(OsmPrimitive.getFilteredList(sel, Node.class)); -
trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateWay.java
r3669 r3671 40 40 keys=_keys; 41 41 } 42 42 43 @Override 43 44 public int hashCode() { 44 45 return coor.hashCode()+keys.hashCode(); 45 46 } 47 46 48 @Override 47 49 public boolean equals(Object obj) { 48 if (!(obj instanceof WayPair)) return false; 50 if (!(obj instanceof WayPair)) 51 return false; 49 52 WayPair wp = (WayPair) obj; 50 53 return wp.coor.equals(coor) && wp.keys.equals(keys); … … 60 63 * Constructor 61 64 */ 62 public DuplicateWay() 63 { 65 public DuplicateWay() { 64 66 super(tr("Duplicated ways")+".", 65 67 tr("This test checks that there are no ways with same tags and same node coordinates.")); … … 68 70 69 71 @Override 70 public void startTest(ProgressMonitor monitor) 71 { 72 public void startTest(ProgressMonitor monitor) { 72 73 super.startTest(monitor); 73 74 ways = new Bag<WayPair, OsmPrimitive>(1000); … … 75 76 76 77 @Override 77 public void endTest() 78 { 78 public void endTest() { 79 79 super.endTest(); 80 for(List<OsmPrimitive> duplicated : ways.values() ) 81 { 82 if( duplicated.size() > 1) 83 { 80 for (List<OsmPrimitive> duplicated : ways.values()) { 81 if (duplicated.size() > 1) { 84 82 TestError testError = new TestError(this, Severity.ERROR, tr("Duplicated ways"), DUPLICATE_WAY, duplicated); 85 errors.add( 83 errors.add(testError); 86 84 } 87 85 } … … 90 88 91 89 @Override 92 public void visit(Way w) 93 { 94 if( !w.isUsable() ) 90 public void visit(Way w) { 91 if (!w.isUsable()) 95 92 return; 96 93 List<Node> wNodes=w.getNodes(); 97 94 Vector<LatLon> wLat=new Vector<LatLon>(wNodes.size()); 98 for(int i=0;i<wNodes.size();i++) { 99 95 for (int i=0;i<wNodes.size();i++) { 96 wLat.add(wNodes.get(i).getCoor()); 100 97 } 101 98 Map<String, String> wkeys=w.getKeys(); … … 109 106 */ 110 107 @Override 111 public Command fixError(TestError testError) 112 { 108 public Command fixError(TestError testError) { 113 109 Collection<? extends OsmPrimitive> sel = testError.getPrimitives(); 114 110 HashSet<Way> ways = new HashSet<Way>(); 115 111 116 for (OsmPrimitive osm : sel) 117 if (osm instanceof Way) 112 for (OsmPrimitive osm : sel) { 113 if (osm instanceof Way) { 118 114 ways.add((Way)osm); 115 } 116 } 119 117 120 if (ways.size() < 2118 if (ways.size() < 2) 121 119 return null; 122 120 … … 171 169 172 170 @Override 173 public boolean isFixable(TestError testError) 174 { 171 public boolean isFixable(TestError testError) { 175 172 if (!(testError.getTester() instanceof DuplicateWay)) 176 173 return false; … … 180 177 HashSet<Way> ways = new HashSet<Way>(); 181 178 182 for (OsmPrimitive osm : sel) 183 if (osm instanceof Way) 179 for (OsmPrimitive osm : sel) { 180 if (osm instanceof Way) { 184 181 ways.add((Way)osm); 182 } 183 } 185 184 186 185 if (ways.size() < 2) -
trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicatedWayNodes.java
r3669 r3671 25 25 } 26 26 27 @Override public void visit(Way w) { 27 @Override 28 public void visit(Way w) { 28 29 if (!w.isUsable()) return; 29 30 -
trunk/src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java
r3669 r3671 51 51 52 52 @Override 53 public void initialize() throws Exception 54 { 53 public void initialize() throws Exception { 55 54 styles = MapPaintStyles.getStyles().getStyleSet(); 56 55 } … … 59 58 List<List<Node>> result = new ArrayList<List<Node>>(); 60 59 List<Way> waysToJoin = new ArrayList<Way>(); 61 for (Way way: ways) { 60 for (Way way : ways) { 62 61 if (way.isClosed()) { 63 62 result.add(way.getNodes()); … … 67 66 } 68 67 69 for (JoinedWay jw: Multipolygon.joinWays(waysToJoin)) { 68 for (JoinedWay jw : Multipolygon.joinWays(waysToJoin)) { 70 69 if (!jw.isClosed()) { 71 70 nonClosedWays.add(jw.getNodes()); … … 79 78 private GeneralPath createPath(List<Node> nodes) { 80 79 GeneralPath result = new GeneralPath(); 81 result.moveTo((float)nodes.get(0).getCoor().lat(), (float)nodes.get(0).getCoor().lon()); 80 result.moveTo((float) nodes.get(0).getCoor().lat(), (float) nodes.get(0).getCoor().lon()); 82 81 for (int i=1; i<nodes.size(); i++) { 83 82 Node n = nodes.get(i); 84 result.lineTo((float)n.getCoor().lat(), (float)n.getCoor().lon()); 83 result.lineTo((float )n.getCoor().lat(), (float) n.getCoor().lon()); 85 84 } 86 85 return result; … … 89 88 private List<GeneralPath> createPolygons(List<List<Node>> joinedWays) { 90 89 List<GeneralPath> result = new ArrayList<GeneralPath>(); 91 for (List<Node> way: joinedWays) { 90 for (List<Node> way : joinedWays) { 92 91 result.add(createPath(way)); 93 92 } … … 99 98 boolean outside = false; 100 99 101 for (Node n: inner) { 100 for (Node n : inner) { 102 101 boolean contains = outer.contains(n.getCoor().lat(), n.getCoor().lon()); 103 102 inside = inside | contains; … … 108 107 } 109 108 110 return inside ?Intersection.INSIDE:Intersection.OUTSIDE;109 return inside ? Intersection.INSIDE : Intersection.OUTSIDE; 111 110 } 112 111 113 112 @Override 114 113 public void visit(Way w) { 115 if (styles != null && !w.isClosed()) 116 { 114 if (styles != null && !w.isClosed()) { 117 115 ElemStyle e = styles.getArea(w); 118 if(e instanceof AreaElemStyle && !((AreaElemStyle)e).closed) 116 if (e instanceof AreaElemStyle && !((AreaElemStyle)e).closed) { 119 117 errors.add( new TestError(this, Severity.WARNING, tr("Area style way is not closed"), NOT_CLOSED, w)); 118 } 120 119 } 121 120 } … … 134 133 } 135 134 136 for (RelationMember rm: r.getMembers()) { 137 if (!rm.getMember().isUsable()) {135 for (RelationMember rm : r.getMembers()) { 136 if (!rm.getMember().isUsable()) 138 137 return; // Rest of checks is only for complete multipolygons 139 }140 138 } 141 139 … … 143 141 List<List<Node>> outerWays = joinWays(polygon.getOuterWays()); 144 142 145 if(styles != null) { 143 if (styles != null) { 146 144 ElemStyle wayStyle = styles.get(r); 147 145 148 146 // If area style was not found for relation then use style of ways 149 if(!(wayStyle instanceof AreaElemStyle)) { 147 if (!(wayStyle instanceof AreaElemStyle)) { 150 148 errors.add( new TestError(this, Severity.OTHER, tr("No style in multipolygon relation"), 151 149 NO_STYLE_POLYGON, r)); … … 159 157 160 158 if (wayStyle instanceof AreaElemStyle) { 161 for (Way wInner : polygon.getInnerWays()) 162 { 159 for (Way wInner : polygon.getInnerWays()) { 163 160 ElemStyle innerStyle = styles.get(wInner); 164 if(wayStyle != null && wayStyle.equals(innerStyle)) { 161 if (wayStyle != null && wayStyle.equals(innerStyle)) { 165 162 List<OsmPrimitive> l = new ArrayList<OsmPrimitive>(); 166 163 l.add(r); … … 170 167 } 171 168 } 172 for (Way wOuter : polygon.getOuterWays()) 173 { 169 for (Way wOuter : polygon.getOuterWays()) { 174 170 ElemStyle outerStyle = styles.get(wOuter); 175 if(outerStyle instanceof AreaElemStyle && !wayStyle.equals(outerStyle)) { 171 if (outerStyle instanceof AreaElemStyle && !wayStyle.equals(outerStyle)) { 176 172 List<OsmPrimitive> l = new ArrayList<OsmPrimitive>(); 177 173 l.add(r); 178 174 l.add(wOuter); 179 errors.add( 175 errors.add(new TestError(this, Severity.WARNING, tr("Style for outer way mismatches"), 180 176 OUTER_STYLE_MISMATCH, l, Collections.singletonList(wOuter))); 181 177 } 182 178 } 183 179 } 184 else 185 errors.add( 186 NO_STYLE, r));180 else { 181 errors.add(new TestError(this, Severity.OTHER, tr("No style for multipolygon"), NO_STYLE, r)); 182 } 187 183 } 188 184 189 185 if (!nonClosedWays.isEmpty()) { 190 errors.add( 186 errors.add(new TestError(this, Severity.WARNING, tr("Multipolygon is not closed"), NON_CLOSED_WAY, Collections.singletonList(r), nonClosedWays)); 191 187 } 192 188 193 189 // For painting is used Polygon class which works with ints only. For validation we need more precision 194 190 List<GeneralPath> outerPolygons = createPolygons(outerWays); 195 for (List<Node> pdInner: innerWays) { 191 for (List<Node> pdInner : innerWays) { 196 192 boolean outside = true; 197 193 boolean crossing = false; … … 221 217 222 218 private void checkMembersAndRoles(Relation r) { 223 for (RelationMember rm: r.getMembers()) { 219 for (RelationMember rm : r.getMembers()) { 224 220 if (rm.isWay()) { 225 221 if (!("inner".equals(rm.getRole()) || "outer".equals(rm.getRole()) || !rm.hasRole())) { 226 errors.add( 222 errors.add(new TestError(this, Severity.WARNING, tr("No useful role for multipolygon member"), WRONG_MEMBER_ROLE, rm.getMember())); 227 223 } 228 224 } else { 229 errors.add( new TestError(this, Severity.WARNING, tr("Non-Way in multipolygon"), WRONG_MEMBER_TYPE, rm.getMember())); 230 } 231 } 232 } 233 234 225 errors.add(new TestError(this, Severity.WARNING, tr("Non-Way in multipolygon"), WRONG_MEMBER_TYPE, rm.getMember())); 226 } 227 } 228 } 235 229 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/NameMismatch.java
r3669 r3671 72 72 if (name == null) { 73 73 errors.add(new TestError(this, Severity.OTHER, 74 tr("A name is missing, even though name:* exists."), 75 74 tr("A name is missing, even though name:* exists."), 75 NAME_MISSING, p)); 76 76 return; 77 77 } … … 105 105 @Override public void visit(Collection<OsmPrimitive> selection) { 106 106 for (OsmPrimitive p : selection) 107 if (!p.isDeleted() && !p.isIncomplete()) 107 if (!p.isDeleted() && !p.isIncomplete()) { 108 108 check(p); 109 } 109 110 } 110 111 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/NodesWithSameName.java
r3669 r3671 9 9 import java.util.HashSet; 10 10 import java.util.ArrayList; 11 12 11 13 12 import org.openstreetmap.josm.data.osm.Node; … … 39 38 String highway = n.get("highway"); 40 39 if (name == null 41 || (sign != null && sign.equals("city_limit")) 42 || (highway != null && highway.equals("bus_stop"))) {40 || (sign != null && sign.equals("city_limit")) 41 || (highway != null && highway.equals("bus_stop"))) 43 42 return; 44 }45 43 46 44 List<Node> nodes = namesToNodes.get(name); 47 if (nodes == null) 45 if (nodes == null) { 48 46 namesToNodes.put(name, nodes = new ArrayList<Node>()); 47 } 49 48 50 49 nodes.add(n); … … 61 60 if (ref == null || !refs.add(ref)) { 62 61 errors.add(new TestError(this, Severity.OTHER, 63 tr("Nodes with same name"), SAME_NAME, nodes)); 62 tr("Nodes with same name"), SAME_NAME, nodes)); 64 63 break; 65 64 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/OverlappingWays.java
r3669 r3671 26 26 * @author frsantos 27 27 */ 28 public class OverlappingWays extends Test 29 { 28 public class OverlappingWays extends Test { 29 30 30 /** Bag of all way segments */ 31 31 Bag<Pair<Node,Node>, WaySegment> nodePairs; … … 40 40 41 41 /** Constructor */ 42 public OverlappingWays() 43 { 42 public OverlappingWays() { 44 43 super(tr("Overlapping ways."), 45 44 tr("This test checks that a connection between two nodes " 46 45 + "is not used by more than one way.")); 47 48 46 } 49 47 50 51 48 @Override 52 public void startTest(ProgressMonitor monitor) 53 { 49 public void startTest(ProgressMonitor monitor) { 54 50 super.startTest(monitor); 55 51 nodePairs = new Bag<Pair<Node,Node>, WaySegment>(1000); … … 57 53 58 54 @Override 59 public void endTest() 60 { 55 public void endTest() { 61 56 Map<List<Way>, List<WaySegment>> ways_seen = new HashMap<List<Way>, List<WaySegment>>(500); 62 57 63 for (List<WaySegment> duplicated : nodePairs.values()) 64 { 58 for (List<WaySegment> duplicated : nodePairs.values()) { 65 59 int ways = duplicated.size(); 66 60 67 if (ways > 1) 68 { 61 if (ways > 1) { 69 62 List<OsmPrimitive> prims = new ArrayList<OsmPrimitive>(); 70 63 List<Way> current_ways = new ArrayList<Way>(); … … 74 67 int area = 0; 75 68 76 for (WaySegment ws : duplicated) 77 { 78 if (ws.way.get("highway") != null) 69 for (WaySegment ws : duplicated) { 70 if (ws.way.get("highway") != null) { 79 71 highway++; 80 else if (ws.way.get("railway") != null) 72 } else if (ws.way.get("railway") != null) { 81 73 railway++; 74 } 82 75 Boolean ar = OsmUtils.getOsmBoolean(ws.way.get("area")); 83 if (ar != null && ar) 76 if (ar != null && ar) { 84 77 area++; 85 if (ws.way.get("landuse") != null || ws.way.get("natural") != null 86 || ws.way.get("amenity") != null || ws.way.get("leisure") != null 87 || ws.way.get("building") != null) 88 { 89 area++; ways--; 78 } 79 if (ws.way.get("landuse") != null 80 || ws.way.get("natural") != null 81 || ws.way.get("amenity") != null 82 || ws.way.get("leisure") != null 83 || ws.way.get("building") != null) { 84 area++; 85 ways--; 90 86 } 91 87 … … 97 93 * highways or railways mark a separate error 98 94 */ 99 if ((highlight = ways_seen.get(current_ways)) == null) 100 { 95 if ((highlight = ways_seen.get(current_ways)) == null) { 101 96 String errortype; 102 97 int type; 103 98 104 if(area > 0) 105 { 106 if (ways == 0 || duplicated.size() == area) 107 { 99 if (area > 0) { 100 if (ways == 0 || duplicated.size() == area) { 108 101 errortype = tr("Overlapping areas"); 109 102 type = OVERLAPPING_AREA; 110 } 111 else if (highway == ways) 112 { 103 } else if (highway == ways) { 113 104 errortype = tr("Overlapping highways (with area)"); 114 105 type = OVERLAPPING_HIGHWAY_AREA; 115 } 116 else if (railway == ways) 117 { 106 } else if (railway == ways) { 118 107 errortype = tr("Overlapping railways (with area)"); 119 108 type = OVERLAPPING_RAILWAY_AREA; 120 } 121 else 122 { 109 } else { 123 110 errortype = tr("Overlapping ways (with area)"); 124 111 type = OVERLAPPING_WAY_AREA; 125 112 } 126 113 } 127 else if (highway == ways) 128 { 114 else if (highway == ways) { 129 115 errortype = tr("Overlapping highways"); 130 116 type = OVERLAPPING_HIGHWAY; 131 } 132 else if (railway == ways) 133 { 117 } else if (railway == ways) { 134 118 errortype = tr("Overlapping railways"); 135 119 type = OVERLAPPING_RAILWAY; 136 } 137 else 138 { 120 } else { 139 121 errortype = tr("Overlapping ways"); 140 122 type = OVERLAPPING_WAY; 141 123 } 142 124 143 errors.add(new TestError(this, type < OVERLAPPING_HIGHWAY_AREA 144 ? Severity.WARNING : Severity.OTHER, tr(errortype), type, prims, duplicated)); 125 errors.add(new TestError(this, 126 type < OVERLAPPING_HIGHWAY_AREA ? Severity.WARNING : Severity.OTHER, 127 tr(errortype), type, prims, duplicated)); 145 128 ways_seen.put(current_ways, duplicated); 146 } 147 else /* way seen, mark highlight layer only */ 148 { 149 for (WaySegment ws : duplicated) 129 } else { /* way seen, mark highlight layer only */ 130 for (WaySegment ws : duplicated) { 150 131 highlight.add(ws); 132 } 151 133 } 152 134 } … … 157 139 158 140 @Override 159 public void visit(Way w) 160 { 141 public void visit(Way w) { 161 142 Node lastN = null; 162 143 int i = -2; -
trunk/src/org/openstreetmap/josm/data/validation/tests/RelationChecker.java
r3669 r3671 23 23 * 24 24 */ 25 public class RelationChecker extends Test 26 { 25 public class RelationChecker extends Test { 26 27 27 protected static int ROLE_UNKNOWN = 1701; 28 28 protected static int ROLE_EMPTY = 1702; … … 37 37 * Constructor 38 38 */ 39 public RelationChecker() 40 { 39 public RelationChecker() { 41 40 super(tr("Relation checker :"), 42 41 tr("This plugin checks for errors in relations.")); … … 44 43 45 44 @Override 46 public void initialize() throws Exception 47 { 45 public void initialize() throws Exception { 48 46 initializePresets(); 49 47 } 50 48 51 49 static Collection<TaggingPreset> relationpresets = new LinkedList<TaggingPreset>(); 50 52 51 /** 53 52 * Reads the presets data. 54 53 * 55 54 */ 56 public void initializePresets() 57 { 55 public void initializePresets() { 58 56 Collection<TaggingPreset> presets = TaggingPresetPreference.taggingPresets; 59 if(presets != null) 60 { 61 for(TaggingPreset p : presets) 62 { 63 for(TaggingPreset.Item i : p.data) 64 { 65 if(i instanceof TaggingPreset.Roles) 66 { 57 if (presets != null) { 58 for (TaggingPreset p : presets) { 59 for (TaggingPreset.Item i : p.data) { 60 if (i instanceof TaggingPreset.Roles) { 67 61 relationpresets.add(p); 68 62 break; … … 73 67 } 74 68 75 public class RoleInfo 76 { 69 public class RoleInfo { 77 70 int total = 0; 78 71 int nodes = 0; … … 84 77 85 78 @Override 86 public void visit(Relation n) 87 { 79 public void visit(Relation n) { 88 80 LinkedList<TaggingPreset.Role> allroles = new LinkedList<TaggingPreset.Role>(); 89 for(TaggingPreset p : relationpresets) 90 { 81 for (TaggingPreset p : relationpresets) { 91 82 boolean matches = true; 92 83 TaggingPreset.Roles r = null; 93 for(TaggingPreset.Item i : p.data) 94 { 95 if(i instanceof TaggingPreset.Key) 96 { 97 TaggingPreset.Key k = (TaggingPreset.Key)i; 98 if(!k.value.equals(n.get(k.key))) 99 { 84 for (TaggingPreset.Item i : p.data) { 85 if (i instanceof TaggingPreset.Key) { 86 TaggingPreset.Key k = (TaggingPreset.Key) i; 87 if (!k.value.equals(n.get(k.key))) { 100 88 matches = false; 101 89 break; 102 90 } 91 } else if (i instanceof TaggingPreset.Roles) { 92 r = (TaggingPreset.Roles) i; 103 93 } 104 else if(i instanceof TaggingPreset.Roles)105 r = (TaggingPreset.Roles) i;106 94 } 107 if(matches && r != null) 95 if (matches && r != null) { 108 96 allroles.addAll(r.roles); 97 } 109 98 } 110 if(allroles.size() == 0) 111 { 99 if (allroles.size() == 0) { 112 100 errors.add( new TestError(this, Severity.WARNING, tr("Relation type is unknown"), 113 101 RELATION_UNKNOWN, n) ); 114 115 } 116 else 117 { 102 } else { 118 103 HashMap<String,RoleInfo> map = new HashMap<String, RoleInfo>(); 119 for(RelationMember m : n.getMembers()) { 104 for (RelationMember m : n.getMembers()) { 120 105 String s = ""; 121 if(m.hasRole()) 106 if (m.hasRole()) { 122 107 s = m.getRole(); 108 } 123 109 RoleInfo ri = map.get(s); 124 if(ri == null) 110 if (ri == null) { 125 111 ri = new RoleInfo(); 112 } 126 113 ri.total++; 127 if(m.isRelation()) 114 if (m.isRelation()) { 128 115 ri.relations++; 129 else if(m.isWay()) 130 { 116 } else if(m.isWay()) { 131 117 ri.ways++; 132 if(m.getWay().isClosed()) 118 if (m.getWay().isClosed()) { 133 119 ri.closedways++; 134 else120 } else { 135 121 ri.openways++; 122 } 136 123 } 137 else if(m.isNode()) 124 else if (m.isNode()) { 138 125 ri.nodes++; 126 } 139 127 map.put(s, ri); 140 128 } 141 if(map. size() == 0)129 if(map.isEmpty()) { 142 130 errors.add( new TestError(this, Severity.ERROR, tr("Relation is empty"), 143 131 RELATION_EMPTY, n) ); 144 else 145 { 132 } else { 146 133 LinkedList<String> done = new LinkedList<String>(); 147 for(TaggingPreset.Role r : allroles) 148 { 134 for (TaggingPreset.Role r : allroles) { 149 135 done.add(r.key); 150 136 String keyname = r.key; 151 if(keyname == "") 137 if (keyname == "") { //FIXME 152 138 keyname = tr("<empty>"); 139 } 153 140 RoleInfo ri = map.get(r.key); 154 141 long count = (ri == null) ? 0 : ri.total; 155 142 long vc = r.getValidCount(count); 156 if(count != vc) 157 { 158 if(count == 0) 159 { 143 if (count != vc) { 144 if (count == 0) { 160 145 String s = marktr("Role {0} missing"); 161 146 errors.add( new TestError(this, Severity.WARNING, tr("Role verification problem"), 162 147 tr(s, keyname), MessageFormat.format(s, keyname), ROLE_MISSING, n) ); 163 148 } 164 else if(vc > count) 165 { 149 else if (vc > count) { 166 150 String s = marktr("Number of {0} roles too low ({1})"); 167 151 errors.add( new TestError(this, Severity.WARNING, tr("Role verification problem"), 168 152 tr(s, keyname, count), MessageFormat.format(s, keyname, count), LOW_COUNT, n) ); 169 } 170 else 171 { 153 } else { 172 154 String s = marktr("Number of {0} roles too high ({1})"); 173 155 errors.add( new TestError(this, Severity.WARNING, tr("Role verification problem"), … … 175 157 } 176 158 } 177 if(ri != null && ((!r.types.contains(PresetType.WAY) && (r.types.contains(PresetType.CLOSEDWAY) ? ri.openways > 0 : ri.ways > 0)) 159 if (ri != null && ((!r.types.contains(PresetType.WAY) && (r.types.contains(PresetType.CLOSEDWAY) ? ri.openways > 0 : ri.ways > 0)) 178 160 || (!r.types.contains(PresetType.NODE) && ri.nodes > 0) || (!r.types.contains(PresetType.RELATION) && ri.relations > 0))) 179 161 { … … 183 165 } 184 166 } 185 for(String key : map.keySet()) 186 { 187 if(!done.contains(key)) 188 { 189 if(key.length() > 0) 190 { 167 for (String key : map.keySet()) { 168 if (!done.contains(key)) { 169 if (key.length() > 0) { 191 170 String s = marktr("Role {0} unknown"); 192 errors.add( new TestError(this, Severity.WARNING, tr("Role verification problem"), 193 tr(s, key), MessageFormat.format(s, key), ROLE_UNKNOWN, n) ); 194 } 195 else 196 { 171 errors.add(new TestError(this, Severity.WARNING, tr("Role verification problem"), 172 tr(s, key), MessageFormat.format(s, key), ROLE_UNKNOWN, n)); 173 } else { 197 174 String s = marktr("Empty role found"); 198 errors.add( 199 tr(s), s, ROLE_EMPTY, n) 175 errors.add(new TestError(this, Severity.WARNING, tr("Role verification problem"), 176 tr(s), s, ROLE_EMPTY, n)); 200 177 } 201 178 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/SelfIntersectingWay.java
r3669 r3671 17 17 */ 18 18 public class SelfIntersectingWay extends Test { 19 19 20 protected static int SELF_INTERSECT = 401; 20 21 -
trunk/src/org/openstreetmap/josm/data/validation/tests/SimilarNamedWays.java
r3669 r3671 25 25 * @author frsantos 26 26 */ 27 public class SimilarNamedWays extends Test 28 { 27 public class SimilarNamedWays extends Test { 28 29 29 protected static int SIMILAR_NAMED = 701; 30 30 … … 37 37 * Constructor 38 38 */ 39 public SimilarNamedWays() 40 { 39 public SimilarNamedWays() { 41 40 super(tr("Similarly named ways")+".", 42 41 tr("This test checks for ways with similar names that may have been misspelled.")); … … 44 43 45 44 @Override 46 public void startTest(ProgressMonitor monitor) 47 { 45 public void startTest(ProgressMonitor monitor) { 48 46 super.startTest(monitor); 49 47 cellWays = new HashMap<Point2D,List<Way>>(1000); … … 52 50 53 51 @Override 54 public void endTest() 55 { 52 public void endTest() { 56 53 cellWays = null; 57 54 errorWays = null; … … 60 57 61 58 @Override 62 public void visit(Way w) 63 { 64 if( !w.isUsable() ) 59 public void visit(Way w) { 60 if (!w.isUsable()) 65 61 return; 66 62 67 63 String name = w.get("name"); 68 if (name == null || name.length() < 664 if (name == null || name.length() < 6) 69 65 return; 70 66 71 67 List<List<Way>> theCellWays = ValUtil.getWaysInCell(w, cellWays); 72 for( List<Way> ways : theCellWays) 73 { 74 for( Way w2 : ways) 75 { 76 if( errorWays.contains(w, w2) || errorWays.contains(w2, w) ) 68 for (List<Way> ways : theCellWays) { 69 for (Way w2 : ways) { 70 if (errorWays.contains(w, w2) || errorWays.contains(w2, w)) { 77 71 continue; 72 } 78 73 79 74 String name2 = w2.get("name"); 80 if (name2 == null || name2.length() < 6)75 if (name2 == null || name2.length() < 6) { 81 76 continue; 77 } 82 78 83 79 int levenshteinDistance = getLevenshteinDistance(name, name2); 84 if( 0 < levenshteinDistance && levenshteinDistance <= 2 ) 85 { 80 if (0 < levenshteinDistance && levenshteinDistance <= 2) { 86 81 List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(); 87 82 primitives.add(w); 88 83 primitives.add(w2); 89 errors.add( 84 errors.add(new TestError(this, Severity.WARNING, tr("Similarly named ways"), SIMILAR_NAMED, primitives)); 90 85 errorWays.add(w, w2); 91 86 } … … 102 97 * @return The distance between words 103 98 */ 104 public int getLevenshteinDistance(String s, String t) 105 { 99 public int getLevenshteinDistance(String s, String t) { 106 100 int d[][]; // matrix 107 101 int n; // length of s … … 114 108 115 109 // Step 1 116 117 110 n = s.length(); 118 111 m = t.length(); 119 if (n == 0) return m; 120 if (m == 0) return n; 112 if (n == 0) 113 return m; 114 if (m == 0) 115 return n; 121 116 d = new int[n + 1][m + 1]; 122 117 123 118 // Step 2 124 for (i = 0; i <= n; i++) d[i][0] = i; 125 for (j = 0; j <= m; j++) d[0][j] = j; 119 for (i = 0; i <= n; i++) { 120 d[i][0] = i; 121 } 122 for (j = 0; j <= m; j++) { 123 d[0][j] = j; 124 } 126 125 127 126 // Step 3 128 for (i = 1; i <= n; i++) 129 { 127 for (i = 1; i <= n; i++) { 128 130 129 s_i = s.charAt(i - 1); 131 130 132 131 // Step 4 133 for (j = 1; j <= m; j++) 134 { 132 for (j = 1; j <= m; j++) { 133 135 134 t_j = t.charAt(j - 1); 136 135 137 136 // Step 5 138 if (s_i == t_j) 139 { 137 if (s_i == t_j) { 140 138 cost = 0; 141 } 142 else 143 { 139 } else { 144 140 cost = 1; 145 141 } 146 142 147 143 // Step 6 148 d[i][j] = Minimum(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);144 d[i][j] = min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost); 149 145 } 150 146 } … … 154 150 } 155 151 156 /** 152 /** // FIXME: move to utils 157 153 * Get minimum of three values 158 154 * @param a First value 159 155 * @param b Second value 160 156 * @param c Third value 161 * @return The minimum of the t re values157 * @return The minimum of the three values 162 158 */ 163 private static int Minimum(int a, int b, int c) 164 { 159 private static int min(int a, int b, int c) { 165 160 int mi = a; 166 if (b < mi) 167 { 161 if (b < mi) { 168 162 mi = b; 169 } 170 if (c < mi) 171 { 163 } if (c < mi) { 172 164 mi = c; 173 165 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
r3669 r3671 141 141 142 142 /** List of sources for spellcheck data */ 143 protected JList Sources; 144 143 protected JList sourcesList; 145 144 146 145 protected static Entities entities = new Entities(); 146 147 147 /** 148 148 * Constructor 149 149 */ 150 public TagChecker() 151 { 150 public TagChecker() { 152 151 super(tr("Properties checker :"), 153 152 tr("This plugin checks for errors in property keys and values.")); … … 155 154 156 155 @Override 157 public void initialize() throws Exception 158 { 156 public void initialize() throws Exception { 159 157 initializeData(); 160 158 initializePresets(); … … 170 168 * @throws IOException 171 169 */ 172 private static void initializeData() throws IOException 173 { 170 private static void initializeData() throws IOException { 174 171 spellCheckKeyData = new HashMap<String, String>(); 175 172 String sources = Main.pref.get( PREF_SOURCES, ""); 176 if(Main.pref.getBoolean(PREF_USE_DATA_FILE, true)) 177 { 178 if( sources == null || sources.length() == 0) 173 if (Main.pref.getBoolean(PREF_USE_DATA_FILE, true)) { 174 if (sources == null || sources.length() == 0) { 179 175 sources = DATA_FILE; 180 else176 } else { 181 177 sources = DATA_FILE + ";" + sources; 182 } 183 if(Main.pref.getBoolean(PREF_USE_IGNORE_FILE, true))184 { 185 if (sources == null || sources.length() == 0)178 } 179 } 180 if (Main.pref.getBoolean(PREF_USE_IGNORE_FILE, true)) { 181 if (sources == null || sources.length() == 0) { 186 182 sources = IGNORE_FILE; 187 else183 } else { 188 184 sources = IGNORE_FILE + ";" + sources; 189 } 190 if(Main.pref.getBoolean(PREF_USE_SPELL_FILE, true))191 { 192 if( sources == null || sources.length() == 0) 185 } 186 } 187 if (Main.pref.getBoolean(PREF_USE_SPELL_FILE, true)) { 188 if( sources == null || sources.length() == 0) { 193 189 sources = SPELL_FILE; 194 else190 } else { 195 191 sources = SPELL_FILE + ";" + sources; 192 } 196 193 } 197 194 198 195 String errorSources = ""; 199 if(sources.length() == 0) 196 if (sources.length() == 0) 200 197 return; 201 for(String source: sources.split(";")) 202 { 203 try 204 { 198 for (String source : sources.split(";")) { 199 try { 205 200 MirroredInputStream s = new MirroredInputStream(source, ValUtil.getPluginDir(), -1); 206 201 InputStreamReader r; 207 try 208 { 202 try { 209 203 r = new InputStreamReader(s, "UTF-8"); 210 } 211 catch (UnsupportedEncodingException e) 212 { 204 } catch (UnsupportedEncodingException e) { 213 205 r = new InputStreamReader(s); 214 206 } … … 219 211 boolean ignorefile = false; 220 212 String line; 221 while((line = reader.readLine()) != null && (tagcheckerfile || line.length() != 0)) 222 { 223 if(line.startsWith("#")) 224 { 225 if(line.startsWith("# JOSM TagChecker")) 213 while ((line = reader.readLine()) != null && (tagcheckerfile || line.length() != 0)) { 214 if (line.startsWith("#")) { 215 if (line.startsWith("# JOSM TagChecker")) { 226 216 tagcheckerfile = true; 227 if(line.startsWith("# JOSM IgnoreTags")) 217 } 218 if (line.startsWith("# JOSM IgnoreTags")) { 228 219 ignorefile = true; 220 } 229 221 continue; 230 } 231 else if(ignorefile) 232 { 222 } else if (ignorefile) { 233 223 line = line.trim(); 234 if(line.length() < 4) 224 if (line.length() < 4) { 235 225 continue; 226 } 236 227 237 228 String key = line.substring(0, 2); 238 229 line = line.substring(2); 239 230 240 if(key.equals("S:")) 241 { 231 if (key.equals("S:")) { 242 232 ignoreDataStartsWith.add(line); 243 } 244 else if(key.equals("E:")) 245 { 233 } else if (key.equals("E:")) { 246 234 ignoreDataEquals.add(line); 247 } 248 else if(key.equals("F:")) 249 { 235 } else if (key.equals("F:")) { 250 236 ignoreDataEndsWith.add(line); 251 } 252 else if(key.equals("K:")) 253 { 237 } else if (key.equals("K:")) { 254 238 IgnoreKeyPair tmp = new IgnoreKeyPair(); 255 239 int mid = line.indexOf("="); … … 257 241 tmp.value = line.substring(mid+1); 258 242 ignoreDataKeyPair.add(tmp); 259 } 260 else if(key.equals("T:")) 261 { 243 } else if (key.equals("T:")) { 262 244 IgnoreTwoKeyPair tmp = new IgnoreTwoKeyPair(); 263 245 int mid = line.indexOf("="); … … 272 254 } 273 255 continue; 274 } 275 else if(tagcheckerfile) 276 { 277 if(line.length() > 0) 278 { 256 } else if (tagcheckerfile) { 257 if (line.length() > 0) { 279 258 CheckerData d = new CheckerData(); 280 259 String err = d.getData(line); 281 260 282 if(err == null) 261 if (err == null) { 283 262 checkerData.add(d); 284 else263 } else { 285 264 System.err.println(tr("Invalid tagchecker line - {0}: {1}", err, line)); 286 } 287 } 288 else if(line.charAt(0) == '+') 289 { 265 } 266 } 267 } else if (line.charAt(0) == '+') { 290 268 okValue = line.substring(1); 291 } 292 else if(line.charAt(0) == '-' && okValue != null) 293 { 269 } else if (line.charAt(0) == '-' && okValue != null) { 294 270 spellCheckKeyData.put(line.substring(1), okValue); 295 } 296 else 297 { 271 } else { 298 272 System.err.println(tr("Invalid spellcheck line: {0}", line)); 299 273 } 300 274 } 301 } 302 catch (IOException e) 303 { 275 } catch (IOException e) { 304 276 errorSources += source + "\n"; 305 277 } 306 278 } 307 279 308 if (errorSources.length() > 0280 if (errorSources.length() > 0) 309 281 throw new IOException( tr("Could not access data file(s):\n{0}", errorSources) ); 310 282 } … … 315 287 * @throws Exception 316 288 */ 317 public static void initializePresets() throws Exception 318 { 319 if (!Main.pref.getBoolean(PREF_CHECK_VALUES, true)289 public static void initializePresets() throws Exception { 290 291 if (!Main.pref.getBoolean(PREF_CHECK_VALUES, true)) 320 292 return; 321 293 322 294 Collection<TaggingPreset> presets = TaggingPresetPreference.taggingPresets; 323 if(presets != null) 324 { 295 if (presets != null) { 325 296 presetsValueData = new Bag<String, String>(); 326 for(String a : OsmPrimitive.getUninterestingKeys()) 297 for (String a : OsmPrimitive.getUninterestingKeys()) { 327 298 presetsValueData.add(a); 299 } 328 300 // TODO directionKeys are no longer in OsmPrimitive (search pattern is used instead) 329 301 /* for(String a : OsmPrimitive.getDirectionKeys()) 330 302 presetsValueData.add(a); 331 303 */ 332 for(String a : Main.pref.getCollection(ValidatorPreference.PREFIX + ".knownkeys", 333 Arrays.asList(new String[]{"is_in", "int_ref", "fixme", "population"}))) 304 for (String a : Main.pref.getCollection(ValidatorPreference.PREFIX + ".knownkeys", 305 Arrays.asList(new String[]{"is_in", "int_ref", "fixme", "population"}))) { 334 306 presetsValueData.add(a); 335 for(TaggingPreset p : presets) 336 { 337 for(TaggingPreset.Item i : p.data) 338 { 339 if(i instanceof TaggingPreset.Combo) 340 { 307 } 308 for (TaggingPreset p : presets) { 309 for(TaggingPreset.Item i : p.data) { 310 if (i instanceof TaggingPreset.Combo) { 341 311 TaggingPreset.Combo combo = (TaggingPreset.Combo) i; 342 if(combo.values != null) 343 { 344 for(String value : combo.values.split(",")) 312 if (combo.values != null) { 313 for(String value : combo.values.split(",")) { 345 314 presetsValueData.add(combo.key, value); 346 } 347 } 348 else if(i instanceof TaggingPreset.Key) 349 { 315 } 316 } 317 } else if (i instanceof TaggingPreset.Key) { 350 318 TaggingPreset.Key k = (TaggingPreset.Key) i; 351 319 presetsValueData.add(k.key, k.value); 352 } 353 else if(i instanceof TaggingPreset.Text) 354 { 320 } else if (i instanceof TaggingPreset.Text) { 355 321 TaggingPreset.Text k = (TaggingPreset.Text) i; 356 322 presetsValueData.add(k.key); 357 } 358 else if(i instanceof TaggingPreset.Check) 359 { 323 } else if (i instanceof TaggingPreset.Check) { 360 324 TaggingPreset.Check k = (TaggingPreset.Check) i; 361 325 presetsValueData.add(k.key, "yes"); … … 368 332 369 333 @Override 370 public void visit(Node n) 371 { 334 public void visit(Node n) { 372 335 checkPrimitive(n); 373 336 } 374 337 375 376 338 @Override 377 public void visit(Relation n) 378 { 339 public void visit(Relation n) { 379 340 checkPrimitive(n); 380 341 } 381 342 382 383 343 @Override 384 public void visit(Way w) 385 { 344 public void visit(Way w) { 386 345 checkPrimitive(w); 387 346 } … … 392 351 */ 393 352 private boolean containsLow(String s) { 394 if (s==null) return false; 395 for(int i=0;i<s.length();i++) { 396 if (s.charAt(i)<0x20) return true; 353 if (s == null) 354 return false; 355 for (int i = 0; i < s.length(); i++) { 356 if (s.charAt(i) < 0x20) 357 return true; 397 358 } 398 359 return false; … … 403 364 * @param p The primitive to check 404 365 */ 405 private void checkPrimitive(OsmPrimitive p) 406 { 366 private void checkPrimitive(OsmPrimitive p) { 407 367 // Just a collection to know if a primitive has been already marked with error 408 368 Bag<OsmPrimitive, String> withErrors = new Bag<OsmPrimitive, String>(); 409 369 410 if(checkComplex) 411 { 370 if (checkComplex) { 412 371 Map<String, String> props = (p.getKeys() == null) ? Collections.<String, String>emptyMap() : p.getKeys(); 413 for(Entry<String, String> prop: props.entrySet() ) 414 { 372 for (Entry<String, String> prop : props.entrySet()) { 415 373 boolean ignore = true; 416 374 String key1 = prop.getKey(); 417 375 String value1 = prop.getValue(); 418 376 419 for(IgnoreTwoKeyPair a : ignoreDataTwoKeyPair) 420 { 421 if(key1.equals(a.key1) && value1.equals(a.value1)) 422 { 377 for (IgnoreTwoKeyPair a : ignoreDataTwoKeyPair) { 378 if (key1.equals(a.key1) && value1.equals(a.value1)) { 423 379 ignore = false; 424 for(Entry<String, String> prop2: props.entrySet() ) 425 { 380 for (Entry<String, String> prop2 : props.entrySet()) { 426 381 String key2 = prop2.getKey(); 427 382 String value2 = prop2.getValue(); 428 for(IgnoreTwoKeyPair b : ignoreDataTwoKeyPair) 429 { 430 if(key2.equals(b.key2) && value2.equals(b.value2)) 431 { 383 for (IgnoreTwoKeyPair b : ignoreDataTwoKeyPair) { 384 if (key2.equals(b.key2) && value2.equals(b.value2)) { 432 385 ignore = true; 433 386 break; 434 387 } 435 388 } 436 if (ignore)389 if (ignore) { 437 390 break; 438 } 439 } 440 if(ignore) 391 } 392 } 393 } 394 if (ignore) { 441 395 break; 442 } 443 444 if(!ignore) 445 { 396 } 397 } 398 399 if (!ignore) { 446 400 errors.add( new TestError(this, Severity.ERROR, tr("Illegal tag/value combinations"), 447 401 tr("Illegal tag/value combinations"), tr("Illegal tag/value combinations"), 1272, p) ); … … 451 405 452 406 Map<String, String> keys = p.getKeys(); 453 for(CheckerData d : checkerData) 454 { 455 if(d.match(p, keys)) 456 { 407 for (CheckerData d : checkerData) { 408 if (d.match(p, keys)) { 457 409 errors.add( new TestError(this, d.getSeverity(), tr("Illegal tag/value combinations"), 458 410 d.getDescription(), d.getDescriptionOrig(), d.getCode(), p) ); … … 463 415 464 416 Map<String, String> props = (p.getKeys() == null) ? Collections.<String, String>emptyMap() : p.getKeys(); 465 for(Entry<String, String> prop: props.entrySet() ) 466 { 417 for (Entry<String, String> prop : props.entrySet()) { 467 418 String s = marktr("Key ''{0}'' invalid."); 468 419 String key = prop.getKey(); 469 420 String value = prop.getValue(); 470 if( checkValues && (containsLow(value)) && !withErrors.contains(p, "ICV")) 471 { 421 if (checkValues && (containsLow(value)) && !withErrors.contains(p, "ICV")) { 472 422 errors.add( new TestError(this, Severity.WARNING, tr("Tag value contains character with code less than 0x20"), 473 423 tr(s, key), MessageFormat.format(s, key), LOW_CHAR_VALUE, p) ); 474 424 withErrors.add(p, "ICV"); 475 425 } 476 if( checkKeys && (containsLow(key)) && !withErrors.contains(p, "ICK")) 477 { 426 if (checkKeys && (containsLow(key)) && !withErrors.contains(p, "ICK")) { 478 427 errors.add( new TestError(this, Severity.WARNING, tr("Tag key contains character with code less than 0x20"), 479 428 tr(s, key), MessageFormat.format(s, key), LOW_CHAR_KEY, p) ); 480 429 withErrors.add(p, "ICK"); 481 430 } 482 if( checkValues && (value!=null && value.length() > 255) && !withErrors.contains(p, "LV")) 483 { 431 if (checkValues && (value!=null && value.length() > 255) && !withErrors.contains(p, "LV")) { 484 432 errors.add( new TestError(this, Severity.ERROR, tr("Tag value longer than allowed"), 485 433 tr(s, key), MessageFormat.format(s, key), LONG_VALUE, p) ); 486 434 withErrors.add(p, "LV"); 487 435 } 488 if( checkKeys && (key!=null && key.length() > 255) && !withErrors.contains(p, "LK")) 489 { 436 if (checkKeys && (key!=null && key.length() > 255) && !withErrors.contains(p, "LK")) { 490 437 errors.add( new TestError(this, Severity.ERROR, tr("Tag key longer than allowed"), 491 438 tr(s, key), MessageFormat.format(s, key), LONG_KEY, p) ); 492 439 withErrors.add(p, "LK"); 493 440 } 494 if( checkValues && (value==null || value.trim().length() == 0) && !withErrors.contains(p, "EV")) 495 { 441 if (checkValues && (value==null || value.trim().length() == 0) && !withErrors.contains(p, "EV")) { 496 442 errors.add( new TestError(this, Severity.WARNING, tr("Tags with empty values"), 497 443 tr(s, key), MessageFormat.format(s, key), EMPTY_VALUES, p) ); 498 444 withErrors.add(p, "EV"); 499 445 } 500 if( checkKeys && spellCheckKeyData.containsKey(key) && !withErrors.contains(p, "IPK")) 501 { 446 if (checkKeys && spellCheckKeyData.containsKey(key) && !withErrors.contains(p, "IPK")) { 502 447 errors.add( new TestError(this, Severity.WARNING, tr("Invalid property key"), 503 448 tr(s, key), MessageFormat.format(s, key), INVALID_KEY, p) ); 504 449 withErrors.add(p, "IPK"); 505 450 } 506 if( checkKeys && key.indexOf(" ") >= 0 && !withErrors.contains(p, "IPK")) 507 { 451 if (checkKeys && key.indexOf(" ") >= 0 && !withErrors.contains(p, "IPK")) { 508 452 errors.add( new TestError(this, Severity.WARNING, tr("Invalid white space in property key"), 509 453 tr(s, key), MessageFormat.format(s, key), INVALID_KEY_SPACE, p) ); 510 454 withErrors.add(p, "IPK"); 511 455 } 512 if( checkValues && value != null && (value.startsWith(" ") || value.endsWith(" ")) && !withErrors.contains(p, "SPACE")) 513 { 456 if (checkValues && value != null && (value.startsWith(" ") || value.endsWith(" ")) && !withErrors.contains(p, "SPACE")) { 514 457 errors.add( new TestError(this, Severity.OTHER, tr("Property values start or end with white space"), 515 458 tr(s, key), MessageFormat.format(s, key), INVALID_SPACE, p) ); 516 459 withErrors.add(p, "SPACE"); 517 460 } 518 if( checkValues && value != null && !value.equals(entities.unescape(value)) && !withErrors.contains(p, "HTML")) 519 { 461 if (checkValues && value != null && !value.equals(entities.unescape(value)) && !withErrors.contains(p, "HTML")) { 520 462 errors.add( new TestError(this, Severity.OTHER, tr("Property values contain HTML entity"), 521 463 tr(s, key), MessageFormat.format(s, key), INVALID_HTML, p) ); 522 464 withErrors.add(p, "HTML"); 523 465 } 524 if( checkValues && value != null && value.length() > 0 && presetsValueData != null) 525 { 466 if (checkValues && value != null && value.length() > 0 && presetsValueData != null) { 526 467 List<String> values = presetsValueData.get(key); 527 if(values == null) 528 { 468 if (values == null) { 529 469 boolean ignore = false; 530 for(String a : ignoreDataStartsWith) 531 { 532 if(key.startsWith(a)) 470 for (String a : ignoreDataStartsWith) { 471 if (key.startsWith(a)) { 533 472 ignore = true; 534 } 535 for(String a : ignoreDataEquals)536 { 537 if(key.equals(a)) 473 } 474 } 475 for (String a : ignoreDataEquals) { 476 if(key.equals(a)) { 538 477 ignore = true; 539 } 540 for(String a : ignoreDataEndsWith)541 { 542 if(key.endsWith(a)) 478 } 479 } 480 for (String a : ignoreDataEndsWith) { 481 if(key.endsWith(a)) { 543 482 ignore = true; 544 } 545 if(!ignore)546 { 483 } 484 } 485 if (!ignore) { 547 486 String i = marktr("Key ''{0}'' not in presets."); 548 487 errors.add( new TestError(this, Severity.OTHER, tr("Presets do not contain property key"), … … 550 489 withErrors.add(p, "UPK"); 551 490 } 552 } 553 else if(values.size() > 0 && !values.contains(prop.getValue())) 554 { 491 } else if (values.size() > 0 && !values.contains(prop.getValue())) { 555 492 boolean ignore = false; 556 for(IgnoreKeyPair a : ignoreDataKeyPair) 557 { 558 if(key.equals(a.key) && value.equals(a.value)) 493 for (IgnoreKeyPair a : ignoreDataKeyPair) { 494 if (key.equals(a.key) && value.equals(a.value)) { 559 495 ignore = true; 560 } 561 562 for(IgnoreTwoKeyPair a : ignoreDataTwoKeyPair) 563 { 564 if(key.equals(a.key2) && value.equals(a.value2)) 496 } 497 } 498 499 for (IgnoreTwoKeyPair a : ignoreDataTwoKeyPair) { 500 if (key.equals(a.key2) && value.equals(a.value2)) { 565 501 ignore = true; 566 } 567 568 if(!ignore) 569 { 502 } 503 } 504 505 if (!ignore) { 570 506 String i = marktr("Value ''{0}'' for key ''{1}'' not in presets."); 571 507 errors.add( new TestError(this, Severity.OTHER, tr("Presets do not contain property value"), … … 589 525 590 526 @Override 591 public void startTest(ProgressMonitor monitor) 592 { 527 public void startTest(ProgressMonitor monitor) { 593 528 super.startTest(monitor); 594 529 checkKeys = Main.pref.getBoolean(PREF_CHECK_KEYS, true); 595 if (isBeforeUpload)530 if (isBeforeUpload) { 596 531 checkKeys = checkKeys && Main.pref.getBoolean(PREF_CHECK_KEYS_BEFORE_UPLOAD, true); 532 } 597 533 598 534 checkValues = Main.pref.getBoolean(PREF_CHECK_VALUES, true); 599 if (isBeforeUpload)535 if (isBeforeUpload) { 600 536 checkValues = checkValues && Main.pref.getBoolean(PREF_CHECK_VALUES_BEFORE_UPLOAD, true); 537 } 601 538 602 539 checkComplex = Main.pref.getBoolean(PREF_CHECK_COMPLEX, true); 603 if (isBeforeUpload)540 if (isBeforeUpload) { 604 541 checkComplex = checkValues && Main.pref.getBoolean(PREF_CHECK_COMPLEX_BEFORE_UPLOAD, true); 542 } 605 543 606 544 checkFixmes = Main.pref.getBoolean(PREF_CHECK_FIXMES, true); 607 if (isBeforeUpload)545 if (isBeforeUpload) { 608 546 checkFixmes = checkFixmes && Main.pref.getBoolean(PREF_CHECK_FIXMES_BEFORE_UPLOAD, true); 547 } 609 548 } 610 549 611 550 @Override 612 public void visit(Collection<OsmPrimitive> selection) 613 { 614 if( checkKeys || checkValues || checkComplex || checkFixmes) 551 public void visit(Collection<OsmPrimitive> selection) { 552 if (checkKeys || checkValues || checkComplex || checkFixmes) { 615 553 super.visit(selection); 554 } 616 555 } 617 556 618 557 @Override 619 public void addGui(JPanel testPanel) 620 { 558 public void addGui(JPanel testPanel) { 621 559 GBC a = GBC.eol(); 622 560 a.anchor = GridBagConstraints.EAST; 623 561 624 testPanel.add( 562 testPanel.add(new JLabel(name), GBC.eol().insets(3,0,0,0)); 625 563 626 564 prefCheckKeys = new JCheckBox(tr("Check property keys."), Main.pref.getBoolean(PREF_CHECK_KEYS, true)); … … 640 578 testPanel.add(prefCheckComplexBeforeUpload, a); 641 579 642 Sources= new JList(new DefaultListModel());580 sourcesList = new JList(new DefaultListModel()); 643 581 644 582 String sources = Main.pref.get( PREF_SOURCES ); 645 if(sources != null && sources.length() > 0) 646 { 647 for(String source :sources.split(";"))648 ((DefaultListModel)Sources.getModel()).addElement(source);583 if (sources != null && sources.length() > 0) { 584 for (String source : sources.split(";")) { 585 ((DefaultListModel)sourcesList.getModel()).addElement(source); 586 } 649 587 } 650 588 651 589 addSrcButton = new JButton(tr("Add")); 652 addSrcButton.addActionListener(new ActionListener(){ 590 addSrcButton.addActionListener(new ActionListener() { 591 @Override 653 592 public void actionPerformed(ActionEvent e) { 654 593 String source = JOptionPane.showInputDialog( … … 656 595 tr("TagChecker source"), 657 596 tr("TagChecker source"), 658 JOptionPane.QUESTION_MESSAGE 659 );660 if(source!= null)661 ((DefaultListModel)Sources.getModel()).addElement(source);662 Sources.clearSelection();597 JOptionPane.QUESTION_MESSAGE); 598 if (source != null) { 599 ((DefaultListModel)sourcesList.getModel()).addElement(source); 600 } 601 sourcesList.clearSelection(); 663 602 } 664 603 }); 665 604 666 605 editSrcButton = new JButton(tr("Edit")); 667 editSrcButton.addActionListener(new ActionListener(){ 606 editSrcButton.addActionListener(new ActionListener() { 607 @Override 668 608 public void actionPerformed(ActionEvent e) { 669 int row = Sources.getSelectedIndex(); 670 if(row == -1 && Sources.getModel().getSize() == 1) 671 { 672 Sources.setSelectedIndex(0); 609 int row = sourcesList.getSelectedIndex(); 610 if (row == -1 && sourcesList.getModel().getSize() == 1) { 611 sourcesList.setSelectedIndex(0); 673 612 row = 0; 674 613 } 675 if (row == -1) 676 { 677 if(Sources.getModel().getSize() == 0) 678 { 614 if (row == -1) { 615 if (sourcesList.getModel().getSize() == 0) { 679 616 String source = JOptionPane.showInputDialog(Main.parent, tr("TagChecker source"), tr("TagChecker source"), JOptionPane.QUESTION_MESSAGE); 680 if (source != null) 681 ((DefaultListModel)Sources.getModel()).addElement(source); 682 } 683 else 684 { 617 if (source != null) { 618 ((DefaultListModel)sourcesList.getModel()).addElement(source); 619 } 620 } else { 685 621 JOptionPane.showMessageDialog( 686 622 Main.parent, … … 690 626 ); 691 627 } 692 } 693 else { 628 } else { 694 629 String source = (String)JOptionPane.showInputDialog(Main.parent, 695 630 tr("TagChecker source"), 696 631 tr("TagChecker source"), 697 632 JOptionPane.QUESTION_MESSAGE, null, null, 698 Sources.getSelectedValue()); 699 if (source != null) 700 ((DefaultListModel)Sources.getModel()).setElementAt(source, row); 701 } 702 Sources.clearSelection(); 633 sourcesList.getSelectedValue()); 634 if (source != null) { 635 ((DefaultListModel)sourcesList.getModel()).setElementAt(source, row); 636 } 637 } 638 sourcesList.clearSelection(); 703 639 } 704 640 }); 705 641 706 642 deleteSrcButton = new JButton(tr("Delete")); 707 deleteSrcButton.addActionListener(new ActionListener(){ 643 deleteSrcButton.addActionListener(new ActionListener() { 644 @Override 708 645 public void actionPerformed(ActionEvent e) { 709 if ( Sources.getSelectedIndex() == -1)646 if (sourcesList.getSelectedIndex() == -1) { 710 647 JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to delete."), tr("Information"), JOptionPane.QUESTION_MESSAGE); 711 else { 712 ((DefaultListModel) Sources.getModel()).remove(Sources.getSelectedIndex());648 } else { 649 ((DefaultListModel)sourcesList.getModel()).remove(sourcesList.getSelectedIndex()); 713 650 } 714 651 } 715 652 }); 716 Sources.setMinimumSize(new Dimension(300,50));717 Sources.setVisibleRowCount(3);718 719 Sources.setToolTipText(tr("The sources (URL or filename) of spell check (see http://wiki.openstreetmap.org/index.php/User:JLS/speller) or tag checking data files."));653 sourcesList.setMinimumSize(new Dimension(300,50)); 654 sourcesList.setVisibleRowCount(3); 655 656 sourcesList.setToolTipText(tr("The sources (URL or filename) of spell check (see http://wiki.openstreetmap.org/index.php/User:JLS/speller) or tag checking data files.")); 720 657 addSrcButton.setToolTipText(tr("Add a new source to the list.")); 721 658 editSrcButton.setToolTipText(tr("Edit the selected source.")); … … 723 660 724 661 testPanel.add(new JLabel(tr("Data sources")), GBC.eol().insets(23,0,0,0)); 725 testPanel.add(new JScrollPane( Sources), GBC.eol().insets(23,0,0,0).fill(GridBagConstraints.HORIZONTAL));662 testPanel.add(new JScrollPane(sourcesList), GBC.eol().insets(23,0,0,0).fill(GridBagConstraints.HORIZONTAL)); 726 663 final JPanel buttonPanel = new JPanel(new GridBagLayout()); 727 664 testPanel.add(buttonPanel, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); … … 730 667 buttonPanel.add(deleteSrcButton, GBC.std().insets(0,5,0,0)); 731 668 732 ActionListener disableCheckActionListener = new ActionListener(){ 669 ActionListener disableCheckActionListener = new ActionListener() { 670 @Override 733 671 public void actionPerformed(ActionEvent e) { 734 672 handlePrefEnable(); … … 771 709 } 772 710 773 public void handlePrefEnable() 774 { 711 public void handlePrefEnable() { 775 712 boolean selected = prefCheckKeys.isSelected() || prefCheckKeysBeforeUpload.isSelected() 776 || prefCheckComplex.isSelected() || prefCheckComplexBeforeUpload.isSelected(); 777 Sources.setEnabled( selected );713 || prefCheckComplex.isSelected() || prefCheckComplexBeforeUpload.isSelected(); 714 sourcesList.setEnabled( selected ); 778 715 addSrcButton.setEnabled(selected); 779 716 editSrcButton.setEnabled(selected); … … 786 723 enabled = prefCheckKeys.isSelected() || prefCheckValues.isSelected() || prefCheckComplex.isSelected() || prefCheckFixmes.isSelected(); 787 724 testBeforeUpload = prefCheckKeysBeforeUpload.isSelected() || prefCheckValuesBeforeUpload.isSelected() 788 || prefCheckFixmesBeforeUpload.isSelected() || prefCheckComplexBeforeUpload.isSelected(); 725 || prefCheckFixmesBeforeUpload.isSelected() || prefCheckComplexBeforeUpload.isSelected(); 789 726 790 727 Main.pref.put(PREF_CHECK_VALUES, prefCheckValues.isSelected()); … … 800 737 Main.pref.put(PREF_USE_SPELL_FILE, prefUseSpellFile.isSelected()); 801 738 String sources = ""; 802 if( Sources.getModel().getSize() > 0 ) 803 { 739 if (sourcesList.getModel().getSize() > 0) { 804 740 String sb = ""; 805 for (int i = 0; i < Sources.getModel().getSize(); ++i) 806 sb += ";"+Sources.getModel().getElementAt(i); 741 for (int i = 0; i < sourcesList.getModel().getSize(); ++i) { 742 sb += ";"+sourcesList.getModel().getElementAt(i); 743 } 807 744 sources = sb.substring(1); 808 745 } 809 if(sources.length() == 0) 746 if (sources.length() == 0) { 810 747 sources = null; 748 } 811 749 return Main.pref.put(PREF_SOURCES, sources); 812 750 } 813 751 814 752 @Override 815 public Command fixError(TestError testError) 816 { 753 public Command fixError(TestError testError) { 754 817 755 List<Command> commands = new ArrayList<Command>(50); 818 756 819 757 int i = -1; 820 758 List<? extends OsmPrimitive> primitives = testError.getPrimitives(); 821 for(OsmPrimitive p : primitives ) 822 { 759 for (OsmPrimitive p : primitives) { 823 760 i++; 824 761 Map<String, String> tags = p.getKeys(); 825 if (tags == null || tags.size() == 0 )762 if (tags == null || tags.isEmpty()) { 826 763 continue; 827 828 for(Entry<String, String> prop: tags.entrySet() ) 829 { 764 } 765 766 for (Entry<String, String> prop: tags.entrySet()) { 830 767 String key = prop.getKey(); 831 768 String value = prop.getValue(); 832 if( value == null || value.trim().length() == 0 ) 833 commands.add( new ChangePropertyCommand(Collections.singleton(primitives.get(i)), key, null) ); 834 else if(value.startsWith(" ") || value.endsWith(" ")) 835 commands.add( new ChangePropertyCommand(Collections.singleton(primitives.get(i)), key, value.trim()) ); 836 else if(key.startsWith(" ") || key.endsWith(" ")) 837 commands.add( new ChangePropertyKeyCommand(Collections.singleton(primitives.get(i)), key, key.trim()) ); 838 else 839 { 769 if (value == null || value.trim().length() == 0) { 770 commands.add(new ChangePropertyCommand(Collections.singleton(primitives.get(i)), key, null)); 771 } else if (value.startsWith(" ") || value.endsWith(" ")) { 772 commands.add(new ChangePropertyCommand(Collections.singleton(primitives.get(i)), key, value.trim())); 773 } else if (key.startsWith(" ") || key.endsWith(" ")) { 774 commands.add(new ChangePropertyKeyCommand(Collections.singleton(primitives.get(i)), key, key.trim())); 775 } else { 840 776 String evalue = entities.unescape(value); 841 if(!evalue.equals(value)) 842 commands.add( new ChangePropertyCommand(Collections.singleton(primitives.get(i)), key, evalue) ); 843 else 844 { 777 if (!evalue.equals(value)) { 778 commands.add(new ChangePropertyCommand(Collections.singleton(primitives.get(i)), key, evalue)); 779 } else { 845 780 String replacementKey = spellCheckKeyData.get(key); 846 if( replacementKey != null ) 847 { 848 commands.add( new ChangePropertyKeyCommand(Collections.singleton(primitives.get(i)), 849 key, replacementKey) ); 850 } 851 } 852 } 853 } 854 } 855 856 if( commands.size() == 0 ) 781 if (replacementKey != null) { 782 commands.add(new ChangePropertyKeyCommand(Collections.singleton(primitives.get(i)), 783 key, replacementKey)); 784 } 785 } 786 } 787 } 788 } 789 790 if (commands.isEmpty()) 857 791 return null; 858 else if(commands.size() == 1792 if (commands.size() == 1) 859 793 return commands.get(0); 860 else861 794 795 return new SequenceCommand(tr("Fix properties"), commands); 862 796 } 863 797 864 798 @Override 865 public boolean isFixable(TestError testError) 866 { 867 if( testError.getTester() instanceof TagChecker) 868 { 799 public boolean isFixable(TestError testError) { 800 801 if (testError.getTester() instanceof TagChecker) { 869 802 int code = testError.getCode(); 870 803 return code == INVALID_KEY || code == EMPTY_VALUES || code == INVALID_SPACE || code == INVALID_KEY_SPACE || code == INVALID_HTML; … … 903 836 public boolean valueAll = false; 904 837 public boolean valueBool = false; 905 private Pattern getPattern(String str) throws IllegalStateException, PatternSyntaxException 906 { 907 if(str.endsWith("/i")) 838 private Pattern getPattern(String str) throws IllegalStateException, PatternSyntaxException { 839 if (str.endsWith("/i")) 908 840 return Pattern.compile(str.substring(1,str.length()-2), Pattern.CASE_INSENSITIVE); 909 else if(str.endsWith("/"))841 if (str.endsWith("/")) 910 842 return Pattern.compile(str.substring(1,str.length()-1)); 843 911 844 throw new IllegalStateException(); 912 845 } 913 public CheckerElement(String exp) throws IllegalStateException, PatternSyntaxException 914 { 846 public CheckerElement(String exp) throws IllegalStateException, PatternSyntaxException { 915 847 Matcher m = Pattern.compile("(.+)([!=]=)(.+)").matcher(exp); 916 848 m.matches(); 917 849 918 850 String n = m.group(1).trim(); 851 852 // FIXME FIXME: indentation and { } pairs don't match, probably coding error 853 919 854 if(n.equals("*")) 920 855 tagAll = true; … … 938 873 value = n.startsWith("/") ? getPattern(n) : n; 939 874 } 875 940 876 public boolean match(OsmPrimitive osm, Map<String, String> keys) { 941 for(Entry<String, String> prop: keys.entrySet()) { 877 for (Entry<String, String> prop: keys.entrySet()) { 942 878 String key = prop.getKey(); 943 879 String val = valueBool ? OsmUtils.getNamedOsmBoolean(prop.getValue()) : prop.getValue(); 944 if((tagAll || (tag instanceof Pattern ? ((Pattern)tag).matcher(key).matches() : key.equals(tag))) 945 && (valueAll || (value instanceof Pattern ? ((Pattern)value).matcher(val).matches() : val.equals(value)))) 880 if ((tagAll || (tag instanceof Pattern ? ((Pattern) tag).matcher(key).matches() : key.equals(tag))) 881 && (valueAll || (value instanceof Pattern ? ((Pattern) value).matcher(val).matches() : val.equals(value)))) 946 882 return !noMatch; 947 883 } … … 950 886 }; 951 887 952 public String getData(String str) 953 { 888 public String getData(String str) { 954 889 Matcher m = Pattern.compile(" *# *([^#]+) *$").matcher(str); 955 890 str = m.replaceFirst("").trim(); 956 try 957 { 891 try { 958 892 description = m.group(1); 959 if(description != null && description.length() == 0) 893 if (description != null && description.length() == 0) { 960 894 description = null; 961 } 962 catch (IllegalStateException e) 963 { 895 } 896 } catch (IllegalStateException e) { 964 897 description = null; 965 898 } 966 899 String[] n = str.split(" *: *", 3); 967 if(n[0].equals("way")) 900 if (n[0].equals("way")) { 968 901 type = OsmPrimitiveType.WAY; 969 else if(n[0].equals("node"))902 } else if (n[0].equals("node")) { 970 903 type = OsmPrimitiveType.NODE; 971 else if(n[0].equals("relation"))904 } else if (n[0].equals("relation")) { 972 905 type = OsmPrimitiveType.RELATION; 973 else if(n[0].equals("*"))906 } else if (n[0].equals("*")) { 974 907 type = null; 975 else 908 } else 976 909 return tr("Could not find element type"); 977 910 if (n.length != 3) 978 911 return tr("Incorrect number of parameters"); 979 912 980 if(n[1].equals("W")) 981 { 913 if (n[1].equals("W")) { 982 914 severity = Severity.WARNING; 983 915 code = TAG_CHECK_WARN; 984 } 985 else if(n[1].equals("E")) 986 { 916 } else if (n[1].equals("E")) { 987 917 severity = Severity.ERROR; 988 918 code = TAG_CHECK_ERROR; 989 } 990 else if(n[1].equals("I")) 991 { 919 } else if(n[1].equals("I")) { 992 920 severity = Severity.OTHER; 993 921 code = TAG_CHECK_INFO; 994 } 995 else 922 } else 996 923 return tr("Could not find warning level"); 997 for(String exp: n[2].split(" *&& *")) 998 { 999 try 1000 { 924 for (String exp: n[2].split(" *&& *")) { 925 try { 1001 926 data.add(new CheckerElement(exp)); 1002 } 1003 catch(IllegalStateException e) 1004 { 927 } catch (IllegalStateException e) { 1005 928 return tr("Illegal expression ''{0}''", exp); 1006 929 } 1007 catch(PatternSyntaxException e) 1008 { 930 catch (PatternSyntaxException e) { 1009 931 return tr("Illegal regular expression ''{0}''", exp); 1010 932 } … … 1012 934 return null; 1013 935 } 1014 public boolean match(OsmPrimitive osm, Map<String, String> keys) 1015 { 936 937 public boolean match(OsmPrimitive osm, Map<String, String> keys) { 1016 938 if (type != null && OsmPrimitiveType.from(osm) != type) 1017 939 return false; 1018 940 1019 for(CheckerElement ce : data) { 1020 if(!ce.match(osm, keys)) 941 for (CheckerElement ce : data) { 942 if (!ce.match(osm, keys)) 1021 943 return false; 1022 944 } 1023 945 return true; 1024 946 } 1025 public String getDescription() 1026 { 947 948 public String getDescription() { 1027 949 return tr(description); 1028 950 } 1029 public String getDescriptionOrig() 1030 { 951 952 public String getDescriptionOrig() { 1031 953 return description; 1032 954 } 1033 public Severity getSeverity() 1034 { 955 956 public Severity getSeverity() { 1035 957 return severity; 1036 958 } 1037 959 1038 960 public int getCode() { 1039 if (type == null) {961 if (type == null) 1040 962 return code; 1041 } else { 1042 return code + type.ordinal() + 1; 1043 } 963 964 return code + type.ordinal() + 1; 1044 965 } 1045 966 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/TurnrestrictionTest.java
r3669 r3671 33 33 34 34 public TurnrestrictionTest() { 35 super(tr("Turnrestriction"), 36 tr("This test checks if turnrestrictions are valid")); 35 super(tr("Turnrestriction"), tr("This test checks if turnrestrictions are valid")); 37 36 } 38 37 … … 51 50 52 51 /* find the "from", "via" and "to" elements */ 53 for (RelationMember m : r.getMembers()) 54 { 55 if(m.getMember().isIncomplete()) 52 for (RelationMember m : r.getMembers()) { 53 if (m.getMember().isIncomplete()) 56 54 return; 57 else 58 { 59 ArrayList<OsmPrimitive> l = new ArrayList<OsmPrimitive>(); 60 l.add(r); 61 l.add(m.getMember()); 62 if(m.isWay()) 63 { 64 Way w = m.getWay(); 65 if(w.getNodesCount() < 2) { 66 continue; 55 56 ArrayList<OsmPrimitive> l = new ArrayList<OsmPrimitive>(); 57 l.add(r); 58 l.add(m.getMember()); 59 if (m.isWay()) { 60 Way w = m.getWay(); 61 if (w.getNodesCount() < 2) { 62 continue; 63 } 64 65 if ("from".equals(m.getRole())) { 66 if (fromWay != null) { 67 morefrom = true; 68 } else { 69 fromWay = w; 67 70 } 68 69 if("from".equals(m.getRole())) { 70 if(fromWay != null) { 71 morefrom = true; 72 } else { 73 fromWay = w; 74 } 75 } else if("to".equals(m.getRole())) { 76 if(toWay != null) { 77 moreto = true; 78 } else { 79 toWay = w; 80 } 81 } else if("via".equals(m.getRole())) { 82 if(via != null) { 83 morevia = true; 84 } else { 85 via = w; 86 } 71 } else if ("to".equals(m.getRole())) { 72 if (toWay != null) { 73 moreto = true; 87 74 } else { 88 errors.add(new TestError(this, Severity.WARNING, tr("Unknown role"), UNKNOWN_ROLE, 89 l, Collections.singletonList(m))); 75 toWay = w; 90 76 } 91 } 92 else if(m.isNode()) 93 { 94 Node n = m.getNode(); 95 if("via".equals(m.getRole())) 96 { 97 if(via != null) { 98 morevia = true; 99 } else { 100 via = n; 101 } 77 } else if ("via".equals(m.getRole())) { 78 if (via != null) { 79 morevia = true; 102 80 } else { 103 errors.add(new TestError(this, Severity.WARNING, tr("Unknown role"), UNKNOWN_ROLE, 104 l, Collections.singletonList(m))); 81 via = w; 105 82 } 106 83 } else { 107 errors.add(new TestError(this, Severity.WARNING, tr("Unknown member type"), UNKNOWN_TYPE,108 l, Collections.singletonList(m))); 84 errors.add(new TestError(this, Severity.WARNING, tr("Unknown role"), UNKNOWN_ROLE, 85 l, Collections.singletonList(m))); 109 86 } 87 } else if (m.isNode()) { 88 Node n = m.getNode(); 89 if ("via".equals(m.getRole())) { 90 if (via != null) { 91 morevia = true; 92 } else { 93 via = n; 94 } 95 } else { 96 errors.add(new TestError(this, Severity.WARNING, tr("Unknown role"), UNKNOWN_ROLE, 97 l, Collections.singletonList(m))); 98 } 99 } else { 100 errors.add(new TestError(this, Severity.WARNING, tr("Unknown member type"), UNKNOWN_TYPE, 101 l, Collections.singletonList(m))); 110 102 } 111 103 } 112 if(morefrom) 104 if (morefrom) { 113 105 errors.add(new TestError(this, Severity.ERROR, tr("More than one \"from\" way found"), MORE_FROM, r)); 114 if(moreto) 106 } 107 if (moreto) { 115 108 errors.add(new TestError(this, Severity.ERROR, tr("More than one \"to\" way found"), MORE_TO, r)); 116 if(morevia) 109 } 110 if (morevia) { 117 111 errors.add(new TestError(this, Severity.ERROR, tr("More than one \"via\" way found"), MORE_VIA, r)); 112 } 118 113 119 114 if (fromWay == null) { … … 131 126 132 127 Node viaNode; 133 if(via instanceof Node) 134 { 128 if (via instanceof Node) { 135 129 viaNode = (Node) via; 136 if(!fromWay.isFirstLastNode(viaNode)) { 130 if (!fromWay.isFirstLastNode(viaNode)) { 137 131 errors.add(new TestError(this, Severity.ERROR, 138 tr("The \"from\" way does not start or end at a \"via\" node"), FROM_VIA_NODE, r)); 132 tr("The \"from\" way does not start or end at a \"via\" node"), FROM_VIA_NODE, r)); 139 133 return; 140 134 } 141 if(!toWay.isFirstLastNode(viaNode)) { 135 if (!toWay.isFirstLastNode(viaNode)) { 142 136 errors.add(new TestError(this, Severity.ERROR, 143 tr("The \"to\" way does not start or end at a \"via\" node"), TO_VIA_NODE, r)); 137 tr("The \"to\" way does not start or end at a \"via\" node"), TO_VIA_NODE, r)); 138 //FIXME: return; ? 144 139 } 145 } 146 else 147 { 140 } else { 148 141 Way viaWay = (Way) via; 149 142 Node firstNode = viaWay.firstNode(); … … 152 145 153 146 String onewayviastr = viaWay.get("oneway"); 154 if(onewayviastr != null) 155 { 156 if("-1".equals(onewayviastr)) { 147 if (onewayviastr != null) { 148 if ("-1".equals(onewayviastr)) { 157 149 onewayvia = true; 158 150 Node tmp = firstNode; … … 167 159 } 168 160 169 if(fromWay.isFirstLastNode(firstNode)) 161 if (fromWay.isFirstLastNode(firstNode)) { 170 162 viaNode = firstNode; 171 else if(!onewayvia && fromWay.isFirstLastNode(lastNode))163 } else if (!onewayvia && fromWay.isFirstLastNode(lastNode)) { 172 164 viaNode = lastNode; 173 else 174 { 165 } else { 175 166 errors.add(new TestError(this, Severity.ERROR, 176 tr("The \"from\" way does not start or end at a \"via\" way."), FROM_VIA_WAY, r)); 167 tr("The \"from\" way does not start or end at a \"via\" way."), FROM_VIA_WAY, r)); 177 168 return; 178 169 } 179 if(!toWay.isFirstLastNode(viaNode == firstNode ? lastNode : firstNode)) { 170 if (!toWay.isFirstLastNode(viaNode == firstNode ? lastNode : firstNode)) { 180 171 errors.add(new TestError(this, Severity.ERROR, 181 tr("The \"to\" way does not start or end at a \"via\" way."), TO_VIA_WAY, r)); 172 tr("The \"to\" way does not start or end at a \"via\" way."), TO_VIA_WAY, r)); 182 173 } 183 174 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/UnclosedWays.java
r3669 r3671 27 27 public class UnclosedWays extends Test { 28 28 /** The already detected errors */ 29 Bag<Way, Way> _errorWays;29 protected Bag<Way, Way> errorWays; 30 30 31 31 /** … … 39 39 public void startTest(ProgressMonitor monitor) { 40 40 super.startTest(monitor); 41 _errorWays = new Bag<Way, Way>();41 errorWays = new Bag<Way, Way>(); 42 42 } 43 43 44 44 @Override 45 45 public void endTest() { 46 _errorWays = null;46 errorWays = null; 47 47 super.endTest(); 48 48 } … … 74 74 75 75 test = w.get("natural"); 76 if (test != null && !"coastline".equals(test) && !"cliff".equals(test)) 76 if (test != null && !"coastline".equals(test) && !"cliff".equals(test)) { 77 77 set(1101, marktr("natural type {0}"), test); 78 } 78 79 test = w.get("landuse"); 79 if (test != null) 80 if (test != null) { 80 81 set(1102, marktr("landuse type {0}"), test); 82 } 81 83 test = w.get("amenities"); 82 if (test != null) 84 if (test != null) { 83 85 set(1103, marktr("amenities type {0}"), test); 86 } 84 87 test = w.get("sport"); 85 if (test != null && !test.equals("water_slide")) 88 if (test != null && !test.equals("water_slide")) { 86 89 set(1104, marktr("sport type {0}"), test); 90 } 87 91 test = w.get("tourism"); 88 if (test != null) 92 if (test != null) { 89 93 set(1105, marktr("tourism type {0}"), test); 94 } 90 95 test = w.get("shop"); 91 if (test != null) 96 if (test != null) { 92 97 set(1106, marktr("shop type {0}"), test); 98 } 93 99 test = w.get("leisure"); 94 if (test != null) 100 if (test != null) { 95 101 set(1107, marktr("leisure type {0}"), test); 102 } 96 103 test = w.get("waterway"); 97 if (test != null && test.equals("riverbank")) 104 if (test != null && test.equals("riverbank")) { 98 105 set(1108, marktr("waterway type {0}"), test); 106 } 99 107 Boolean btest = OsmUtils.getOsmBoolean(w.get("building")); 100 if (btest != null && btest) 108 if (btest != null && btest) { 101 109 set(1120, marktr("building")); 110 } 102 111 btest = OsmUtils.getOsmBoolean(w.get("area")); 103 if (btest != null && btest) 112 if (btest != null && btest) { 104 113 set(1130, marktr("area")); 114 } 105 115 106 116 if (type != null && !w.isClosed()) { … … 123 133 errors.add(new TestError(this, Severity.WARNING, tr("Unclosed way"), 124 134 type, etype, mode, primitives, highlight)); 125 _errorWays.add(w, w);135 errorWays.add(w, w); 126 136 } 127 137 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java
r3669 r3671 37 37 * @author frsantos 38 38 */ 39 public class UnconnectedWays extends Test 40 { 39 public class UnconnectedWays extends Test { 40 41 41 protected static int UNCONNECTED_WAYS = 1301; 42 42 protected static final String PREFIX = ValidatorPreference.PREFIX + "." + UnconnectedWays.class.getSimpleName(); … … 54 54 double mindist; 55 55 double minmiddledist; 56 56 57 /** 57 58 * Constructor 58 59 */ 59 public UnconnectedWays() 60 { 60 public UnconnectedWays() { 61 61 super(tr("Unconnected ways."), 62 62 tr("This test checks if a way has an endpoint very near to another way.")); … … 64 64 65 65 @Override 66 public void startTest(ProgressMonitor monitor) 67 { 66 public void startTest(ProgressMonitor monitor) { 68 67 super.startTest(monitor); 69 68 ways = new HashSet<MyWaySegment>(); … … 79 78 80 79 @Override 81 public void endTest() 82 { 80 public void endTest() { 83 81 //Area a = Main.ds.getDataSourceArea(); 84 82 Map<Node, Way> map = new HashMap<Node, Way>(); 85 long last = -1; 83 //long last = -1; 86 84 for (int iter = 0; iter < 1; iter++) { 87 last = System.currentTimeMillis(); 88 long last_print = -1; 89 int nr = 0; 90 Collection<MyWaySegment> tmp_ways = ways; 91 for(MyWaySegment s : tmp_ways) { 92 nr++; 93 long now = System.currentTimeMillis(); 94 if (now - last_print > 200) { 95 //System.err.println("processing segment nr: " + nr + " of " + ways.size()); 96 last_print = now; 97 } 98 for(Node en : s.nearbyNodes(mindist)) { 99 if (en == null) 100 continue; 101 if(!s.highway) 102 continue; 103 if (!endnodes_highway.contains(en)) 104 continue; 105 if("turning_circle".equals(en.get("highway")) 106 || "bus_stop".equals(en.get("highway")) 107 || OsmUtils.isTrue(en.get("noexit")) 108 || en.hasKey("barrier")) 109 continue; 110 // There's a small false-positive here. Imagine an intersection 111 // like a 't'. If the top part of the 't' is short enough, it 112 // will trigger the node at the very top of the 't' to be unconnected 113 // to the way that "crosses" the 't'. We should probably check that 114 // the ways to which 'en' belongs are not connected to 's.w'. 115 map.put(en, s.w); 116 } 117 } 118 //System.out.println("p1 elapsed: " + (System.currentTimeMillis()-last)); 119 last = System.currentTimeMillis(); 120 } 121 for(Map.Entry<Node, Way> error : map.entrySet()) 122 { 85 //last = System.currentTimeMillis(); 86 long last_print = -1; 87 int nr = 0; 88 Collection<MyWaySegment> tmp_ways = ways; 89 for (MyWaySegment s : tmp_ways) { 90 nr++; 91 long now = System.currentTimeMillis(); 92 if (now - last_print > 200) { 93 //System.err.println("processing segment nr: " + nr + " of " + ways.size()); 94 last_print = now; 95 } 96 for (Node en : s.nearbyNodes(mindist)) { 97 if (en == null || !s.highway || !endnodes_highway.contains(en)) { 98 continue; 99 } 100 if ("turning_circle".equals(en.get("highway")) 101 || "bus_stop".equals(en.get("highway")) 102 || OsmUtils.isTrue(en.get("noexit")) 103 || en.hasKey("barrier")) { 104 continue; 105 } 106 // There's a small false-positive here. Imagine an intersection 107 // like a 't'. If the top part of the 't' is short enough, it 108 // will trigger the node at the very top of the 't' to be unconnected 109 // to the way that "crosses" the 't'. We should probably check that 110 // the ways to which 'en' belongs are not connected to 's.w'. 111 map.put(en, s.w); 112 } 113 } 114 //System.out.println("p1 elapsed: " + (System.currentTimeMillis()-last)); 115 //last = System.currentTimeMillis(); 116 } 117 for (Map.Entry<Node, Way> error : map.entrySet()) { 123 118 errors.add(new TestError(this, Severity.WARNING, 124 tr("Way end node near other highway"), UNCONNECTED_WAYS, 125 Arrays.asList(error.getKey(), error.getValue()))); 119 tr("Way end node near other highway"), 120 UNCONNECTED_WAYS, 121 Arrays.asList(error.getKey(), error.getValue()))); 126 122 } 127 123 map.clear(); 128 for(MyWaySegment s : ways) 129 { 130 for(Node en : s.nearbyNodes(mindist)) 131 { 124 for (MyWaySegment s : ways) { 125 for (Node en : s.nearbyNodes(mindist)) { 132 126 if (endnodes_highway.contains(en) && !s.highway && !s.isArea()) { 133 127 map.put(en, s.w); … … 138 132 } 139 133 //System.out.println("p2 elapsed: " + (System.currentTimeMillis()-last)); 140 last = System.currentTimeMillis(); 141 for(Map.Entry<Node, Way> error : map.entrySet()) 142 { 134 //last = System.currentTimeMillis(); 135 for (Map.Entry<Node, Way> error : map.entrySet()) { 143 136 errors.add(new TestError(this, Severity.WARNING, 144 tr("Way end node near other way"), UNCONNECTED_WAYS, 145 Arrays.asList(error.getKey(), error.getValue()))); 137 tr("Way end node near other way"), 138 UNCONNECTED_WAYS, 139 Arrays.asList(error.getKey(), error.getValue()))); 146 140 } 147 141 /* the following two use a shorter distance */ 148 if(minmiddledist > 0.0) 149 { 142 if (minmiddledist > 0.0) { 150 143 map.clear(); 151 for(MyWaySegment s : ways) 152 { 153 for(Node en : s.nearbyNodes(minmiddledist)) 154 { 155 if (!middlenodes.contains(en)) 144 for (MyWaySegment s : ways) { 145 for (Node en : s.nearbyNodes(minmiddledist)) { 146 if (!middlenodes.contains(en)) { 156 147 continue; 148 } 157 149 map.put(en, s.w); 158 150 } 159 151 } 160 152 //System.out.println("p3 elapsed: " + (System.currentTimeMillis()-last)); 161 last = System.currentTimeMillis(); 162 for(Map.Entry<Node, Way> error : map.entrySet()) 163 { 153 //last = System.currentTimeMillis(); 154 for (Map.Entry<Node, Way> error : map.entrySet()) { 164 155 errors.add(new TestError(this, Severity.OTHER, 165 tr("Way node near other way"), UNCONNECTED_WAYS, 166 Arrays.asList(error.getKey(), error.getValue()))); 156 tr("Way node near other way"), 157 UNCONNECTED_WAYS, 158 Arrays.asList(error.getKey(), error.getValue()))); 167 159 } 168 160 map.clear(); 169 for(MyWaySegment s : ways) 170 { 171 for(Node en : s.nearbyNodes(minmiddledist)) 172 { 173 if (!othernodes.contains(en)) 161 for (MyWaySegment s : ways) { 162 for (Node en : s.nearbyNodes(minmiddledist)) { 163 if (!othernodes.contains(en)) { 174 164 continue; 165 } 175 166 map.put(en, s.w); 176 167 } 177 168 } 178 169 //System.out.println("p4 elapsed: " + (System.currentTimeMillis()-last)); 179 last = System.currentTimeMillis(); 180 for(Map.Entry<Node, Way> error : map.entrySet()) 181 { 170 //last = System.currentTimeMillis(); 171 for (Map.Entry<Node, Way> error : map.entrySet()) { 182 172 errors.add(new TestError(this, Severity.OTHER, 183 tr("Connected way end node near other way"), UNCONNECTED_WAYS, 184 Arrays.asList(error.getKey(), error.getValue()))); 173 tr("Connected way end node near other way"), 174 UNCONNECTED_WAYS, 175 Arrays.asList(error.getKey(), error.getValue()))); 185 176 } 186 177 } … … 189 180 super.endTest(); 190 181 //System.out.println("p99 elapsed: " + (System.currentTimeMillis()-last)); 191 last = System.currentTimeMillis(); 192 } 193 194 private class MyWaySegment 195 { 182 //last = System.currentTimeMillis(); 183 } 184 185 private class MyWaySegment { 196 186 private final Line2D line; 197 187 public final Way w; … … 205 195 final Node n2; 206 196 207 public MyWaySegment(Way w, Node n1, Node n2) 208 { 197 public MyWaySegment(Way w, Node n1, Node n2) { 209 198 this.w = w; 210 199 String railway = w.get("railway"); … … 220 209 } 221 210 222 public boolean nearby(Node n, double dist) 223 { 224 // return !w.containsNode(n) 225 // && line.ptSegDist(n.getEastNorth().east(), n.getEastNorth().north()) < dist; 211 public boolean nearby(Node n, double dist) { 226 212 if (w == null) { 227 213 Main.debug("way null"); … … 240 226 return line.ptSegDist(p) < dist; 241 227 } 242 public List<LatLon> getBounds(double fudge) 243 { 228 229 public List<LatLon> getBounds(double fudge) { 244 230 double x1 = n1.getCoor().lon(); 245 231 double x2 = n2.getCoor().lon(); … … 264 250 } 265 251 266 public Collection<Node> nearbyNodes(double dist) 267 { 252 public Collection<Node> nearbyNodes(double dist) { 268 253 // If you're looking for nodes that are farther 269 254 // away that we looked for last time, the cached … … 284 269 Set<Node> trimmed = new HashSet<Node>(nearbyNodeCache); 285 270 for (Node n : new HashSet<Node>(nearbyNodeCache)) { 286 if (!nearby(n, dist)) 271 if (!nearby(n, dist)) { 287 272 trimmed.remove(n); 273 } 288 274 } 289 275 return trimmed; … … 307 293 for (Node n : found_nodes) { 308 294 if (!nearby(n, dist) || 309 (ds_area != null && !ds_area.contains(n.getCoor()))) 295 (ds_area != null && !ds_area.contains(n.getCoor()))) { 310 296 continue; 297 } 311 298 // It is actually very rare for us to find a node 312 299 // so defer as much of the work as possible, like 313 300 // allocating the hash set 314 if (nearbyNodeCache == null) 301 if (nearbyNodeCache == null) { 315 302 nearbyNodeCache = new HashSet<Node>(); 303 } 316 304 nearbyNodeCache.add(n); 317 305 } 318 306 nearbyNodeCacheDist = dist; 319 if (nearbyNodeCache == null) 307 if (nearbyNodeCache == null) { 320 308 nearbyNodeCache = Collections.emptySet(); 309 } 321 310 return nearbyNodeCache; 322 311 } … … 330 319 } 331 320 332 List<MyWaySegment> getWaySegments(Way w) 333 { 321 List<MyWaySegment> getWaySegments(Way w) { 334 322 List<MyWaySegment> ret = new ArrayList<MyWaySegment>(); 335 323 if (!w.isUsable() … … 339 327 340 328 int size = w.getNodesCount(); 341 if(size < 2) 329 if (size < 2) 342 330 return ret; 343 for(int i = 1; i < size; ++i) 344 { 345 if(i < size-1) 331 for (int i = 1; i < size; ++i) { 332 if(i < size-1) { 346 333 addNode(w.getNode(i), middlenodes); 334 } 347 335 MyWaySegment ws = new MyWaySegment(w, w.getNode(i-1), w.getNode(i)); 348 if (ws.isBoundary || ws.isAbandoned) 336 if (ws.isBoundary || ws.isAbandoned) { 349 337 continue; 338 } 350 339 ret.add(ws); 351 340 } … … 354 343 355 344 @Override 356 public void visit(Way w) 357 { 345 public void visit(Way w) { 358 346 ways.addAll(getWaySegments(w)); 359 347 Set<Node> set = endnodes; 360 if(w.hasKey("highway") || w.hasKey("railway")) 348 if (w.hasKey("highway") || w.hasKey("railway")) { 361 349 set = endnodes_highway; 350 } 362 351 addNode(w.firstNode(), set); 363 352 addNode(w.lastNode(), set); 364 353 } 354 365 355 @Override 366 public void visit(Node n) 367 { 368 } 369 private void addNode(Node n, Set<Node> s) 370 { 356 public void visit(Node n) { 357 } 358 359 private void addNode(Node n, Set<Node> s) { 371 360 boolean m = middlenodes.contains(n); 372 361 boolean e = endnodes.contains(n); 373 362 boolean eh = endnodes_highway.contains(n); 374 363 boolean o = othernodes.contains(n); 375 if(!m && !e && !o && !eh) 364 if (!m && !e && !o && !eh) { 376 365 s.add(n); 377 else if(!o) 378 { 366 } else if (!o) { 379 367 othernodes.add(n); 380 if (e)368 if (e) { 381 369 endnodes.remove(n); 382 else if (eh)370 } else if (eh) { 383 371 endnodes_highway.remove(n); 384 else372 } else { 385 373 middlenodes.remove(n); 374 } 386 375 } 387 376 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/UntaggedNode.java
r3669 r3671 23 23 * @author frsantos 24 24 */ 25 public class UntaggedNode extends Test 26 { 25 public class UntaggedNode extends Test { 26 27 27 protected static final int UNTAGGED_NODE_BLANK = 201; 28 28 protected static final int UNTAGGED_NODE_FIXME = 202; … … 36 36 * Constructor 37 37 */ 38 public UntaggedNode() 39 { 38 public UntaggedNode() { 40 39 super(tr("Untagged and unconnected nodes")+".", 41 40 tr("This test checks for untagged nodes that are not part of any way.")); … … 43 42 44 43 @Override 45 public void startTest(ProgressMonitor monitor) 46 { 44 public void startTest(ProgressMonitor monitor) { 47 45 super.startTest(monitor); 48 46 } 49 47 50 48 @Override 51 public void visit(Collection<OsmPrimitive> selection) 52 { 49 public void visit(Collection<OsmPrimitive> selection) { 53 50 for (OsmPrimitive p : selection) { 54 51 if (p.isUsable() && p instanceof Node) { … … 59 56 60 57 @Override 61 public void visit(Node n) 62 { 58 public void visit(Node n) { 63 59 if(n.isUsable() && !n.isTagged() && n.getReferrers().isEmpty()) { 64 60 if (!n.hasKeys()) { … … 69 65 for (Map.Entry<String, String> tag : n.getKeys().entrySet()) { 70 66 String key = tag.getKey(); 71 String value = tag.getValue();72 67 if (contains(tag, "fixme") || contains(tag, "FIXME")) { 73 68 /* translation note: don't translate quoted words */ … … 114 109 115 110 @Override 116 public Command fixError(TestError testError) 117 { 111 public Command fixError(TestError testError) { 118 112 return DeleteCommand.delete(Main.map.mapView.getEditLayer(), testError.getPrimitives()); 119 113 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/UntaggedWay.java
r3669 r3671 44 44 /** Ways that must have a name */ 45 45 public static final Set<String> NAMED_WAYS = new HashSet<String>(); 46 static 47 { 46 static { 48 47 NAMED_WAYS.add( "motorway" ); 49 48 NAMED_WAYS.add( "trunk" ); … … 58 57 * Constructor 59 58 */ 60 public UntaggedWay() 61 { 59 public UntaggedWay() { 62 60 super(tr("Untagged, empty and one node ways."), 63 61 tr("This test checks for untagged, empty and one node ways.")); … … 65 63 66 64 @Override 67 public void visit(Way w) 68 {69 if (!w.isUsable())return;65 public void visit(Way w) { 66 if (!w.isUsable()) 67 return; 70 68 71 69 Map<String, String> tags = w.getKeys(); 72 if( tags.size() != 0 ) 73 { 70 if (!tags.isEmpty()) { 74 71 String highway = tags.get("highway"); 75 if(highway != null && NAMED_WAYS.contains(highway)) 76 { 77 if( !tags.containsKey("name") && !tags.containsKey("ref") ) 78 { 72 if (highway != null && NAMED_WAYS.contains(highway)) { 73 if (!tags.containsKey("name") && !tags.containsKey("ref")) { 79 74 boolean isRoundabout = false; 80 75 boolean hasName = false; 81 for( String key : w.keySet()) 82 { 76 for (String key : w.keySet()) { 83 77 hasName = key.startsWith("name:") || key.endsWith("_name") || key.endsWith("_ref"); 84 if (hasName)78 if (hasName) { 85 79 break; 86 if(key.equals("junction"))87 { 80 } 81 if (key.equals("junction")) { 88 82 isRoundabout = w.get("junction").equals("roundabout"); 89 83 break; … … 91 85 } 92 86 93 if( !hasName && !isRoundabout) 94 errors.add( new TestError(this, Severity.WARNING, tr("Unnamed ways"), UNNAMED_WAY, w) ); 95 else if(isRoundabout) 96 errors.add( new TestError(this, Severity.WARNING, tr("Unnamed junction"), UNNAMED_JUNCTION, w) ); 87 if (!hasName && !isRoundabout) { 88 errors.add(new TestError(this, Severity.WARNING, tr("Unnamed ways"), UNNAMED_WAY, w)); 89 } else if (isRoundabout) { 90 errors.add(new TestError(this, Severity.WARNING, tr("Unnamed junction"), UNNAMED_JUNCTION, w)); 91 } 97 92 } 98 93 } 99 94 } 100 95 101 if(!w.isTagged() && !multipolygonways.contains(w)) 102 { 103 if(w.hasKeys())104 errors.add( new TestError(this, Severity.WARNING, tr("Untagged ways (commented)"), COMMENTED_WAY, w) );105 else106 errors.add( new TestError(this, Severity.WARNING, tr("Untagged ways"), UNTAGGED_WAY, w) );96 if (!w.isTagged() && !multipolygonways.contains(w)) { 97 if (w.hasKeys()) { 98 errors.add(new TestError(this, Severity.WARNING, tr("Untagged ways (commented)"), COMMENTED_WAY, w)); 99 } else { 100 errors.add(new TestError(this, Severity.WARNING, tr("Untagged ways"), UNTAGGED_WAY, w)); 101 } 107 102 } 108 103 109 if( w.getNodesCount() == 0 ) 110 { 111 errors.add( new TestError(this, Severity.ERROR, tr("Empty ways"), EMPTY_WAY, w) ); 104 if (w.getNodesCount() == 0) { 105 errors.add(new TestError(this, Severity.ERROR, tr("Empty ways"), EMPTY_WAY, w)); 106 } else if (w.getNodesCount() == 1) { 107 errors.add(new TestError(this, Severity.ERROR, tr("One node ways"), ONE_NODE_WAY, w)); 112 108 } 113 else if( w.getNodesCount() == 1 )114 {115 errors.add( new TestError(this, Severity.ERROR, tr("One node ways"), ONE_NODE_WAY, w) );116 }117 118 109 } 119 110 120 111 @Override 121 public void startTest(ProgressMonitor monitor) 122 { 112 public void startTest(ProgressMonitor monitor) { 123 113 super.startTest(monitor); 124 114 multipolygonways = new LinkedList<Way>(); 125 for (Relation r : Main.main.getCurrentDataSet().getRelations()) 126 { 127 if(r.isUsable() && "multipolygon".equals(r.get("type"))) 128 { 129 for (RelationMember m : r.getMembers()) 130 { 131 if(m.getMember() != null && m.getMember() instanceof Way && 132 m.getMember().isUsable() && !m.getMember().isTagged()) 115 for (Relation r : Main.main.getCurrentDataSet().getRelations()) { 116 if (r.isUsable() && "multipolygon".equals(r.get("type"))) { 117 for (RelationMember m : r.getMembers()) { 118 if (m.getMember() != null && m.getMember() instanceof Way && 119 m.getMember().isUsable() && !m.getMember().isTagged()) { 133 120 multipolygonways.add((Way)m.getMember()); 121 } 134 122 } 135 123 } … … 138 126 139 127 @Override 140 public void endTest() 141 { 128 public void endTest() { 142 129 multipolygonways = null; 143 130 super.endTest(); … … 145 132 146 133 @Override 147 public boolean isFixable(TestError testError) 148 { 149 if( testError.getTester() instanceof UntaggedWay ) 150 { 134 public boolean isFixable(TestError testError) { 135 if (testError.getTester() instanceof UntaggedWay) 151 136 return testError.getCode() == EMPTY_WAY 152 137 || testError.getCode() == ONE_NODE_WAY; 153 }154 138 155 139 return false; … … 157 141 158 142 @Override 159 public Command fixError(TestError testError) 160 { 143 public Command fixError(TestError testError) { 161 144 return DeleteCommand.delete(Main.map.mapView.getEditLayer(), testError.getPrimitives()); 162 145 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/WronglyOrderedWays.java
r3669 r3671 20 20 * @author jrreid 21 21 */ 22 public class WronglyOrderedWays extends Test { 22 public class WronglyOrderedWays extends Test { 23 23 24 protected static int WRONGLY_ORDERED_COAST = 1001; 24 25 protected static int WRONGLY_ORDERED_WATER = 1002; … … 26 27 27 28 /** The already detected errors */ 28 Bag<Way, Way> _errorWays;29 protected Bag<Way, Way> errorWays; 29 30 30 31 /** 31 32 * Constructor 32 33 */ 33 public WronglyOrderedWays() 34 { 34 public WronglyOrderedWays() { 35 35 super(tr("Wrongly Ordered Ways."), 36 36 tr("This test checks the direction of water, land and coastline ways.")); … … 38 38 39 39 @Override 40 public void startTest(ProgressMonitor monitor) 41 { 40 public void startTest(ProgressMonitor monitor) { 42 41 super.startTest(monitor); 43 _errorWays = new Bag<Way, Way>();42 errorWays = new Bag<Way, Way>(); 44 43 } 45 44 46 45 @Override 47 public void endTest() 48 { 49 _errorWays = null; 46 public void endTest() { 47 errorWays = null; 50 48 super.endTest(); 51 49 } 52 50 53 51 @Override 54 public void visit(Way w) 55 { 52 public void visit(Way w) { 56 53 String errortype = ""; 57 54 int type; 58 55 59 if (!w.isUsable()56 if (!w.isUsable()) 60 57 return; 61 58 if (w.getNodesCount() <= 0) … … 63 60 64 61 String natural = w.get("natural"); 65 if (natural == null)62 if (natural == null) 66 63 return; 67 64 68 if( natural.equals("coastline") ) 69 { 65 if (natural.equals("coastline")) { 70 66 errortype = tr("Reversed coastline: land not on left side"); 71 67 type= WRONGLY_ORDERED_COAST; 72 } 73 else if(natural.equals("water") ) 74 { 68 } else if (natural.equals("water")) { 75 69 errortype = tr("Reversed water: land not on left side"); 76 70 type= WRONGLY_ORDERED_WATER; 77 } 78 else if( natural.equals("land") ) 79 { 71 } else if (natural.equals("land")) { 80 72 errortype = tr("Reversed land: land not on left side"); 81 73 type= WRONGLY_ORDERED_LAND; 82 } 83 else 74 } else 84 75 return; 85 86 76 87 77 /** … … 93 83 * 94 84 */ 95 96 if(w.getNode(0) == w.getNode(w.getNodesCount()-1)) 97 { 85 if(w.getNode(0) == w.getNode(w.getNodesCount()-1)) { 98 86 double area2 = 0; 99 87 100 for (int node = 1; node < w.getNodesCount(); node++) 101 { 88 for (int node = 1; node < w.getNodesCount(); node++) { 102 89 area2 += (w.getNode(node-1).getCoor().lon() * w.getNode(node).getCoor().lat() 103 90 - w.getNode(node).getCoor().lon() * w.getNode(node-1).getCoor().lat()); 104 91 } 105 92 106 if(((natural.equals("coastline") || natural.equals("land")) && area2 < 0.) 107 || (natural.equals("water") && area2 > 0.)) 108 { 93 if (((natural.equals("coastline") || natural.equals("land")) && area2 < 0.) 94 || (natural.equals("water") && area2 > 0.)) { 109 95 List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(); 110 96 primitives.add(w); 111 97 errors.add( new TestError(this, Severity.OTHER, errortype, type, primitives) ); 112 _errorWays.add(w,w);98 errorWays.add(w,w); 113 99 } 114 100 } -
trunk/src/org/openstreetmap/josm/data/validation/util/AgregatePrimitivesVisitor.java
r3669 r3671 19 19 * @author frsantos 20 20 */ 21 public class AgregatePrimitivesVisitor extends AbstractVisitor 22 { 21 public class AgregatePrimitivesVisitor extends AbstractVisitor { 23 22 /** Aggregated data */ 24 23 final Collection<OsmPrimitive> aggregatedData = new HashSet<OsmPrimitive>(); … … 29 28 * @return The aggregated primitives 30 29 */ 31 public Collection<OsmPrimitive> visit(Collection<OsmPrimitive> data) 32 { 33 for (OsmPrimitive osm : data) 34 { 30 public Collection<OsmPrimitive> visit(Collection<OsmPrimitive> data) { 31 for (OsmPrimitive osm : data) { 35 32 osm.visit(this); 36 33 } … … 39 36 } 40 37 41 public void visit(Node n)42 { 43 if(!aggregatedData.contains(n)) 38 @Override 39 public void visit(Node n) { 40 if (!aggregatedData.contains(n)) { 44 41 aggregatedData.add(n); 45 }46 47 public void visit(Way w)48 {49 if(!aggregatedData.contains(w))50 {51 aggregatedData.add(w);52 for (Node n : w.getNodes())53 visit(n);54 42 } 55 43 } 56 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 57 56 public void visit(Relation r) { 58 57 if (!aggregatedData.contains(r)) { -
trunk/src/org/openstreetmap/josm/data/validation/util/MultipleNameVisitor.java
r3669 r3671 31 31 * @param data The collection of primitives 32 32 */ 33 public void visit(Collection<? extends OsmPrimitive> data) 34 { 33 public void visit(Collection<? extends OsmPrimitive> data) { 35 34 String multipleName = null; 36 35 String multiplePluralClassname = null; … … 40 39 41 40 multipleClassname = null; 42 for (OsmPrimitive osm : data) 43 { 41 for (OsmPrimitive osm : data) { 44 42 String name = osm.get("name"); 45 if(name == null) name = osm.get("ref"); 46 if(!initializedname) 47 { 43 if (name == null) { 44 name = osm.get("ref"); 45 } 46 if (!initializedname) { 48 47 multipleName = name; initializedname = true; 49 } 50 else if(multipleName != null && (name == null || !name.equals(multipleName))) 51 { 48 } else if (multipleName != null && (name == null || !name.equals(multipleName))) { 52 49 multipleName = null; 53 50 } 54 51 55 if(firstName == null && name != null) 52 if (firstName == null && name != null) { 56 53 firstName = name; 54 } 57 55 osm.visit(this); 58 if (multipleClassname == null) 59 { 56 if (multipleClassname == null) { 60 57 multipleClassname = className; 61 58 multiplePluralClassname = classNamePlural; 62 } 63 else if (!multipleClassname.equals(className)) 64 { 59 } else if (!multipleClassname.equals(className)) { 65 60 multipleClassname = "object"; 66 61 multiplePluralClassname = trn("object", "objects", 2); … … 68 63 } 69 64 70 if (size == 1)65 if (size == 1) { 71 66 displayName = name; 72 else if(multipleName != null)67 } else if (multipleName != null) { 73 68 displayName = size + " " + trn(multipleClassname, multiplePluralClassname, size) + ": " + multipleName; 74 else if(firstName != null)69 } else if (firstName != null) { 75 70 displayName = size + " " + trn(multipleClassname, multiplePluralClassname, size) + ": " + tr("{0}, ...", firstName); 76 else71 } else { 77 72 displayName = size + " " + trn(multipleClassname, multiplePluralClassname, size); 73 } 78 74 } 79 75 80 76 @Override 81 public JLabel toLabel() 82 { 77 public JLabel toLabel() { 83 78 return new JLabel(getText(), getIcon(), JLabel.HORIZONTAL); 84 79 } … … 88 83 * @return the name of the items 89 84 */ 90 public String getText() 91 { 85 public String getText() { 92 86 return displayName; 93 87 } … … 97 91 * @return the icon of the items 98 92 */ 99 public Icon getIcon() 100 { 101 if( size == 1 ) 93 public Icon getIcon() { 94 if (size == 1) 102 95 return icon; 103 96 else -
trunk/src/org/openstreetmap/josm/data/validation/util/NameVisitor.java
r3669 r3671 43 43 * is displayed. 44 44 */ 45 @Override 45 46 public void visit(Node n) { 46 47 name = n.getDisplayName(DefaultNameFormatter.getInstance()); … … 55 56 * is displayed with x being the number of nodes in the way. 56 57 */ 58 @Override 57 59 public void visit(Way w) { 58 60 name = w.getDisplayName(DefaultNameFormatter.getInstance()); … … 65 67 /** 66 68 */ 69 @Override 67 70 public void visit(Relation e) { 68 71 name = e.getDisplayName(DefaultNameFormatter.getInstance()); … … 77 80 } 78 81 79 80 82 private void addId(OsmPrimitive osm) { 81 if (Main.pref.getBoolean("osm-primitives.showid")) 83 if (Main.pref.getBoolean("osm-primitives.showid")) { 82 84 name += tr(" [id: {0}]", osm.getId()); 85 } 83 86 } 84 87 } -
trunk/src/org/openstreetmap/josm/data/validation/util/ValUtil.java
r3670 r3671 38 38 * @return A list with all the cells the way starts or ends 39 39 */ 40 public static List<List<Way>> getWaysInCell(Way w, Map<Point2D,List<Way>> cellWays) 41 { 40 public static List<List<Way>> getWaysInCell(Way w, Map<Point2D,List<Way>> cellWays) { 42 41 if (w.getNodesCount() == 0) 43 42 return Collections.emptyList(); … … 59 58 cell = new Point2D.Double(x0, y0); 60 59 cellNodes.add(cell); 61 List<Way> ways = cellWays.get( cell ); 62 if( ways == null ) 63 { 60 List<Way> ways = cellWays.get(cell); 61 if (ways == null) { 64 62 ways = new ArrayList<Way>(); 65 63 cellWays.put(cell, ways); … … 69 67 // End of the way 70 68 cell = new Point2D.Double(x1, y1); 71 if( !cellNodes.contains(cell) ) 72 { 69 if (!cellNodes.contains(cell)) { 73 70 cellNodes.add(cell); 74 71 ways = cellWays.get( cell ); 75 if( ways == null ) 76 { 72 if (ways == null) { 77 73 ways = new ArrayList<Way>(); 78 74 cellWays.put(cell, ways); … … 82 78 83 79 // Then floor coordinates, in case the way is in the border of the cell. 84 x0 = (long)Math.floor(n1.getEastNorth().east() * OsmValidator.griddetail); 85 y0 = (long)Math.floor(n1.getEastNorth().north() * OsmValidator.griddetail); 86 x1 = (long)Math.floor(n2.getEastNorth().east() * OsmValidator.griddetail); 87 y1 = (long)Math.floor(n2.getEastNorth().north() * OsmValidator.griddetail); 80 x0 = (long) Math.floor(n1.getEastNorth().east() * OsmValidator.griddetail); 81 y0 = (long) Math.floor(n1.getEastNorth().north() * OsmValidator.griddetail); 82 x1 = (long) Math.floor(n2.getEastNorth().east() * OsmValidator.griddetail); 83 y1 = (long) Math.floor(n2.getEastNorth().north() * OsmValidator.griddetail); 88 84 89 85 // Start of the way 90 86 cell = new Point2D.Double(x0, y0); 91 if( !cellNodes.contains(cell) ) 92 { 87 if (!cellNodes.contains(cell)) { 93 88 cellNodes.add(cell); 94 ways = cellWays.get( cell ); 95 if( ways == null ) 96 { 89 ways = cellWays.get(cell); 90 if (ways == null) { 97 91 ways = new ArrayList<Way>(); 98 92 cellWays.put(cell, ways); … … 103 97 // End of the way 104 98 cell = new Point2D.Double(x1, y1); 105 if( !cellNodes.contains(cell) ) 106 { 99 if (!cellNodes.contains(cell)) { 107 100 cellNodes.add(cell); 108 ways = cellWays.get( cell ); 109 if( ways == null ) 110 { 101 ways = cellWays.get(cell); 102 if (ways == null) { 111 103 ways = new ArrayList<Way>(); 112 104 cellWays.put(cell, ways); … … 114 106 cells.add(ways); 115 107 } 116 117 108 return cells; 118 109 } … … 128 119 * @return A list with the coordinates of all cells 129 120 */ 130 public static List<Point2D> getSegmentCells(Node n1, Node n2, double gridDetail) 131 { 121 public static List<Point2D> getSegmentCells(Node n1, Node n2, double gridDetail) { 132 122 List<Point2D> cells = new ArrayList<Point2D>(); 133 123 double x0 = n1.getEastNorth().east() * gridDetail; … … 136 126 double y1 = n2.getEastNorth().north() * gridDetail + 1; 137 127 138 if( x0 > x1 ) 139 { 128 if (x0 > x1) { 140 129 // Move to 1st-4th cuadrants 141 130 double aux; … … 147 136 double dy = y1 - y0; 148 137 long stepY = y0 <= y1 ? 1 : -1; 149 long gridX0 = (long)Math.floor(x0); 150 long gridX1 = (long)Math.floor(x1); 151 long gridY0 = (long)Math.floor(y0); 152 long gridY1 = (long)Math.floor(y1); 138 long gridX0 = (long) Math.floor(x0); 139 long gridX1 = (long) Math.floor(x1); 140 long gridY0 = (long) Math.floor(y0); 141 long gridY1 = (long) Math.floor(y1); 153 142 154 143 long maxSteps = (gridX1 - gridX0) + Math.abs(gridY1 - gridY0) + 1; 155 while( (gridX0 <= gridX1 && (gridY0 - gridY1)*stepY <= 0) && maxSteps-- > 0) 156 { 157 cells.add( new Point2D.Double(gridX0, gridY0) ); 144 while ((gridX0 <= gridX1 && (gridY0 - gridY1)*stepY <= 0) && maxSteps-- > 0) { 145 cells.add( new Point2D.Double(gridX0, gridY0)); 158 146 159 147 // Is the cross between the segment and next vertical line nearer than the cross with next horizontal line? … … 166 154 double distY = Math.pow(scanX - x0, 2) + Math.pow(gridY0 + stepY - y0, 2); 167 155 168 if (distX < distY)156 if (distX < distY) { 169 157 gridX0 += 1; 170 else158 } else { 171 159 gridY0 += stepY; 160 } 172 161 } 173 174 162 return cells; 175 163 } -
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r3669 r3671 1 1 // License: GPL. See LICENSE file for details. 2 3 2 package org.openstreetmap.josm.gui; 4 3 … … 77 76 import org.openstreetmap.josm.actions.ZoomOutAction; 78 77 import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo; 79 import org.openstreetmap.josm.actions.ValidateAction;80 78 import org.openstreetmap.josm.actions.audio.AudioBackAction; 81 79 import org.openstreetmap.josm.actions.audio.AudioFasterAction; … … 89 87 import org.openstreetmap.josm.gui.tagging.TaggingPresetSearchAction; 90 88 import org.openstreetmap.josm.tools.Shortcut; 89 91 90 /** 92 91 * This is the JOSM main menu bar. It is overwritten to initialize itself and provide all menu -
trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java
r3669 r3671 2 2 package org.openstreetmap.josm.gui.dialogs; 3 3 4 import org.openstreetmap.josm.gui.layer.Layer;5 import org.openstreetmap.josm.gui.layer.OsmDataLayer;6 4 import static org.openstreetmap.josm.tools.I18n.marktr; 7 5 import static org.openstreetmap.josm.tools.I18n.tr; … … 48 46 import org.openstreetmap.josm.data.validation.ValidatorVisitor; 49 47 import org.openstreetmap.josm.gui.MapView; 50 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;51 48 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 52 49 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 53 50 import org.openstreetmap.josm.gui.SideButton; 54 51 import org.openstreetmap.josm.gui.dialogs.validator.ValidatorTreePanel; 52 import org.openstreetmap.josm.gui.layer.Layer; 53 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 55 54 import org.openstreetmap.josm.gui.preferences.ValidatorPreference; 56 55 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 73 72 public ValidatorTreePanel tree; 74 73 74 /** The fix button */ 75 75 private SideButton fixButton; 76 /** The fixbutton */76 /** The ignore button */ 77 77 private SideButton ignoreButton; 78 /** The ignorebutton */78 /** The select button */ 79 79 private SideButton selectButton; 80 /** The select button */81 80 82 81 private JPopupMenu popupMenu; … … 98 97 JMenuItem zoomTo = new JMenuItem(tr("Zoom to problem")); 99 98 zoomTo.addActionListener(new ActionListener() { 99 @Override 100 100 public void actionPerformed(ActionEvent e) { 101 101 zoomToProblem(); … … 129 129 } 130 130 add(buttonPanel, BorderLayout.SOUTH); 131 132 131 } 133 132 … … 154 153 @Override 155 154 public void setVisible(boolean v) { 156 if (tree != null) 155 if (tree != null) { 157 156 tree.setVisible(v); 157 } 158 158 super.setVisible(v); 159 159 Main.map.repaint(); … … 176 176 for (TreePath path : selectionPaths) { 177 177 DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); 178 if (node == null) 178 if (node == null) { 179 179 continue; 180 } 180 181 181 182 Enumeration<DefaultMutableTreeNode> children = node.breadthFirstEnumeration(); 182 183 while (children.hasMoreElements()) { 183 184 DefaultMutableTreeNode childNode = children.nextElement(); 184 if (processedNodes.contains(childNode)) 185 if (processedNodes.contains(childNode)) { 185 186 continue; 187 } 186 188 187 189 processedNodes.add(childNode); … … 215 217 for (TreePath path : selectionPaths) { 216 218 DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); 217 if (node == null) 219 if (node == null) { 218 220 continue; 221 } 219 222 220 223 Object mainNodeInfo = node.getUserObject(); … … 232 235 while (children.hasMoreElements()) { 233 236 DefaultMutableTreeNode childNode = children.nextElement(); 234 if (processedNodes.contains(childNode)) 237 if (processedNodes.contains(childNode)) { 235 238 continue; 239 } 236 240 237 241 processedNodes.add(childNode); … … 248 252 } 249 253 continue; 250 } else if (asked == JOptionPane.CANCEL_OPTION) 254 } else if (asked == JOptionPane.CANCEL_OPTION) { 251 255 continue; 256 } 252 257 } 253 258 … … 255 260 while (children.hasMoreElements()) { 256 261 DefaultMutableTreeNode childNode = children.nextElement(); 257 if (processedNodes.contains(childNode)) 262 if (processedNodes.contains(childNode)) { 258 263 continue; 264 } 259 265 260 266 processedNodes.add(childNode); … … 329 335 } 330 336 } 331 332 337 Main.main.getCurrentDataSet().setSelected(sel); 333 338 } 334 339 340 @Override 335 341 public void actionPerformed(ActionEvent e) { 336 342 String actionCommand = e.getActionCommand(); 337 if (actionCommand.equals("Select")) 343 if (actionCommand.equals("Select")) { 338 344 setSelectedItems(); 339 else if (actionCommand.equals("Fix")) 345 } else if (actionCommand.equals("Fix")) { 340 346 fixErrors(e); 341 else if (actionCommand.equals("Ignore")) 347 } else if (actionCommand.equals("Ignore")) { 342 348 ignoreErrors(e); 349 } 343 350 } 344 351 … … 389 396 } 390 397 selectButton.setEnabled(true); 391 if (ignoreButton != null) 398 if (ignoreButton != null) { 392 399 ignoreButton.setEnabled(true); 400 } 393 401 394 402 return hasFixes; … … 415 423 public void mouseClicked(MouseEvent e) { 416 424 fixButton.setEnabled(false); 417 if (ignoreButton != null) 425 if (ignoreButton != null) { 418 426 ignoreButton.setEnabled(false); 427 } 419 428 selectButton.setEnabled(false); 420 429 … … 428 437 if (isDblClick) { 429 438 Main.main.getCurrentDataSet().setSelected(sel); 430 if(Main.pref.getBoolean("validator.autozoom", false)) 439 if(Main.pref.getBoolean("validator.autozoom", false)) { 431 440 AutoScaleAction.zoomTo(sel); 441 } 432 442 } 433 443 } … … 449 459 */ 450 460 public class SelectionWatch implements TreeSelectionListener { 461 @Override 451 462 public void valueChanged(TreeSelectionEvent e) { 452 463 fixButton.setEnabled(false); 453 if (ignoreButton != null) 464 if (ignoreButton != null) { 454 465 ignoreButton.setEnabled(false); 466 } 455 467 selectButton.setEnabled(false); 456 468 … … 467 479 468 480 public static class ValidatorBoundingXYVisitor extends BoundingXYVisitor implements ValidatorVisitor { 469 481 @Override 470 482 public void visit(OsmPrimitive p) { 471 483 if (p.isUsable()) { … … 474 486 } 475 487 488 @Override 476 489 public void visit(WaySegment ws) { 477 490 if (ws.lowerIndex < 0 || ws.lowerIndex + 1 >= ws.way.getNodesCount()) … … 481 494 } 482 495 496 @Override 483 497 public void visit(List<Node> nodes) { 484 498 for (Node n: nodes) { … … 491 505 if (!Main.pref.getBoolean(ValidatorPreference.PREF_FILTER_BY_SELECTION, false)) 492 506 return; 493 if (newSelection.isEmpty()) 507 if (newSelection.isEmpty()) { 494 508 tree.setFilter(null); 509 } 495 510 HashSet<OsmPrimitive> filter = new HashSet<OsmPrimitive>(newSelection); 496 511 tree.setFilter(filter); 497 512 } 498 513 514 @Override 499 515 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 500 516 updateSelection(newSelection); … … 539 555 final Command fixCommand = error.getFix(); 540 556 if (fixCommand != null) { 541 SwingUtilities.invokeAndWait( 542 new Runnable() { 543 public void run() { 544 Main.main.undoRedo.addNoRedraw(fixCommand); 545 } 546 } 547 ); 557 SwingUtilities.invokeAndWait(new Runnable() { 558 @Override 559 public void run() { 560 Main.main.undoRedo.addNoRedraw(fixCommand); 561 } 562 }); 548 563 error.setIgnored(true); 549 564 } … … 552 567 monitor.subTask(tr("Updating map ...")); 553 568 SwingUtilities.invokeAndWait(new Runnable() { 569 @Override 554 570 public void run() { 555 571 Main.main.undoRedo.afterAdd(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java
r3669 r3671 33 33 * @author frsantos 34 34 */ 35 36 35 public class ValidatorTreePanel extends JTree { 37 36 /** Serializable ID */ … … 41 40 * The validation data. 42 41 */ 43 protected DefaultTreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode());42 protected DefaultTreeModel valTreeModel = new DefaultTreeModel(new DefaultMutableTreeNode()); 44 43 45 44 /** The list of errors shown in the tree */ … … 60 59 public ValidatorTreePanel(List<TestError> errors) { 61 60 ToolTipManager.sharedInstance().registerComponent(this); 62 this.setModel( treeModel);61 this.setModel(valTreeModel); 63 62 this.setRootVisible(false); 64 63 this.setShowsRootHandles(true); … … 87 86 res += "<br>" + d; 88 87 res += "</html>"; 89 } else 88 } else { 90 89 res = node.toString(); 90 } 91 91 } 92 92 return res; … … 100 100 @Override 101 101 public void setVisible(boolean v) { 102 if (v) 102 if (v) { 103 103 buildTree(); 104 else 105 treeModel.setRoot(new DefaultMutableTreeNode()); 104 } else { 105 valTreeModel.setRoot(new DefaultMutableTreeNode()); 106 } 106 107 super.setVisible(v); 107 108 } … … 115 116 116 117 if (errors == null || errors.isEmpty()) { 117 treeModel.setRoot(rootNode);118 valTreeModel.setRoot(rootNode); 118 119 return; 119 120 } … … 127 128 DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); 128 129 Object userObject = node.getUserObject(); 129 if (userObject instanceof Severity) 130 if (userObject instanceof Severity) { 130 131 oldSelectedRows.add(userObject); 131 else if (userObject instanceof String) { 132 } else if (userObject instanceof String) { 132 133 String msg = (String) userObject; 133 134 msg = msg.substring(0, msg.lastIndexOf(" (")); … … 145 146 146 147 for (TestError e : errors) { 147 if (e.getIgnored()) 148 if (e.getIgnored()) { 148 149 continue; 150 } 149 151 Severity s = e.getSeverity(); 150 152 String d = e.getDescription(); … … 158 160 } 159 161 } 160 if (!found) 162 if (!found) { 161 163 continue; 164 } 162 165 } 163 166 if (d != null) { … … 168 171 } 169 172 b.add(d, e); 170 } else 173 } else { 171 174 errorTree.get(s).add(m, e); 175 } 172 176 } 173 177 … … 176 180 Bag<String, TestError> severityErrors = errorTree.get(s); 177 181 Map<String, Bag<String, TestError>> severityErrorsDeep = errorTreeDeep.get(s); 178 if (severityErrors.isEmpty() && severityErrorsDeep.isEmpty()) 182 if (severityErrors.isEmpty() && severityErrorsDeep.isEmpty()) { 179 183 continue; 184 } 180 185 181 186 // Severity node … … 183 188 rootNode.add(severityNode); 184 189 185 if (oldSelectedRows.contains(s)) 190 if (oldSelectedRows.contains(s)) { 186 191 expandedPaths.add(new TreePath(new Object[] { rootNode, severityNode })); 192 } 187 193 188 194 for (Entry<String, List<TestError>> msgErrors : severityErrors.entrySet()) { 189 195 // Message node 190 List<TestError> err ors = msgErrors.getValue();191 String msg = msgErrors.getKey() + " (" + err ors.size() + ")";196 List<TestError> errs = msgErrors.getValue(); 197 String msg = msgErrors.getKey() + " (" + errs.size() + ")"; 192 198 DefaultMutableTreeNode messageNode = new DefaultMutableTreeNode(msg); 193 199 severityNode.add(messageNode); … … 197 203 } 198 204 199 for (TestError error : err ors) {205 for (TestError error : errs) { 200 206 // Error node 201 207 DefaultMutableTreeNode errorNode = new DefaultMutableTreeNode(error); … … 218 224 for (Entry<String, List<TestError>> msgErrors : errorlist.entrySet()) { 219 225 // Message node 220 List<TestError> err ors = msgErrors.getValue();226 List<TestError> errs = msgErrors.getValue(); 221 227 String msg; 222 if (groupNode != null) 223 msg = msgErrors.getKey() + " (" + errors.size() + ")"; 224 else 225 msg = bag.getKey() + " - " + msgErrors.getKey() + " (" + errors.size() + ")"; 228 if (groupNode != null) { 229 msg = msgErrors.getKey() + " (" + errs.size() + ")"; 230 } else { 231 msg = bag.getKey() + " - " + msgErrors.getKey() + " (" + errs.size() + ")"; 232 } 226 233 DefaultMutableTreeNode messageNode = new DefaultMutableTreeNode(msg); 227 if (groupNode != null) 234 if (groupNode != null) { 228 235 groupNode.add(messageNode); 229 else236 } else { 230 237 severityNode.add(messageNode); 238 } 231 239 232 240 if (oldSelectedRows.contains(msgErrors.getKey())) { … … 239 247 } 240 248 241 for (TestError error : err ors) {249 for (TestError error : errs) { 242 250 // Error node 243 251 DefaultMutableTreeNode errorNode = new DefaultMutableTreeNode(error); … … 248 256 } 249 257 250 treeModel.setRoot(rootNode);258 valTreeModel.setRoot(rootNode); 251 259 for (TreePath path : expandedPaths) { 252 260 this.expandPath(path); … … 260 268 public void setErrorList(List<TestError> errors) { 261 269 this.errors = errors; 262 if (isVisible()) 270 if (isVisible()) { 263 271 buildTree(); 272 } 264 273 } 265 274 … … 273 282 errors.clear(); 274 283 for (TestError error : newerrors) { 275 if (!error.getIgnored()) 284 if (!error.getIgnored()) { 276 285 errors.add(error); 277 } 278 if (isVisible()) 286 } 287 } 288 if (isVisible()) { 279 289 buildTree(); 290 } 280 291 } 281 292 … … 293 304 294 305 public void setFilter(Set<OsmPrimitive> filter) { 295 if (filter != null && filter. size() == 0)306 if (filter != null && filter.isEmpty()) { 296 307 this.filter = null; 297 else308 } else { 298 309 this.filter = filter; 299 if (isVisible()) 310 } 311 if (isVisible()) { 300 312 buildTree(); 313 } 301 314 } 302 315 … … 330 343 */ 331 344 public DefaultMutableTreeNode getRoot() { 332 return (DefaultMutableTreeNode) treeModel.getRoot();345 return (DefaultMutableTreeNode) valTreeModel.getRoot(); 333 346 } 334 347 -
trunk/src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreeRenderer.java
r3669 r3671 25 25 public Component getTreeCellRendererComponent(JTree tree, Object value, 26 26 boolean selected, boolean expanded, boolean leaf, int row, 27 boolean hasFocus) 28 { 27 boolean hasFocus) { 29 28 super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); 30 29 31 DefaultMutableTreeNode node = (DefaultMutableTreeNode)value; 30 DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; 32 31 Object nodeInfo = node.getUserObject(); 33 32 34 if (nodeInfo instanceof Severity) 35 { 36 Severity s = (Severity)nodeInfo; 33 if (nodeInfo instanceof Severity) { 34 Severity s = (Severity) nodeInfo; 37 35 setIcon(ImageProvider.get("data", s.getIcon())); 38 } 39 else if (nodeInfo instanceof TestError) 40 { 41 TestError error = (TestError)nodeInfo; 36 } else if (nodeInfo instanceof TestError) { 37 TestError error = (TestError) nodeInfo; 42 38 MultipleNameVisitor v = new MultipleNameVisitor(); 43 39 v.visit(error.getPrimitives()); … … 45 41 setIcon(v.getIcon()); 46 42 } 47 48 43 return this; 49 44 } -
trunk/src/org/openstreetmap/josm/gui/layer/ValidatorLayer.java
r3669 r3671 35 35 private int updateCount = -1; 36 36 37 38 37 public ValidatorLayer() { 39 38 super(tr("Validation errors")); … … 67 66 while (errorMessages.hasMoreElements()) { 68 67 Object tn = errorMessages.nextElement().getUserObject(); 69 if (tn instanceof TestError) 68 if (tn instanceof TestError) { 70 69 ((TestError) tn).paint(g, mv); 70 } 71 71 } 72 72 … … 86 86 StringBuilder b = new StringBuilder(); 87 87 for (Severity s : Severity.values()) { 88 if (errorTree.containsKey(s)) 88 if (errorTree.containsKey(s)) { 89 89 b.append(tr(s.toString())).append(": ").append(errorTree.get(s).size()).append("<br>"); 90 } 90 91 } 91 92 … … 134 135 } 135 136 137 @Override 136 138 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 137 139 } 138 140 141 @Override 139 142 public void layerAdded(Layer newLayer) { 140 143 } … … 143 146 * If layer is the OSM Data layer, remove all errors 144 147 */ 148 @Override 145 149 public void layerRemoved(Layer oldLayer) { 146 150 if (oldLayer instanceof OsmDataLayer && Main.map.mapView.getEditLayer() == null) { -
trunk/src/org/openstreetmap/josm/gui/preferences/ValidatorPreference.java
r3669 r3671 23 23 * @author frsantos 24 24 */ 25 public class ValidatorPreference implements PreferenceSetting 26 { 25 public class ValidatorPreference implements PreferenceSetting { 27 26 28 27 public static class Factory implements PreferenceSettingFactory { 28 @Override 29 29 public PreferenceSetting createPreferenceSetting() { 30 30 return new ValidatorPreference(); … … 66 66 private Collection<Test> allTests; 67 67 68 @Override 68 69 public void addGui(PreferenceTabbedPane gui) 69 70 { … … 89 90 90 91 allTests = OsmValidator.getTests(); 91 for(Test test: allTests) 92 { 92 for (Test test: allTests) { 93 93 test.addGui(testPanel); 94 94 } … … 103 103 } 104 104 105 public boolean ok()106 { 105 @Override 106 public boolean ok() { 107 107 StringBuilder tests = new StringBuilder(); 108 108 StringBuilder testsBeforeUpload = new StringBuilder(); 109 Boolean res = false;110 109 111 for (Test test : allTests) 112 { 113 if(test.ok()) 114 res = false; 110 for (Test test : allTests) { 115 111 String name = test.getClass().getSimpleName(); 116 tests.append( ',').append(name).append('=').append(117 testsBeforeUpload.append( ',').append(name).append('=').append(112 tests.append(',').append(name).append('=').append(test.enabled); 113 testsBeforeUpload.append(',').append(name).append('=').append(test.testBeforeUpload); 118 114 } 119 115 120 if (tests.length() > 0 ) tests = tests.deleteCharAt(0); 121 if (testsBeforeUpload.length() > 0 ) testsBeforeUpload = testsBeforeUpload.deleteCharAt(0); 116 if (tests.length() > 0) { 117 tests = tests.deleteCharAt(0); 118 } 119 if (testsBeforeUpload.length() > 0) { 120 testsBeforeUpload = testsBeforeUpload.deleteCharAt(0); 121 } 122 122 123 OsmValidator.initializeTests( allTests);123 OsmValidator.initializeTests(allTests); 124 124 125 Main.pref.put( 126 Main.pref.put( 127 Main.pref.put( 128 Main.pref.put( 129 Main.pref.put( 125 Main.pref.put(PREF_TESTS, tests.toString()); 126 Main.pref.put(PREF_TESTS_BEFORE_UPLOAD, testsBeforeUpload.toString()); 127 Main.pref.put(PREF_USE_IGNORE, prefUseIgnore.isSelected()); 128 Main.pref.put(PREF_OTHER_UPLOAD, prefOtherUpload.isSelected()); 129 Main.pref.put(PREF_LAYER, prefUseLayer.isSelected()); 130 130 return false; 131 131 } -
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r3669 r3671 92 92 public final static Collection<PluginProxy> pluginList = new LinkedList<PluginProxy>(); 93 93 94 95 94 /** 96 95 * Removes deprecated plugins from a collection of plugins. Modifies the
Note:
See TracChangeset
for help on using the changeset viewer.