Changeset 7500 in josm for trunk/src


Ignore:
Timestamp:
2014-09-05T14:14:11+02:00 (5 years ago)
Author:
Don-vip
Message:

see #10483 - print elapsed time of data consistency test + update javadoc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/DatasetConsistencyTest.java

    r6203 r7500  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.osm;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
    35
    46import java.io.PrintWriter;
     
    68import java.io.Writer;
    79
     10import org.openstreetmap.josm.Main;
    811import org.openstreetmap.josm.data.coor.LatLon;
     12import org.openstreetmap.josm.tools.Utils;
    913
    1014/**
    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.
    1216 * <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
    1519 */
    1620public class DatasetConsistencyTest {
     
    2125    private int errorCount;
    2226
     27    /**
     28     * Constructs a new {@code DatasetConsistencyTest}.
     29     * @param dataSet The dataset to test
     30     * @param writer The writer used to write results
     31     */
    2332    public DatasetConsistencyTest(DataSet dataSet, Writer writer) {
    2433        this.dataSet = dataSet;
     
    3342    }
    3443
     44    /**
     45     * Checks that parent primitive is referred from its child members
     46     */
    3547    public void checkReferrers() {
     48        long startTime = System.currentTimeMillis();
    3649        // 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()) {
    3851            if (!way.isDeleted()) {
    39                 for (Node n:way.getNodes()) {
     52                for (Node n : way.getNodes()) {
    4053                    if (n.getDataSet() != null && !n.getReferrers().contains(way)) {
    4154                        printError("WAY NOT IN REFERRERS", "%s is part of %s but is not in referrers", n, way);
     
    4558        }
    4659
    47         for (Relation relation:dataSet.getRelations()) {
     60        for (Relation relation : dataSet.getRelations()) {
    4861            if (!relation.isDeleted()) {
    49                 for (RelationMember m:relation.getMembers()) {
     62                for (RelationMember m : relation.getMembers()) {
    5063                    if (m.getMember().getDataSet() != null && !m.getMember().getReferrers().contains(relation)) {
    5164                        printError("RELATION NOT IN REFERRERS", "%s is part of %s but is not in referrers", m.getMember(), relation);
     
    5467            }
    5568        }
    56     }
    57 
     69        printElapsedTime(startTime);
     70    }
     71
     72    /**
     73     * Checks for womplete ways with incomplete nodes.
     74     */
    5875    public void checkCompleteWaysWithIncompleteNodes() {
    59         for (Way way:dataSet.getWays()) {
     76        long startTime = System.currentTimeMillis();
     77        for (Way way : dataSet.getWays()) {
    6078            if (way.isUsable()) {
    61                 for (Node node:way.getNodes()) {
     79                for (Node node : way.getNodes()) {
    6280                    if (node.isIncomplete()) {
    6381                        printError("USABLE HAS INCOMPLETE", "%s is usable but contains incomplete node '%s'", way, node);
     
    6684            }
    6785        }
    68     }
    69 
     86        printElapsedTime(startTime);
     87    }
     88
     89    /**
     90     * Checks for complete nodes without coordinates.
     91     */
    7092    public void checkCompleteNodesWithoutCoordinates() {
    71         for (Node node:dataSet.getNodes()) {
     93        long startTime = System.currentTimeMillis();
     94        for (Node node : dataSet.getNodes()) {
    7295            if (!node.isIncomplete() && node.isVisible() && (node.getCoor() == null || node.getEastNorth() == null)) {
    7396                printError("COMPLETE WITHOUT COORDINATES", "%s is not incomplete but has null coordinates", node);
    7497            }
    7598        }
    76     }
    77 
     99        printElapsedTime(startTime);
     100    }
     101
     102    /**
     103     * Checks that nodes can be retrieved through their coordinates.
     104     */
    78105    public void searchNodes() {
    79         for (Node n:dataSet.getNodes()) {
     106        long startTime = System.currentTimeMillis();
     107        for (Node n : dataSet.getNodes()) {
    80108            if (!n.isIncomplete() && !n.isDeleted()) {
    81109                LatLon c = n.getCoor();
     
    88116            }
    89117        }
    90     }
    91 
     118        printElapsedTime(startTime);
     119    }
     120
     121    /**
     122     * Checks that ways can be retrieved through their bounding box.
     123     */
    92124    public void searchWays() {
    93         for (Way w:dataSet.getWays()) {
     125        long startTime = System.currentTimeMillis();
     126        for (Way w : dataSet.getWays()) {
    94127            if (!w.isIncomplete() && !w.isDeleted() && w.getNodesCount() >= 2 && !dataSet.searchWays(w.getBBox()).contains(w)) {
    95128                printError("SEARCH WAYS", "%s not found using Dataset.searchWays()", w);
    96129            }
    97130        }
     131        printElapsedTime(startTime);
    98132    }
    99133
     
    112146    }
    113147
     148    /**
     149     * Checks that referred primitives are present in dataset.
     150     */
    114151    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()) {
    117155                checkReferredPrimitive(node, way);
    118156            }
    119157        }
    120158
    121         for (Relation relation:dataSet.getRelations()) {
    122             for (RelationMember member:relation.getMembers()) {
     159        for (Relation relation : dataSet.getRelations()) {
     160            for (RelationMember member : relation.getMembers()) {
    123161                checkReferredPrimitive(member.getMember(), relation);
    124162            }
    125163        }
    126     }
    127 
    128 
     164        printElapsedTime(startTime);
     165    }
     166
     167    /**
     168     * Checks for zero and one-node ways.
     169     */
    129170    public void checkZeroNodesWays() {
    130         for (Way way:dataSet.getWays()) {
     171        long startTime = System.currentTimeMillis();
     172        for (Way way : dataSet.getWays()) {
    131173            if (way.isUsable() && way.getNodesCount() == 0) {
    132174                printError("WARN - ZERO NODES", "Way %s has zero nodes", way);
     
    135177            }
    136178        }
    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     */
    139195    public void runTest() {
    140196        try {
     197            long startTime = System.currentTimeMillis();
    141198            referredPrimitiveNotInDataset();
    142199            checkReferrers();
     
    146203            searchWays();
    147204            checkZeroNodesWays();
     205            printElapsedTime(startTime);
    148206            if (errorCount > MAX_ERRORS) {
    149207                writer.println((errorCount - MAX_ERRORS) + " more...");
    150208            }
     209
    151210        } catch (Exception e) {
    152211            writer.println("Exception during dataset integrity test:");
     
    155214    }
    156215
     216    /**
     217     * Runs test on the given dataset.
     218     * @param dataSet the dataset to test
     219     * @return the errors as string
     220     */
    157221    public static String runTests(DataSet dataSet) {
    158222        StringWriter writer = new StringWriter();
     
    160224        return writer.toString();
    161225    }
    162 
    163226}
Note: See TracChangeset for help on using the changeset viewer.