Changeset 6591 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2014-01-01T14:56:22+01:00 (11 years ago)
Author:
simon04
Message:

Refactoring: create Test.TagTest for tests that check tags only independent from the primitive type

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

Legend:

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

    r6400 r6591  
    8888
    8989    /**
     90     * A test that forwards all primitives to {@link #check(OsmPrimitive)}.
     91     */
     92    public static abstract class TagTest extends Test {
     93        public TagTest(String name, String description) {
     94            super(name, description);
     95        }
     96
     97        public TagTest(String name) {
     98            super(name);
     99        }
     100
     101        public abstract void check(final OsmPrimitive p);
     102
     103        @Override
     104        public void visit(Node n) {
     105            check(n);
     106        }
     107
     108        @Override
     109        public void visit(Way w) {
     110            check(w);
     111        }
     112
     113        @Override
     114        public void visit(Relation r) {
     115            check(r);
     116        }
     117    }
     118
     119    /**
    90120     * Initializes any global data used this tester.
    91121     * @throws Exception When cannot initialize the test
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

    r6584 r6591  
    5656 * @since 6506
    5757 */
    58 public class MapCSSTagChecker extends Test {
     58public class MapCSSTagChecker extends Test.TagTest {
    5959
    6060    /**
     
    338338     * @param p The primitive to inspect.
    339339     */
    340     public void visit(OsmPrimitive p) {
     340    @Override
     341    public void check(OsmPrimitive p) {
    341342        for (TagCheck check : checks) {
    342343            final TestError error = check.getErrorForPrimitive(p);
     
    346347            }
    347348        }
    348     }
    349 
    350     @Override
    351     public void visit(Node n) {
    352         visit((OsmPrimitive) n);
    353     }
    354 
    355     @Override
    356     public void visit(Way w) {
    357         visit((OsmPrimitive) w);
    358     }
    359 
    360     @Override
    361     public void visit(Relation r) {
    362         visit((OsmPrimitive) r);
    363349    }
    364350
  • trunk/src/org/openstreetmap/josm/data/validation/tests/NameMismatch.java

    r6494 r6591  
    2929 * @author Skela
    3030 */
    31 public class NameMismatch extends Test {
     31public class NameMismatch extends Test.TagTest {
    3232    protected static final int NAME_MISSING = 1501;
    3333    protected static final int NAME_TRANSLATION_MISSING = 1502;
     
    5757     * @param p The primitive to be tested
    5858     */
     59    @Override
    5960    public void check(OsmPrimitive p) {
    6061        HashSet<String> names = new HashSet<String>();
     
    100101        }
    101102    }
    102 
    103     /**
    104      * Checks a name mismatch in all primitives.
    105      *
    106      * @param selection The primitives to be tested
    107      */
    108     @Override
    109     public void visit(Collection<OsmPrimitive> selection) {
    110         for (OsmPrimitive p : selection) {
    111             if (!p.isDeleted() && !p.isIncomplete()) {
    112                 check(p);
    113             }
    114         }
    115     }
    116103}
  • trunk/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java

    r6568 r6591  
    3535 * @since 6370
    3636 */
    37 public class OpeningHourTest extends Test {
     37public class OpeningHourTest extends Test.TagTest {
    3838
    3939    /**
     
    222222    }
    223223
    224     protected void check(final OsmPrimitive p) {
     224    @Override
     225    public void check(final OsmPrimitive p) {
    225226        check(p, "opening_hours", CheckMode.TIME_RANGE);
    226227        check(p, "collection_times", CheckMode.BOTH);
    227228        check(p, "service_times", CheckMode.BOTH);
    228229    }
    229 
    230     @Override
    231     public void visit(final Node n) {
    232         check(n);
    233     }
    234 
    235     @Override
    236     public void visit(final Relation r) {
    237         check(r);
    238     }
    239 
    240     @Override
    241     public void visit(final Way w) {
    242         check(w);
    243     }
    244230}
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    r6553 r6591  
    6666 * @author frsantos
    6767 */
    68 public class TagChecker extends Test {
     68public class TagChecker extends Test.TagTest {
    6969   
    7070    /** The default data file of tagchecker rules */
     
    317317    }
    318318
    319     @Override
    320     public void visit(Node n) {
    321         checkPrimitive(n);
    322     }
    323 
    324     @Override
    325     public void visit(Relation n) {
    326         checkPrimitive(n);
    327     }
    328 
    329     @Override
    330     public void visit(Way w) {
    331         checkPrimitive(w);
    332     }
    333 
    334319    /**
    335320     * Checks given string (key or value) if it contains characters with code below 0x20 (either newline or some other special characters)
     
    350335     * @param p The primitive to check
    351336     */
    352     private void checkPrimitive(OsmPrimitive p) {
     337    @Override
     338    public void check(OsmPrimitive p) {
    353339        // Just a collection to know if a primitive has been already marked with error
    354340        MultiMap<OsmPrimitive, String> withErrors = new MultiMap<OsmPrimitive, String>();
Note: See TracChangeset for help on using the changeset viewer.