Changeset 12390 in josm for trunk/src


Ignore:
Timestamp:
2017-06-11T13:39:33+02:00 (7 years ago)
Author:
michael2402
Message:

See #14794: Document data.validation package and subpackages.

Location:
trunk/src/org/openstreetmap/josm/data/validation
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java

    r12282 r12390  
    134134    };
    135135
     136    /**
     137     * Adds a test to the list of available tests
     138     * @param testClass The test class
     139     */
    136140    public static void addTest(Class<? extends Test> testClass) {
    137141        allTests.add(testClass);
     
    193197    }
    194198
     199    /**
     200     * Adds an ignored error
     201     * @param s The ignore group / sub group name
     202     * @see TestError#getIgnoreGroup()
     203     * @see TestError#getIgnoreSubGroup()
     204     */
    195205    public static void addIgnoredError(String s) {
    196206        ignoredErrors.add(s);
    197207    }
    198208
     209    /**
     210     * Check if a error should be ignored
     211     * @param s The ignore group / sub group name
     212     * @return <code>true</code> to ignore that error
     213     */
    199214    public static boolean hasIgnoredError(String s) {
    200215        return ignoredErrors.contains(s);
    201216    }
    202217
     218    /**
     219     * Saves the names of the ignored errors to a file
     220     */
    203221    public static void saveIgnoredErrors() {
    204222        try (PrintWriter out = new PrintWriter(new File(getValidatorDir(), "ignorederrors"), StandardCharsets.UTF_8.name())) {
     
    270288    }
    271289
     290    /**
     291     * Gets all tests that are possible
     292     * @return The tests
     293     */
    272294    public static Collection<Test> getTests() {
    273295        return getAllTestsMap().values();
    274296    }
    275297
     298    /**
     299     * Gets all tests that are run
     300     * @param beforeUpload To get the ones that are run before upload
     301     * @return The tests
     302     */
    276303    public static Collection<Test> getEnabledTests(boolean beforeUpload) {
    277304        Collection<Test> enabledTests = getTests();
  • trunk/src/org/openstreetmap/josm/data/validation/Severity.java

    r10853 r12390  
    4343    }
    4444
     45    /**
     46     * Retrieves all colors once from the preferences to register them
     47     */
    4548    public static void getColors() {
    4649        for (Severity c : values()) {
  • trunk/src/org/openstreetmap/josm/data/validation/TestError.java

    r11336 r12390  
    299299    }
    300300
     301    /**
     302     * Gets the ignores subgroup that is more specialized than {@link #getIgnoreGroup()}
     303     * @return The ignore sub group
     304     */
    301305    public String getIgnoreSubGroup() {
    302306        String ignorestring = getIgnoreGroup();
     
    307311    }
    308312
     313    /**
     314     * Gets the ignore group ID that is used to allow the user to ignore all same errors
     315     * @return The group id
     316     * @see TestError#getIgnoreSubGroup()
     317     */
    309318    public String getIgnoreGroup() {
    310319        return Integer.toString(code);
    311320    }
    312321
     322    /**
     323     * Flags this error as ignored
     324     * @param state The ignore flag
     325     */
    313326    public void setIgnored(boolean state) {
    314327        ignored = state;
    315328    }
    316329
     330    /**
     331     * Checks if this error is ignored
     332     * @return <code>true</code> if it is ignored
     333     */
    317334    public boolean isIgnored() {
    318335        return ignored;
     
    371388    }
    372389
     390    /**
     391     * Visits all highlighted validation elements
     392     * @param v The visitor that should receive a visit-notification on all highlighted elements
     393     */
    373394    @SuppressWarnings("unchecked")
    374395    public void visitHighlighted(ValidatorVisitor v) {
  • trunk/src/org/openstreetmap/josm/data/validation/ValidatorVisitor.java

    r8510 r12390  
    88import org.openstreetmap.josm.data.osm.WaySegment;
    99
     10/**
     11 * A visitor that is used during validation.
     12 * <p>
     13 * The most basic use is to visit all {@link TestError}s of the validator
     14 */
    1015public interface ValidatorVisitor {
     16    /**
     17     * Visit a test error
     18     * @param error The test error to visit
     19     */
    1120    void visit(TestError error);
    1221
    13     void visit(OsmPrimitive p);
     22    /**
     23     * Visit a OSM primitive, e.g. to highlight it
     24     * @param primitive The primitive
     25     */
     26    void visit(OsmPrimitive primitive);
    1427
    15     void visit(WaySegment ws);
     28    /**
     29     * Visit a way segment that was part of the error
     30     * @param waySegment The way segment
     31     */
     32    void visit(WaySegment waySegment);
    1633
     34    /**
     35     * Visit a list of nodes that are part of the error
     36     * @param nodes The nodes
     37     */
    1738    void visit(List<Node> nodes);
    1839}
  • trunk/src/org/openstreetmap/josm/data/validation/tests/ConditionalKeys.java

    r11747 r12390  
    5151    }
    5252
     53    /**
     54     * Check if the key is a key for an access restriction
     55     * @param part The key (or the restriction part of it, e.g. for lanes)
     56     * @return <code>true</code> if it is a restriction
     57     */
    5358    public static boolean isRestrictionType(String part) {
    5459        return RESTRICTION_TYPES.contains(part);
    5560    }
    5661
     62    /**
     63     * Check if the value is a valid restriction value
     64     * @param part The value
     65     * @return <code>true</code> for allowed restriction values
     66     */
    5767    public static boolean isRestrictionValue(String part) {
    5868        return RESTRICTION_VALUES.contains(part);
    5969    }
    6070
     71    /**
     72     * Checks if the key denotes a <a href="http://wiki.openstreetmap.org/wiki/Key:access#Transport_mode_restrictions">transport access mode restriction</a>
     73     * @param part The key (or the restriction part of it, e.g. for lanes)
     74     * @return <code>true</code> if it is a restriction
     75     */
    6176    public static boolean isTransportationMode(String part) {
    62         // http://wiki.openstreetmap.org/wiki/Key:access#Transport_mode_restrictions
    6377        return TRANSPORT_MODES.contains(part);
    6478    }
    6579
     80    /**
     81     * Check if a key part is a valid direction
     82     * @param part The part of the key
     83     * @return <code>true</code> if it is a direction
     84     */
    6685    public static boolean isDirection(String part) {
    6786        return "forward".equals(part) || "backward".equals(part);
    6887    }
    6988
     89    /**
     90     * Checks if a given key is a valid access key
     91     * @param key The conditional key
     92     * @return <code>true</code> if the key is valid
     93     */
    7094    public boolean isKeyValid(String key) {
    7195        // <restriction-type>[:<transportation mode>][:<direction>]:conditional
     
    91115    }
    92116
     117    /**
     118     * Check if a value is valid
     119     * @param key The key the value is for
     120     * @param value The value
     121     * @return <code>true</code> if it is valid
     122     */
    93123    public boolean isValueValid(String key, String value) {
    94124        return validateValue(key, value) == null;
     
    101131    }
    102132
     133    /**
     134     * A conditional value is a value for the access restriction tag that depends on conditions (time, ...)
     135     */
    103136    public static class ConditionalValue {
     137        /**
     138         * The value the tag should have if the condition matches
     139         */
    104140        public final String restrictionValue;
     141        /**
     142         * The conditions for {@link #restrictionValue}
     143         */
    105144        public final Collection<String> conditions;
    106145
     146        /**
     147         * Create a new {@link ConditionalValue}
     148         * @param restrictionValue The value the tag should have if the condition matches
     149         * @param conditions The conditions for that value
     150         */
    107151        public ConditionalValue(String restrictionValue, Collection<String> conditions) {
    108152            this.restrictionValue = restrictionValue;
     
    137181    }
    138182
     183    /**
     184     * Validate a key/value pair
     185     * @param key The key
     186     * @param value The value
     187     * @return The error message for that value or <code>null</code> to indicate valid
     188     */
    139189    public String validateValue(String key, String value) {
    140190        try {
     
    162212    }
    163213
     214    /**
     215     * Validate a primitive
     216     * @param p The primitive
     217     * @return The errors for that primitive or an empty list if there are no errors.
     218     */
    164219    public List<TestError> validatePrimitive(OsmPrimitive p) {
    165220        final List<TestError> errors = new ArrayList<>();
  • trunk/src/org/openstreetmap/josm/data/validation/tests/SimilarNamedWays.java

    r12283 r12390  
    235235    }
    236236
     237    /**
     238     * A normalization that is applied to names before testing them
     239     */
    237240    @FunctionalInterface
    238241    public interface NormalizeRule {
     
    246249    }
    247250
     251    /**
     252     * A rule to replace by regular expression,
     253     * so that all strings matching the regular expression are handled as if they were {@link RegExprRule#replacement}
     254     */
    248255    public static class RegExprRule implements NormalizeRule {
    249256        private final Pattern regExpr;
    250257        private final String replacement;
    251258
     259        /**
     260         * Create a new rule to replace by regular expression
     261         * @param expression The regular expression
     262         * @param replacement The replacement
     263         */
    252264        public RegExprRule(String expression, String replacement) {
    253265            this.regExpr = Pattern.compile(expression);
     
    266278    }
    267279
     280    /**
     281     * A rule that registers synonyms to a given word
     282     */
    268283    public static class SynonymRule implements NormalizeRule {
    269284
     
    272287        private final String replacement;
    273288
     289        /**
     290         * Create a new {@link SynonymRule}
     291         * @param replacement The word to use instead
     292         * @param words The synonyms for that word
     293         */
    274294        public SynonymRule(String replacement, String... words) {
    275295            this.replacement = replacement.toLowerCase(Locale.ENGLISH);
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    r12279 r12390  
    8181    protected static final String PREFIX = ValidatorPreference.PREFIX + "." + TagChecker.class.getSimpleName();
    8282
     83    /**
     84     * The preference key to check values
     85     */
    8386    public static final String PREF_CHECK_VALUES = PREFIX + ".checkValues";
     87    /**
     88     * The preference key to check keys
     89     */
    8490    public static final String PREF_CHECK_KEYS = PREFIX + ".checkKeys";
     91    /**
     92     * The preference key to enable complex checks
     93     */
    8594    public static final String PREF_CHECK_COMPLEX = PREFIX + ".checkComplex";
     95    /**
     96     * The preference key to search for fixme tags
     97     */
    8698    public static final String PREF_CHECK_FIXMES = PREFIX + ".checkFixmes";
    8799
     100    /**
     101     * The preference key for source files
     102     * @see #DEFAULT_SOURCES
     103     */
    88104    public static final String PREF_SOURCES = PREFIX + ".source";
    89105
     106    /**
     107     * The preference key to check keys - used before upload
     108     */
    90109    public static final String PREF_CHECK_KEYS_BEFORE_UPLOAD = PREF_CHECK_KEYS + "BeforeUpload";
     110    /**
     111     * The preference key to check values - used before upload
     112     */
    91113    public static final String PREF_CHECK_VALUES_BEFORE_UPLOAD = PREF_CHECK_VALUES + "BeforeUpload";
     114    /**
     115     * The preference key to run complex tests - used before upload
     116     */
    92117    public static final String PREF_CHECK_COMPLEX_BEFORE_UPLOAD = PREF_CHECK_COMPLEX + "BeforeUpload";
     118    /**
     119     * The preference key to search for fixmes - used before upload
     120     */
    93121    public static final String PREF_CHECK_FIXMES_BEFORE_UPLOAD = PREF_CHECK_FIXMES + "BeforeUpload";
    94122
     
    638666    }
    639667
     668    /**
     669     * Enables/disables the source list field
     670     */
    640671    public void handlePrefEnable() {
    641672        boolean selected = prefCheckKeys.isSelected() || prefCheckKeysBeforeUpload.isSelected()
Note: See TracChangeset for help on using the changeset viewer.