Changeset 6598 in josm for trunk/src


Ignore:
Timestamp:
2014-01-02T23:14:44+01:00 (11 years ago)
Author:
simon04
Message:

see #8519 - Lanes validator: add test for lanes <= count_of(*:lanes) and the like

File:
1 edited

Legend:

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

    r6592 r6598  
    1010import java.util.Collection;
    1111import java.util.HashSet;
     12import java.util.Set;
    1213import java.util.regex.Pattern;
    1314
     
    2425    }
    2526
    26     protected void checkEqualNumberOfLanes(final OsmPrimitive p, Pattern keyPattern, String message) {
    27         final Collection<String> keysForPattern = Utils.filter(p.keySet(), Predicates.stringContainsPattern(keyPattern));
    28         if (keysForPattern.size() < 2) {
     27    protected void checkEqualNumberOfLanes(final OsmPrimitive p, String lanesKey, String message) {
     28        final Collection<String> keysForPattern = Utils.filter(p.keySet(),
     29                Predicates.stringContainsPattern(Pattern.compile(":" + lanesKey + "$")));
     30        if (keysForPattern.size() < 1) {
    2931            // nothing to check
    3032            return;
    3133        }
    32         final Collection<Integer> lanesCount = Utils.transform(keysForPattern, new Utils.Function<String, Integer>() {
     34        final Set<Integer> lanesCount = new HashSet<Integer>(Utils.transform(keysForPattern, new Utils.Function<String, Integer>() {
    3335            @Override
    3436            public Integer apply(String key) {
    3537                return getLanesCount(p.get(key));
    3638            }
    37         });
    38         // if not all numbers are the same
    39         if (new HashSet<Integer>(lanesCount).size() > 1) {
     39        }));
     40        if (lanesCount.size() > 1) {
     41            // if not all numbers are the same
    4042            errors.add(new TestError(this, Severity.WARNING, message, 3100, p));
     43        } else if (lanesCount.size() == 1 && p.hasKey(lanesKey)) {
     44            // ensure that lanes <= *:lanes
     45            try {
     46                if (Integer.parseInt(p.get(lanesKey)) > lanesCount.iterator().next()) {
     47                    errors.add(new TestError(this, Severity.WARNING, tr("Number of {0} greater than {1}", lanesKey, "*:" + lanesKey), 3100, p));
     48                }
     49            } catch (NumberFormatException ignore) {
     50            }
    4151        }
    4252    }
     
    4454    @Override
    4555    public void check(OsmPrimitive p) {
    46         checkEqualNumberOfLanes(p, Pattern.compile(":lanes$"), tr("Number of lane dependent values inconsistent"));
    47         checkEqualNumberOfLanes(p, Pattern.compile(":lanes:forward"), tr("Number of lane dependent values inconsistent in forward direction"));
    48         checkEqualNumberOfLanes(p, Pattern.compile(":lanes:backward"), tr("Number of lane dependent values inconsistent in backward direction"));
     56        checkEqualNumberOfLanes(p, "lanes", tr("Number of lane dependent values inconsistent"));
     57        checkEqualNumberOfLanes(p, "lanes:forward", tr("Number of lane dependent values inconsistent in forward direction"));
     58        checkEqualNumberOfLanes(p, "lanes:backward", tr("Number of lane dependent values inconsistent in backward direction"));
    4959    }
    5060}
Note: See TracChangeset for help on using the changeset viewer.