Changeset 7500 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2014-09-05T14:14:11+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/DatasetConsistencyTest.java
r6203 r7500 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.data.osm; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import java.io.PrintWriter; … … 6 8 import java.io.Writer; 7 9 10 import org.openstreetmap.josm.Main; 8 11 import org.openstreetmap.josm.data.coor.LatLon; 12 import org.openstreetmap.josm.tools.Utils; 9 13 10 14 /** 11 * This class can be used to run consistency tests on dataset. Any errors found will be written to provided PrintWriter 15 * This class can be used to run consistency tests on dataset. Any errors found will be written to provided PrintWriter. 12 16 * <br> 13 * Texts here should not be translated because they're not intended for users but for josm developers 14 * 17 * Texts here should not be translated because they're not intended for users but for josm developers. 18 * @since 2500 15 19 */ 16 20 public class DatasetConsistencyTest { … … 21 25 private int errorCount; 22 26 27 /** 28 * Constructs a new {@code DatasetConsistencyTest}. 29 * @param dataSet The dataset to test 30 * @param writer The writer used to write results 31 */ 23 32 public DatasetConsistencyTest(DataSet dataSet, Writer writer) { 24 33 this.dataSet = dataSet; … … 33 42 } 34 43 44 /** 45 * Checks that parent primitive is referred from its child members 46 */ 35 47 public void checkReferrers() { 48 long startTime = System.currentTimeMillis(); 36 49 // It's also error when referred primitive's dataset is null but it's already covered by referredPrimitiveNotInDataset check 37 for (Way way :dataSet.getWays()) {50 for (Way way : dataSet.getWays()) { 38 51 if (!way.isDeleted()) { 39 for (Node n :way.getNodes()) {52 for (Node n : way.getNodes()) { 40 53 if (n.getDataSet() != null && !n.getReferrers().contains(way)) { 41 54 printError("WAY NOT IN REFERRERS", "%s is part of %s but is not in referrers", n, way); … … 45 58 } 46 59 47 for (Relation relation :dataSet.getRelations()) {60 for (Relation relation : dataSet.getRelations()) { 48 61 if (!relation.isDeleted()) { 49 for (RelationMember m :relation.getMembers()) {62 for (RelationMember m : relation.getMembers()) { 50 63 if (m.getMember().getDataSet() != null && !m.getMember().getReferrers().contains(relation)) { 51 64 printError("RELATION NOT IN REFERRERS", "%s is part of %s but is not in referrers", m.getMember(), relation); … … 54 67 } 55 68 } 56 } 57 69 printElapsedTime(startTime); 70 } 71 72 /** 73 * Checks for womplete ways with incomplete nodes. 74 */ 58 75 public void checkCompleteWaysWithIncompleteNodes() { 59 for (Way way:dataSet.getWays()) { 76 long startTime = System.currentTimeMillis(); 77 for (Way way : dataSet.getWays()) { 60 78 if (way.isUsable()) { 61 for (Node node :way.getNodes()) {79 for (Node node : way.getNodes()) { 62 80 if (node.isIncomplete()) { 63 81 printError("USABLE HAS INCOMPLETE", "%s is usable but contains incomplete node '%s'", way, node); … … 66 84 } 67 85 } 68 } 69 86 printElapsedTime(startTime); 87 } 88 89 /** 90 * Checks for complete nodes without coordinates. 91 */ 70 92 public void checkCompleteNodesWithoutCoordinates() { 71 for (Node node:dataSet.getNodes()) { 93 long startTime = System.currentTimeMillis(); 94 for (Node node : dataSet.getNodes()) { 72 95 if (!node.isIncomplete() && node.isVisible() && (node.getCoor() == null || node.getEastNorth() == null)) { 73 96 printError("COMPLETE WITHOUT COORDINATES", "%s is not incomplete but has null coordinates", node); 74 97 } 75 98 } 76 } 77 99 printElapsedTime(startTime); 100 } 101 102 /** 103 * Checks that nodes can be retrieved through their coordinates. 104 */ 78 105 public void searchNodes() { 79 for (Node n:dataSet.getNodes()) { 106 long startTime = System.currentTimeMillis(); 107 for (Node n : dataSet.getNodes()) { 80 108 if (!n.isIncomplete() && !n.isDeleted()) { 81 109 LatLon c = n.getCoor(); … … 88 116 } 89 117 } 90 } 91 118 printElapsedTime(startTime); 119 } 120 121 /** 122 * Checks that ways can be retrieved through their bounding box. 123 */ 92 124 public void searchWays() { 93 for (Way w:dataSet.getWays()) { 125 long startTime = System.currentTimeMillis(); 126 for (Way w : dataSet.getWays()) { 94 127 if (!w.isIncomplete() && !w.isDeleted() && w.getNodesCount() >= 2 && !dataSet.searchWays(w.getBBox()).contains(w)) { 95 128 printError("SEARCH WAYS", "%s not found using Dataset.searchWays()", w); 96 129 } 97 130 } 131 printElapsedTime(startTime); 98 132 } 99 133 … … 112 146 } 113 147 148 /** 149 * Checks that referred primitives are present in dataset. 150 */ 114 151 public void referredPrimitiveNotInDataset() { 115 for (Way way:dataSet.getWays()) { 116 for (Node node:way.getNodes()) { 152 long startTime = System.currentTimeMillis(); 153 for (Way way : dataSet.getWays()) { 154 for (Node node : way.getNodes()) { 117 155 checkReferredPrimitive(node, way); 118 156 } 119 157 } 120 158 121 for (Relation relation :dataSet.getRelations()) {122 for (RelationMember member :relation.getMembers()) {159 for (Relation relation : dataSet.getRelations()) { 160 for (RelationMember member : relation.getMembers()) { 123 161 checkReferredPrimitive(member.getMember(), relation); 124 162 } 125 163 } 126 } 127 128 164 printElapsedTime(startTime); 165 } 166 167 /** 168 * Checks for zero and one-node ways. 169 */ 129 170 public void checkZeroNodesWays() { 130 for (Way way:dataSet.getWays()) { 171 long startTime = System.currentTimeMillis(); 172 for (Way way : dataSet.getWays()) { 131 173 if (way.isUsable() && way.getNodesCount() == 0) { 132 174 printError("WARN - ZERO NODES", "Way %s has zero nodes", way); … … 135 177 } 136 178 } 137 } 138 179 printElapsedTime(startTime); 180 } 181 182 private void printElapsedTime(long startTime) { 183 if (Main.isDebugEnabled()) { 184 StackTraceElement item = Thread.currentThread().getStackTrace()[2]; 185 String operation = getClass().getSimpleName() + "." + item.getMethodName(); 186 long elapsedTime = System.currentTimeMillis() - startTime; 187 Main.debug(tr("Test ''{0}'' completed in {1}", 188 operation, Utils.getDurationString(elapsedTime))); 189 } 190 } 191 192 /** 193 * Runs test. 194 */ 139 195 public void runTest() { 140 196 try { 197 long startTime = System.currentTimeMillis(); 141 198 referredPrimitiveNotInDataset(); 142 199 checkReferrers(); … … 146 203 searchWays(); 147 204 checkZeroNodesWays(); 205 printElapsedTime(startTime); 148 206 if (errorCount > MAX_ERRORS) { 149 207 writer.println((errorCount - MAX_ERRORS) + " more..."); 150 208 } 209 151 210 } catch (Exception e) { 152 211 writer.println("Exception during dataset integrity test:"); … … 155 214 } 156 215 216 /** 217 * Runs test on the given dataset. 218 * @param dataSet the dataset to test 219 * @return the errors as string 220 */ 157 221 public static String runTests(DataSet dataSet) { 158 222 StringWriter writer = new StringWriter(); … … 160 224 return writer.toString(); 161 225 } 162 163 226 }
Note:
See TracChangeset
for help on using the changeset viewer.