source: josm/trunk/src/org/openstreetmap/josm/data/validation/tests/ApiCapabilitiesTest.java@ 12941

Last change on this file since 12941 was 11129, checked in by simon04, 8 years ago

fix #13799 - Use builder pattern for TestError

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.validation.tests;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import org.openstreetmap.josm.data.osm.Way;
7import org.openstreetmap.josm.data.validation.Severity;
8import org.openstreetmap.josm.data.validation.Test;
9import org.openstreetmap.josm.data.validation.TestError;
10import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
11import org.openstreetmap.josm.io.Capabilities;
12import org.openstreetmap.josm.io.OsmApi;
13
14/**
15 * Performs validation tests against OSM API capabilities. This class does not test length
16 * of key/values (limited to 255 characters) because it's done by {@code TagChecker}.
17 * @since 7574
18 */
19public class ApiCapabilitiesTest extends Test {
20
21 private static final int MAX_WAY_NODES_ERROR = 3401;
22
23 private long maxNodes = -1;
24
25 /**
26 * Constructs a new {@code ApiCapabilitiesTest}.
27 */
28 public ApiCapabilitiesTest() {
29 super(tr("API Capabilities"), tr("Checks for errors against API capabilities"));
30 }
31
32 @Override
33 public void initialize() throws Exception {
34 super.initialize();
35 OsmApi api = OsmApi.getOsmApi();
36 api.initialize(NullProgressMonitor.INSTANCE);
37 Capabilities capabilities = api.getCapabilities();
38 if (capabilities != null) {
39 maxNodes = capabilities.getMaxWayNodes();
40 }
41 }
42
43 @Override
44 public void visit(Way w) {
45 if (maxNodes > 1 && w.getNodesCount() > maxNodes) {
46 String message;
47 if (w.isClosed()) {
48 message = tr("Way contains more than {0} nodes. It should be replaced by a multipolygon", maxNodes);
49 } else {
50 message = tr("Way contains more than {0} nodes. It should be split or simplified", maxNodes);
51 }
52 errors.add(TestError.builder(this, Severity.ERROR, MAX_WAY_NODES_ERROR)
53 .message(message)
54 .primitives(w)
55 .build());
56 }
57 }
58}
Note: See TracBrowser for help on using the repository browser.