Class CheckResourceLoader


  • public class CheckResourceLoader
    extends java.lang.Object
    Loads Checks found on the classpath. Checks are discovered by scanning a list of configurable classpath URLs for implementations of a specific type, which also configurable. Enabled checks found are instantiated and added to the Set of returned checks. Configuration:
     {
       "CheckResourceLoader": {
         "scanUrls": [
             "org.openstreetmap.atlas.checks"
         ],
         "type": "org.openstreetmap.atlas.checks.base.Check",
         "enabled": {
             "key.template": "%s.enabled",
             "value.default": false
         }
       }
     }
     
    • Constructor Summary

      Constructors 
      Constructor Description
      CheckResourceLoader​(org.openstreetmap.atlas.utilities.configuration.Configuration configuration)
      Default constructor
      CheckResourceLoader​(org.openstreetmap.atlas.utilities.configuration.Configuration configuration, ExternalDataFetcher fileFetcher)
      Default constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.openstreetmap.atlas.utilities.configuration.Configuration getConfiguration()  
      org.openstreetmap.atlas.utilities.configuration.Configuration getConfigurationForCountry​(java.lang.String country)
      Get configuration for a specific country, overriding for country specific overrides and group specific overrides
      <T extends Check>
      java.util.Set<T>
      loadChecks()
      Loads checks that are enabled by configuration
      <T extends Check>
      java.util.Set<T>
      loadChecks​(java.util.function.Predicate<java.lang.Class<?>> isEnabled)  
      <T extends Check>
      java.util.Set<T>
      loadChecks​(java.util.function.Predicate<java.lang.Class<?>> isEnabled, org.openstreetmap.atlas.utilities.configuration.Configuration configuration)
      Loads checks that are enabled by some other means, defined by isEnabled
      <T extends Check>
      java.util.Set<T>
      loadChecks​(java.util.function.Predicate<java.lang.Class<?>> isEnabled, org.openstreetmap.atlas.utilities.configuration.Configuration configuration, ExternalDataFetcher fileFetcher)
      Loads checks that are enabled by some other means, defined by isEnabled
      <T extends Check>
      java.util.Set<T>
      loadChecks​(org.openstreetmap.atlas.utilities.configuration.Configuration configuration)  
      <T extends Check>
      java.util.Set<T>
      loadChecksForCountry​(java.lang.String country)  
      <T extends Check>
      java.util.Set<T>
      loadChecksUsingConstructors​(java.lang.Class<?>[][] constructorArgumentTypes, java.lang.Object[][] constructorArguments)  
      <T extends Check>
      java.util.Set<T>
      loadChecksUsingConstructors​(java.util.function.Predicate<java.lang.Class<?>> isEnabled, java.lang.Class<?>[][] constructorArgumentTypes, java.lang.Object[][] constructorArguments)
      Given a list of corresponding types and arguments, try to initialize each enabled check using each constructor in order.
      • Methods inherited from class java.lang.Object

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

      • CheckResourceLoader

        public CheckResourceLoader​(org.openstreetmap.atlas.utilities.configuration.Configuration configuration)
        Default constructor
        Parameters:
        configuration - the Configuration for loaded checks
      • CheckResourceLoader

        public CheckResourceLoader​(org.openstreetmap.atlas.utilities.configuration.Configuration configuration,
                                   ExternalDataFetcher fileFetcher)
        Default constructor
        Parameters:
        configuration - the Configuration for loaded checks
        fileFetcher - the ExternalDataFetcher to load additional data with
    • Method Detail

      • getConfiguration

        public org.openstreetmap.atlas.utilities.configuration.Configuration getConfiguration()
      • getConfigurationForCountry

        public org.openstreetmap.atlas.utilities.configuration.Configuration getConfigurationForCountry​(java.lang.String country)
        Get configuration for a specific country, overriding for country specific overrides and group specific overrides
        Parameters:
        country - country string
        Returns:
        Configuration
      • loadChecks

        public <T extends Check> java.util.Set<T> loadChecks​(java.util.function.Predicate<java.lang.Class<?>> isEnabled)
      • loadChecks

        public <T extends Check> java.util.Set<T> loadChecks​(org.openstreetmap.atlas.utilities.configuration.Configuration configuration)
      • loadChecks

        public <T extends Check> java.util.Set<T> loadChecks​(java.util.function.Predicate<java.lang.Class<?>> isEnabled,
                                                             org.openstreetmap.atlas.utilities.configuration.Configuration configuration,
                                                             ExternalDataFetcher fileFetcher)
        Loads checks that are enabled by some other means, defined by isEnabled
        Type Parameters:
        T - check type
        Parameters:
        isEnabled - Predicate used to determine if a check is enabled
        configuration - Configuration used to loadChecks CheckResourceLoader
        fileFetcher - ExternalDataFetcher used to load additional data
        Returns:
        a Set of checks
      • loadChecks

        public <T extends Check> java.util.Set<T> loadChecks​(java.util.function.Predicate<java.lang.Class<?>> isEnabled,
                                                             org.openstreetmap.atlas.utilities.configuration.Configuration configuration)
        Loads checks that are enabled by some other means, defined by isEnabled
        Type Parameters:
        T - check type
        Parameters:
        isEnabled - Predicate used to determine if a check is enabled
        configuration - Configuration used to loadChecks CheckResourceLoader
        Returns:
        a Set of checks
      • loadChecks

        public <T extends Check> java.util.Set<T> loadChecks()
        Loads checks that are enabled by configuration
        Type Parameters:
        T - check type
        Returns:
        a Set of checks
      • loadChecksForCountry

        public <T extends Check> java.util.Set<T> loadChecksForCountry​(java.lang.String country)
      • loadChecksUsingConstructors

        public <T extends Check> java.util.Set<T> loadChecksUsingConstructors​(java.lang.Class<?>[][] constructorArgumentTypes,
                                                                              java.lang.Object[][] constructorArguments)
      • loadChecksUsingConstructors

        public <T extends Check> java.util.Set<T> loadChecksUsingConstructors​(java.util.function.Predicate<java.lang.Class<?>> isEnabled,
                                                                              java.lang.Class<?>[][] constructorArgumentTypes,
                                                                              java.lang.Object[][] constructorArguments)
        Given a list of corresponding types and arguments, try to initialize each enabled check using each constructor in order.
        Type Parameters:
        T - Any class that extends Check.
        Parameters:
        isEnabled - Predicate used to determine if a check is enabled
        constructorArgumentTypes - List containing arrays of classes. Each array corresponds to one constructor call. For example, to try a constructor that takes in two doubles but fall back to a constructor that takes in one double, constructorArgumentTypes would look like this: [[Double.TYPE, Double.TYPE], [Double.TYPE]]. An empty constructor is denoted by an empty array.
        constructorArguments - List containing arrays of objects. This MUST have the same shape as constructorArgumentTypes and the values MUST be the same types and in the same order as constructorArgumentTypes. For example, given constructorArgumentTypes of [[Double.TYPE, Boolean.TYPE], [Boolean.TYPE, Integer.TYPE], []], constructorArguments needs to look like [[double, boolean], [boolean, int], []].
        Returns:
        A set of enabled, initialized checks.