- Timestamp:
- 2018-12-02T13:59:27+01:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/OsmUtils.java
r14484 r14486 115 115 * Creates a new OSM primitive around (0,0) according to the given assertion. Originally written for unit tests, 116 116 * this can also be used in another places like validation of local MapCSS validator rules. 117 * Ways and relations created using this method are empty. 117 118 * @param assertion The assertion describing OSM primitive (ex: "way name=Foo railway=rail") 118 119 * @return a new OSM primitive according to the given assertion … … 121 122 */ 122 123 public static OsmPrimitive createPrimitive(String assertion) { 123 return createPrimitive(assertion, LatLon.ZERO );124 return createPrimitive(assertion, LatLon.ZERO, false); 124 125 } 125 126 … … 129 130 * @param assertion The assertion describing OSM primitive (ex: "way name=Foo railway=rail") 130 131 * @param around the coordinate at which the primitive will be located 132 * @param enforceLocation if {@code true}, ways and relations will not be empty to force a physical location 131 133 * @return a new OSM primitive according to the given assertion 132 134 * @throws IllegalArgumentException if assertion is null or if the primitive type cannot be deduced from it 133 * @since 1448 4134 */ 135 public static OsmPrimitive createPrimitive(String assertion, LatLon around ) {135 * @since 14486 136 */ 137 public static OsmPrimitive createPrimitive(String assertion, LatLon around, boolean enforceLocation) { 136 138 CheckParameterUtil.ensureParameterNotNull(assertion, "assertion"); 137 139 final String[] x = assertion.split("\\s+", 2); 138 140 final OsmPrimitive p = "n".equals(x[0]) || "node".equals(x[0]) 139 ? new 141 ? newNode(around) 140 142 : "w".equals(x[0]) || "way".equals(x[0]) || /*for MapCSS related usage*/ "area".equals(x[0]) 141 ? newWay(around )143 ? newWay(around, enforceLocation) 142 144 : "r".equals(x[0]) || "relation".equals(x[0]) 143 ? newRelation(around )145 ? newRelation(around, enforceLocation) 144 146 : null; 145 147 if (p == null) { … … 158 160 } 159 161 160 private static Way newWay(LatLon around ) {162 private static Way newWay(LatLon around, boolean enforceLocation) { 161 163 Way w = new Way(); 162 w.addNode(newNode(new LatLon(around.lat()+0.1, around.lon()))); 163 w.addNode(newNode(new LatLon(around.lat()-0.1, around.lon()))); 164 if (enforceLocation) { 165 w.addNode(newNode(new LatLon(around.lat()+0.1, around.lon()))); 166 w.addNode(newNode(new LatLon(around.lat()-0.1, around.lon()))); 167 } 164 168 return w; 165 169 } 166 170 167 private static Relation newRelation(LatLon around ) {171 private static Relation newRelation(LatLon around, boolean enforceLocation) { 168 172 Relation r = new Relation(); 169 r.addMember(new RelationMember(null, newNode(around))); 173 if (enforceLocation) { 174 r.addMember(new RelationMember(null, newNode(around))); 175 } 170 176 return r; 171 177 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
r14484 r14486 44 44 import org.openstreetmap.josm.data.osm.OsmPrimitive; 45 45 import org.openstreetmap.josm.data.osm.OsmUtils; 46 import org.openstreetmap.josm.data.osm.Relation; 46 47 import org.openstreetmap.josm.data.osm.Tag; 48 import org.openstreetmap.josm.data.osm.Way; 47 49 import org.openstreetmap.josm.data.preferences.sources.SourceEntry; 48 50 import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper; … … 1024 1026 for (final Map.Entry<String, Boolean> i : check.assertions.entrySet()) { 1025 1027 Logging.debug("- Assertion: {0}", i); 1026 final OsmPrimitive p = OsmUtils.createPrimitive(i.getKey(), getLocation(check, insideMethod) );1028 final OsmPrimitive p = OsmUtils.createPrimitive(i.getKey(), getLocation(check, insideMethod), true); 1027 1029 // Build minimal ordered list of checks to run to test the assertion 1028 1030 List<Set<TagCheck>> checksToRun = new ArrayList<>(); … … 1033 1035 checksToRun.add(Collections.singleton(check)); 1034 1036 // Add primitive to dataset to avoid DataIntegrityProblemException when evaluating selectors 1035 ds.addPrimitive(p);1037 addPrimitive(ds, p); 1036 1038 final Collection<TestError> pErrors = getErrorsForPrimitive(p, true, checksToRun); 1037 1039 Logging.debug("- Errors: {0}", pErrors); … … 1047 1049 } 1048 1050 return assertionErrors; 1051 } 1052 1053 private static void addPrimitive(DataSet ds, OsmPrimitive p) { 1054 if (p instanceof Way) { 1055 ((Way) p).getNodes().forEach(n -> addPrimitive(ds, n)); 1056 } else if (p instanceof Relation) { 1057 ((Relation) p).getMembers().forEach(m -> addPrimitive(ds, m.getMember())); 1058 } 1059 ds.addPrimitive(p); 1049 1060 } 1050 1061
Note:
See TracChangeset
for help on using the changeset viewer.