Changeset 6598 in josm for trunk/src/org
- Timestamp:
- 2014-01-02T23:14:44+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/Lanes.java
r6592 r6598 10 10 import java.util.Collection; 11 11 import java.util.HashSet; 12 import java.util.Set; 12 13 import java.util.regex.Pattern; 13 14 … … 24 25 } 25 26 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) { 29 31 // nothing to check 30 32 return; 31 33 } 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>() { 33 35 @Override 34 36 public Integer apply(String key) { 35 37 return getLanesCount(p.get(key)); 36 38 } 37 }) ;38 // if not all numbers are the same39 if (new HashSet<Integer>(lanesCount).size() > 1) {39 })); 40 if (lanesCount.size() > 1) { 41 // if not all numbers are the same 40 42 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 } 41 51 } 42 52 } … … 44 54 @Override 45 55 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")); 49 59 } 50 60 }
Note:
See TracChangeset
for help on using the changeset viewer.