Changeset 7356 in josm for trunk/src/org/openstreetmap/josm/data/osm
- Timestamp:
- 2014-08-01T19:17:40+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/OsmUtils.java
r7005 r7356 6 6 import java.util.List; 7 7 import java.util.Locale; 8 import java.util.Map; 9 10 import org.openstreetmap.josm.tools.CheckParameterUtil; 11 import org.openstreetmap.josm.tools.TextTagParser; 8 12 9 13 public final class OsmUtils { … … 48 52 return FALSE_VALUES.contains(value); 49 53 } 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 } 50 81 }
Note:
See TracChangeset
for help on using the changeset viewer.