- Timestamp:
- 2021-03-23T00:47:34+01:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerRule.java
r17640 r17642 17 17 import org.openstreetmap.josm.gui.mappaint.Keyword; 18 18 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition; 19 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.TagCondition; 19 20 import org.openstreetmap.josm.gui.mappaint.mapcss.Expression; 20 21 import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction; … … 237 238 try { 238 239 final Condition c = matchingSelector.getConditions().get(index); 239 final Tag tag = c instanceof Condition.ToTagConvertable240 ? (( Condition.ToTagConvertable) c).asTag(p)240 final Tag tag = c instanceof TagCondition 241 ? ((TagCondition) c).asTag(p) 241 242 : null; 242 243 if (tag == null) { -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java
r11713 r17642 2 2 package org.openstreetmap.josm.gui.mappaint.mapcss; 3 3 4 import org.openstreetmap.josm.data.osm.OsmPrimitive;5 4 import org.openstreetmap.josm.data.osm.Tag; 5 import org.openstreetmap.josm.data.osm.Tagged; 6 6 import org.openstreetmap.josm.gui.mappaint.Environment; 7 import org.openstreetmap.josm.tools.CheckParameterUtil; 7 8 8 9 /** … … 18 19 */ 19 20 boolean applies(Environment e); 21 22 /** 23 * Checks if the condition applies in the given {@link Tagged} element. 24 * @param tagged The tagged to check. 25 * @return <code>true</code> if the condition applies. 26 */ 27 default boolean applies(Tagged tagged) { 28 return false; 29 } 20 30 21 31 /** … … 37 47 * This is a condition that can be converted to a tag 38 48 * @author Michael Zangl 39 * @since 10674 49 * @since 10674 (ToTagConvertable), 17642 (TagCondition) 40 50 */ 41 @FunctionalInterface 42 interface ToTagConvertable { 51 interface TagCondition extends Condition { 52 53 @Override 54 default boolean applies(Environment e) { 55 CheckParameterUtil.ensureThat(!e.isLinkContext(), "Illegal state: TagCondition not supported in LINK context"); 56 return applies(e.osm); 57 } 58 59 @Override 60 boolean applies(Tagged tagged); 61 43 62 /** 44 63 * Converts the current condition to a tag 45 * @param primitive A primitiveto use as context. May be ignored.64 * @param tagged A tagged object to use as context. May be ignored. 46 65 * @return A tag with the key/value of this condition. 47 66 */ 48 Tag asTag( OsmPrimitive primitive);67 Tag asTag(Tagged tagged); 49 68 } 50 69 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ConditionFactory.java
r17602 r17642 23 23 import org.openstreetmap.josm.data.osm.Relation; 24 24 import org.openstreetmap.josm.data.osm.Tag; 25 import org.openstreetmap.josm.data.osm.Tagged; 25 26 import org.openstreetmap.josm.data.osm.search.SearchCompiler.InDataSourceArea; 26 27 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon; … … 30 31 import org.openstreetmap.josm.gui.mappaint.Environment; 31 32 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Context; 32 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.T oTagConvertable;33 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.TagCondition; 33 34 import org.openstreetmap.josm.tools.CheckParameterUtil; 34 35 import org.openstreetmap.josm.tools.JosmRuntimeException; … … 257 258 * Extra class for performance reasons. 258 259 */ 259 public static class SimpleKeyValueCondition implements Condition, ToTagConvertable{260 public static class SimpleKeyValueCondition implements TagCondition { 260 261 /** 261 262 * The key to search for. … … 278 279 279 280 @Override 280 public boolean applies( Environment e) {281 return v.equals( e.osm.get(k));282 } 283 284 @Override 285 public Tag asTag( OsmPrimitiveprimitive) {281 public boolean applies(Tagged osm) { 282 return v.equals(osm.get(k)); 283 } 284 285 @Override 286 public Tag asTag(Tagged primitive) { 286 287 return new Tag(k, v); 287 288 } … … 298 299 * 299 300 */ 300 public static class KeyValueCondition implements Condition, ToTagConvertable{301 public static class KeyValueCondition implements TagCondition { 301 302 /** 302 303 * The key to search for. … … 341 342 342 343 @Override 343 public boolean applies( Environment env) {344 return op.eval( env.osm.get(k), considerValAsKey ? env.osm.get(v) : v);345 } 346 347 @Override 348 public Tag asTag( OsmPrimitiveprimitive) {344 public boolean applies(Tagged osm) { 345 return op.eval(osm.get(k), considerValAsKey ? osm.get(v) : v); 346 } 347 348 @Override 349 public Tag asTag(Tagged primitive) { 349 350 return new Tag(k, v); 350 351 } … … 379 380 } 380 381 381 protected boolean matches( Environment env) {382 final String value = env.osm.get(k);382 protected boolean matches(Tagged osm) { 383 final String value = osm.get(k); 383 384 return value != null && pattern.matcher(value).find(); 384 385 } 385 386 386 387 @Override 387 public boolean applies( Environment env) {388 public boolean applies(Tagged osm) { 388 389 if (Op.REGEX == op) { 389 return matches( env);390 return matches(osm); 390 391 } else if (Op.NREGEX == op) { 391 return !matches( env);392 return !matches(osm); 392 393 } else { 393 394 throw new IllegalStateException(); … … 420 421 421 422 @Override 422 protected boolean matches( Environment env) {423 return env.osm.getKeys().entrySet().stream()423 protected boolean matches(Tagged osm) { 424 return osm.getKeys().entrySet().stream() 424 425 .anyMatch(kv -> keyPattern.matcher(kv.getKey()).find() && pattern.matcher(kv.getValue()).find()); 425 426 } … … 537 538 * @see KeyRegexpCondition 538 539 */ 539 public static class KeyCondition implements Condition, ToTagConvertable{540 public static class KeyCondition implements TagCondition { 540 541 541 542 /** … … 567 568 568 569 @Override 569 public boolean applies(Environment e) { 570 CheckParameterUtil.ensureThat(!e.isLinkContext(), "Illegal state: KeyCondition not supported in LINK context"); 570 public boolean applies(Tagged osm) { 571 571 switch (matchType) { 572 572 case TRUE: 573 return e.osm.isKeyTrue(label) ^ negateResult;573 return osm.isKeyTrue(label) ^ negateResult; 574 574 case FALSE: 575 return e.osm.isKeyFalse(label) ^ negateResult;575 return osm.isKeyFalse(label) ^ negateResult; 576 576 case ANY_CONTAINS: 577 577 case ANY_STARTS_WITH: 578 578 case ANY_ENDS_WITH: 579 return e.osm.keys().anyMatch(keyPredicate()) ^ negateResult;579 return osm.keys().anyMatch(keyPredicate()) ^ negateResult; 580 580 default: 581 return e.osm.hasKey(label) ^ negateResult;581 return osm.hasKey(label) ^ negateResult; 582 582 } 583 583 } … … 604 604 */ 605 605 @Override 606 public Tag asTag( OsmPrimitivep) {606 public Tag asTag(Tagged p) { 607 607 String key = label; 608 608 Predicate<String> keyPredicate = keyPredicate(); … … 622 622 * KeyPatternCondition represents a conditions matching keys based on a pattern. 623 623 */ 624 public static class KeyRegexpCondition implements Condition, ToTagConvertable{624 public static class KeyRegexpCondition implements TagCondition { 625 625 626 626 /** … … 644 644 645 645 @Override 646 public boolean applies(Environment e) { 647 CheckParameterUtil.ensureThat(!e.isLinkContext(), "Illegal state: KeyCondition not supported in LINK context"); 648 return e.osm.keys().anyMatch(pattern.asPredicate()) ^ negateResult; 646 public boolean applies(Tagged osm) { 647 return osm.keys().anyMatch(pattern.asPredicate()) ^ negateResult; 649 648 } 650 649 … … 659 658 */ 660 659 @Override 661 public Tag asTag( OsmPrimitivep) {660 public Tag asTag(Tagged p) { 662 661 String key = p.keys().filter(pattern.asPredicate()).findAny().orElse(pattern.pattern()); 663 662 return new Tag(key, p.get(key));
Note:
See TracChangeset
for help on using the changeset viewer.