Ignore:
Timestamp:
2014-08-01T19:17:40+02:00 (10 years ago)
Author:
Don-vip
Message:

fix #10206 - Check MapCSS validator assertions for local rules if new advanced option validator.check_assert_local_rules is enabled in preferences

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/OsmUtils.java

    r7005 r7356  
    66import java.util.List;
    77import java.util.Locale;
     8import java.util.Map;
     9
     10import org.openstreetmap.josm.tools.CheckParameterUtil;
     11import org.openstreetmap.josm.tools.TextTagParser;
    812
    913public final class OsmUtils {
     
    4852        return FALSE_VALUES.contains(value);
    4953    }
     54
     55    /**
     56     * Creates a new OSM primitive according to the given assertion. Originally written for unit tests,
     57     * this can also be used in another places like validation of local MapCSS validator rules.
     58     * @param assertion The assertion describing OSM primitive (ex: "way name=Foo railway=rail")
     59     * @return a new OSM primitive according to the given assertion
     60     * @throws IllegalArgumentException if assertion is null or if the primitive type cannot be deduced from it
     61     * @since 7356
     62     */
     63    public static OsmPrimitive createPrimitive(String assertion) {
     64        CheckParameterUtil.ensureParameterNotNull(assertion, "assertion");
     65        final String[] x = assertion.split("\\s+", 2);
     66        final OsmPrimitive p = "n".equals(x[0]) || "node".equals(x[0])
     67                ? new Node()
     68                : "w".equals(x[0]) || "way".equals(x[0])
     69                ? new Way()
     70                : "r".equals(x[0]) || "relation".equals(x[0])
     71                ? new Relation()
     72                : null;
     73        if (p == null) {
     74            throw new IllegalArgumentException("Expecting n/node/w/way/r/relation, but got " + x[0]);
     75        }
     76        for (final Map.Entry<String, String> i : TextTagParser.readTagsFromText(x[1]).entrySet()) {
     77            p.put(i.getKey(), i.getValue());
     78        }
     79        return p;
     80    }
    5081}
Note: See TracChangeset for help on using the changeset viewer.