Class OsmValidator


  • public final class OsmValidator
    extends java.lang.Object
    A OSM data validator.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.Collection<java.lang.Class<? extends Test>> allTests
      All registered tests
      private static java.util.Map<java.lang.String,​Test> allTestsMap  
      private static java.lang.Class<Test>[] CORE_TEST_CLASSES
      All available tests in core
      private static ValidatorLayer errorLayer  
      private static double griddetail
      Grid detail, multiplier of east,north values for valuable cell sizing
      private static java.util.SortedMap<java.lang.String,​java.lang.String> ignoredErrors  
      private static boolean testsInitialized  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private OsmValidator()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addIgnoredError​(java.lang.String s)
      Adds an ignored error
      static void addIgnoredError​(java.lang.String s, java.lang.String description)
      Adds an ignored error
      static void addTest​(java.lang.Class<? extends Test> testClass)
      Adds a test to the list of available tests
      private static void applyPrefs​(java.util.Map<java.lang.String,​Test> tests, boolean beforeUpload)  
      static java.util.Map<java.lang.String,​java.lang.String> buildIgnore​(javax.swing.JTree tree)
      Build a HashMap from a tree of ignored errors
      private static java.util.Map<java.lang.String,​java.lang.String> buildIgnore​(javax.swing.tree.TreeModel model, javax.swing.tree.DefaultMutableTreeNode node)  
      static javax.swing.JTree buildJTreeList()
      Build a JTree with a list
      (package private) static void cleanupIgnoredErrors()
      Make sure that we don't keep single entries for a "group ignore".
      (package private) static void clearIgnoredErrors()
      For unit tests
      private static java.lang.String extractCodeFromIgnoreKey​(java.lang.String key)
      Extract the leading digits building the code for the error key.
      static java.util.Collection<java.lang.Class<? extends Test>> getAllAvailableTestClasses()
      Gets the list of all available test classes
      static java.util.SortedMap<java.lang.String,​Test> getAllTestsMap()
      Gets a map from simple names to all tests.
      static java.util.Collection<Test> getEnabledTests​(boolean beforeUpload)
      Gets all tests that are run
      static java.util.Map<Severity,​java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​java.util.List<TestError>>>> getErrorsBySeverityMessageDescription​(java.util.Collection<TestError> errors, java.util.function.Predicate<? super TestError> filterToUse)
      Groups the given collection of errors by severity, then message, then description.
      static double getGridDetail()
      Returns grid detail, multiplier of east,north values for valuable cell sizing
      static java.util.SortedMap<java.lang.String,​java.lang.String> getIgnoredErrors()
      Get the list of all ignored errors
      static <T extends Test>
      T
      getTest​(java.lang.Class<T> testClass)
      Returns the instance of the given test class.
      static java.util.Collection<Test> getTests()
      Gets all tests that are possible
      static java.lang.String getValidatorDir()
      Returns the validator directory.
      static boolean hasIgnoredError​(java.lang.String s)
      Check if a error should be ignored
      static void initialize()
      Initializes OsmValidator.
      static void initializeErrorLayer()
      Initializes error layer.
      static void initializeGridDetail()
      Initialize grid details based on the current projection system.
      static void initializeTests()
      Initializes all tests if this operation hasn't been performed already.
      static void initializeTests​(java.util.Collection<? extends Test> allTests)
      Initializes all tests
      private static javax.swing.tree.DefaultMutableTreeNode inTree​(javax.swing.tree.DefaultMutableTreeNode root, java.lang.String name)  
      private static void loadIgnoredErrors()  
      private static void removeLegacyEntries​(boolean force)  
      private static boolean removeLegacyEntry​(boolean force, boolean keep, java.lang.String prefix)  
      static boolean removeTest​(java.lang.Class<? extends Test> testClass)
      Removes a test from the list of available tests.
      static void resetErrorLayer()
      Resets error layer.
      static void resetErrorList()
      Reset the error list by deleting validator.ignorelist
      private static boolean sameCode​(java.lang.String key1, java.lang.String key2)  
      static void saveIgnoredErrors()
      Saves the names of the ignored errors to a preference
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • griddetail

        private static double griddetail
        Grid detail, multiplier of east,north values for valuable cell sizing
      • ignoredErrors

        private static final java.util.SortedMap<java.lang.String,​java.lang.String> ignoredErrors
      • allTests

        private static final java.util.Collection<java.lang.Class<? extends Test>> allTests
        All registered tests
      • allTestsMap

        private static final java.util.Map<java.lang.String,​Test> allTestsMap
      • CORE_TEST_CLASSES

        private static final java.lang.Class<Test>[] CORE_TEST_CLASSES
        All available tests in core
    • Method Detail

      • addTest

        public static void addTest​(java.lang.Class<? extends Test> testClass)
        Adds a test to the list of available tests
        Parameters:
        testClass - The test class
      • removeTest

        public static boolean removeTest​(java.lang.Class<? extends Test> testClass)
        Removes a test from the list of available tests. This will not remove core tests.
        Parameters:
        testClass - The test class
        Returns:
        true if the test was removed (see Collection.remove(java.lang.Object))
        Since:
        15603
      • initialize

        public static void initialize()
        Initializes OsmValidator.
      • getValidatorDir

        public static java.lang.String getValidatorDir()
        Returns the validator directory.
        Returns:
        The validator directory
      • removeLegacyEntry

        private static boolean removeLegacyEntry​(boolean force,
                                                 boolean keep,
                                                 java.lang.String prefix)
      • cleanupIgnoredErrors

        static void cleanupIgnoredErrors()
        Make sure that we don't keep single entries for a "group ignore".
      • sameCode

        private static boolean sameCode​(java.lang.String key1,
                                        java.lang.String key2)
      • extractCodeFromIgnoreKey

        private static java.lang.String extractCodeFromIgnoreKey​(java.lang.String key)
        Extract the leading digits building the code for the error key.
        Parameters:
        key - the error key
        Returns:
        the leading digits
      • hasIgnoredError

        public static boolean hasIgnoredError​(java.lang.String s)
        Check if a error should be ignored
        Parameters:
        s - The ignore group / sub group name
        Returns:
        true to ignore that error
      • getIgnoredErrors

        public static java.util.SortedMap<java.lang.String,​java.lang.String> getIgnoredErrors()
        Get the list of all ignored errors
        Returns:
        The Collection<String> of errors that are ignored
      • buildJTreeList

        public static javax.swing.JTree buildJTreeList()
        Build a JTree with a list
        Returns:
        <type>list as a JTree
      • inTree

        private static javax.swing.tree.DefaultMutableTreeNode inTree​(javax.swing.tree.DefaultMutableTreeNode root,
                                                                      java.lang.String name)
      • buildIgnore

        public static java.util.Map<java.lang.String,​java.lang.String> buildIgnore​(javax.swing.JTree tree)
        Build a HashMap from a tree of ignored errors
        Parameters:
        tree - The JTree of ignored errors
        Returns:
        A HashMap of the ignored errors for comparison
      • buildIgnore

        private static java.util.Map<java.lang.String,​java.lang.String> buildIgnore​(javax.swing.tree.TreeModel model,
                                                                                          javax.swing.tree.DefaultMutableTreeNode node)
      • resetErrorList

        public static void resetErrorList()
        Reset the error list by deleting validator.ignorelist
      • saveIgnoredErrors

        public static void saveIgnoredErrors()
        Saves the names of the ignored errors to a preference
      • resetErrorLayer

        public static void resetErrorLayer()
        Resets error layer.
        Since:
        11852
      • getAllTestsMap

        public static java.util.SortedMap<java.lang.String,​TestgetAllTestsMap()
        Gets a map from simple names to all tests.
        Returns:
        A map of all tests, indexed and sorted by the name of their Java class
      • getTest

        public static <T extends Test> T getTest​(java.lang.Class<T> testClass)
        Returns the instance of the given test class.
        Type Parameters:
        T - testClass type
        Parameters:
        testClass - The class of test to retrieve
        Returns:
        the instance of the given test class, if any, or null
        Since:
        6670
      • applyPrefs

        private static void applyPrefs​(java.util.Map<java.lang.String,​Test> tests,
                                       boolean beforeUpload)
      • getTests

        public static java.util.Collection<TestgetTests()
        Gets all tests that are possible
        Returns:
        The tests
      • getEnabledTests

        public static java.util.Collection<TestgetEnabledTests​(boolean beforeUpload)
        Gets all tests that are run
        Parameters:
        beforeUpload - To get the ones that are run before upload
        Returns:
        The tests
      • getAllAvailableTestClasses

        public static java.util.Collection<java.lang.Class<? extends Test>> getAllAvailableTestClasses()
        Gets the list of all available test classes
        Returns:
        A collection of the test classes
      • initializeGridDetail

        public static void initializeGridDetail()
        Initialize grid details based on the current projection system. Values based on the original value fixed for EPSG:4326 (10000) using heuristics (that is, test&error until most bugs were discovered while keeping the processing time reasonable)
      • getGridDetail

        public static double getGridDetail()
        Returns grid detail, multiplier of east,north values for valuable cell sizing
        Returns:
        grid detail
        Since:
        11852
      • initializeTests

        public static void initializeTests()
        Initializes all tests if this operation hasn't been performed already.
      • initializeTests

        public static void initializeTests​(java.util.Collection<? extends Test> allTests)
        Initializes all tests
        Parameters:
        allTests - The tests to initialize
      • getErrorsBySeverityMessageDescription

        public static java.util.Map<Severity,​java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​java.util.List<TestError>>>> getErrorsBySeverityMessageDescription​(java.util.Collection<TestError> errors,
                                                                                                                                                                                                java.util.function.Predicate<? super TestError> filterToUse)
        Groups the given collection of errors by severity, then message, then description.
        Parameters:
        errors - list of errors to group
        filterToUse - optional filter
        Returns:
        collection of errors grouped by severity, then message, then description
        Since:
        12667