diff --git a/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java b/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java
index 94e171d..e10d8af 100644
|
a
|
b
|
import org.openstreetmap.josm.Main;
|
| 15 | 15 | import org.openstreetmap.josm.actions.search.SearchCompiler.InDataSourceArea; |
| 16 | 16 | import org.openstreetmap.josm.data.osm.Node; |
| 17 | 17 | import org.openstreetmap.josm.data.osm.OsmPrimitive; |
| | 18 | import org.openstreetmap.josm.data.osm.OsmUtils; |
| 18 | 19 | import org.openstreetmap.josm.data.osm.Relation; |
| 19 | 20 | import org.openstreetmap.josm.data.osm.Tag; |
| 20 | 21 | import org.openstreetmap.josm.data.osm.Way; |
| … |
… |
public abstract class Condition {
|
| 82 | 83 | return new ExpressionCondition(e); |
| 83 | 84 | } |
| 84 | 85 | |
| | 86 | /** |
| | 87 | * This is the operation that {@link KeyValueCondition} uses to match. |
| | 88 | */ |
| 85 | 89 | public static enum Op { |
| 86 | | EQ, NEQ, GREATER_OR_EQUAL, GREATER, LESS_OR_EQUAL, LESS, |
| 87 | | REGEX, NREGEX, ONE_OF, BEGINS_WITH, ENDS_WITH, CONTAINS; |
| | 90 | /** |
| | 91 | * The value equals the given reference. |
| | 92 | */ |
| | 93 | EQ, |
| | 94 | /** |
| | 95 | * The value does not equal the reference. |
| | 96 | */ |
| | 97 | NEQ, |
| | 98 | /** |
| | 99 | * The value is greater than or equal to the given reference value (as float). |
| | 100 | */ |
| | 101 | GREATER_OR_EQUAL, |
| | 102 | /** |
| | 103 | * The value is greater than the given reference value (as float). |
| | 104 | */ |
| | 105 | GREATER, |
| | 106 | /** |
| | 107 | * The value is less than or equal to the given reference value (as float). |
| | 108 | */ |
| | 109 | LESS_OR_EQUAL, |
| | 110 | /** |
| | 111 | * The value is less than the given reference value (as float). |
| | 112 | */ |
| | 113 | LESS, |
| | 114 | /** |
| | 115 | * The reference is treated as regular expression and the value needs to match it. |
| | 116 | */ |
| | 117 | REGEX, |
| | 118 | /** |
| | 119 | * The reference is treated as regular expression and the value needs to not match it. |
| | 120 | */ |
| | 121 | NREGEX, |
| | 122 | /** |
| | 123 | * The reference is treated as a list separated by ';'. Spaces around the ; are ignored. The value needs to be equal one of the list elements. |
| | 124 | */ |
| | 125 | ONE_OF, |
| | 126 | /** |
| | 127 | * The value needs to begin with the reference string. |
| | 128 | */ |
| | 129 | BEGINS_WITH, |
| | 130 | /** |
| | 131 | * The value needs to end with the reference string. |
| | 132 | */ |
| | 133 | ENDS_WITH, |
| | 134 | /** |
| | 135 | * The value needs to contain the reference string. |
| | 136 | */ |
| | 137 | CONTAINS; |
| 88 | 138 | |
| 89 | 139 | public static final Set<Op> NEGATED_OPS = EnumSet.of(NEQ, NREGEX); |
| 90 | 140 | |
| | 141 | /** |
| | 142 | * Evaluates a value against a reference string. |
| | 143 | * @param testString The value. May be <code>null</code> |
| | 144 | * @param prototypeString The reference string- |
| | 145 | * @return <code>true</code> if and only if this operation matches for the given value/reference pair. |
| | 146 | */ |
| 91 | 147 | public boolean eval(String testString, String prototypeString) { |
| 92 | 148 | if (testString == null && !NEGATED_OPS.contains(this)) |
| 93 | 149 | return false; |
| … |
… |
public abstract class Condition {
|
| 149 | 205 | } |
| 150 | 206 | |
| 151 | 207 | /** |
| 152 | | * Most common case of a KeyValueCondition. |
| | 208 | * Most common case of a KeyValueCondition, this is the basic key=value case. |
| 153 | 209 | * |
| 154 | 210 | * Extra class for performance reasons. |
| 155 | 211 | */ |
| 156 | 212 | public static class SimpleKeyValueCondition extends Condition { |
| | 213 | /** |
| | 214 | * The key to search for. |
| | 215 | */ |
| 157 | 216 | public final String k; |
| | 217 | /** |
| | 218 | * The value to search for. |
| | 219 | */ |
| 158 | 220 | public final String v; |
| 159 | 221 | |
| | 222 | /** |
| | 223 | * Create a new SimpleKeyValueCondition. |
| | 224 | * @param k The key |
| | 225 | * @param v The value. |
| | 226 | */ |
| 160 | 227 | public SimpleKeyValueCondition(String k, String v) { |
| 161 | 228 | this.k = k; |
| 162 | 229 | this.v = v; |
| … |
… |
public abstract class Condition {
|
| 183 | 250 | * |
| 184 | 251 | */ |
| 185 | 252 | public static class KeyValueCondition extends Condition { |
| 186 | | |
| | 253 | /** |
| | 254 | * The key to search for. |
| | 255 | */ |
| 187 | 256 | public final String k; |
| | 257 | /** |
| | 258 | * The value to search for. |
| | 259 | */ |
| 188 | 260 | public final String v; |
| | 261 | /** |
| | 262 | * The key/value match operation. |
| | 263 | */ |
| 189 | 264 | public final Op op; |
| | 265 | /** |
| | 266 | * If this flag is set, {@link #v} is treated as a key and the value is the value set for that key. |
| | 267 | */ |
| 190 | 268 | public boolean considerValAsKey; |
| 191 | 269 | |
| 192 | 270 | /** |
| … |
… |
public abstract class Condition {
|
| 281 | 359 | } |
| 282 | 360 | } |
| 283 | 361 | |
| | 362 | /** |
| | 363 | * This defines how {@link KeyCondition} matches a given key. |
| | 364 | */ |
| 284 | 365 | public static enum KeyMatchType { |
| 285 | | EQ, TRUE, FALSE, REGEX |
| | 366 | /** |
| | 367 | * The key needs to be equal to the given label. |
| | 368 | */ |
| | 369 | EQ, |
| | 370 | /** |
| | 371 | * The key needs to have a true value (yes, ...) |
| | 372 | * @see OsmUtils#isTrue(String) |
| | 373 | */ |
| | 374 | TRUE, |
| | 375 | /** |
| | 376 | * The key needs to have a false value (no, ...) |
| | 377 | * @see OsmUtils#isFalse(String) |
| | 378 | */ |
| | 379 | FALSE, |
| | 380 | /** |
| | 381 | * The key needs to match the given regular expression. |
| | 382 | */ |
| | 383 | REGEX |
| 286 | 384 | } |
| 287 | 385 | |
| 288 | 386 | /** |
| … |
… |
public abstract class Condition {
|
| 306 | 404 | */ |
| 307 | 405 | public static class KeyCondition extends Condition { |
| 308 | 406 | |
| | 407 | /** |
| | 408 | * The key name. |
| | 409 | */ |
| 309 | 410 | public final String label; |
| | 411 | /** |
| | 412 | * If we should negate the result of the match. |
| | 413 | */ |
| 310 | 414 | public final boolean negateResult; |
| | 415 | /** |
| | 416 | * Describes how to match the label against the key. |
| | 417 | * @see KeyMatchType |
| | 418 | */ |
| 311 | 419 | public final KeyMatchType matchType; |
| 312 | | public Predicate<String> containsPattern; |
| | 420 | /** |
| | 421 | * A predicate used to match a the regexp against the key. Only used if the match type is regexp. |
| | 422 | */ |
| | 423 | public final Predicate<String> containsPattern; |
| 313 | 424 | |
| | 425 | /** |
| | 426 | * Creates a new KeyCondition |
| | 427 | * @param label The key name (or regexp) to use. |
| | 428 | * @param negateResult If we should negate the result., |
| | 429 | * @param matchType The match type. |
| | 430 | */ |
| 314 | 431 | public KeyCondition(String label, boolean negateResult, KeyMatchType matchType) { |
| 315 | 432 | this.label = label; |
| 316 | 433 | this.negateResult = negateResult; |
| 317 | | this.matchType = matchType; |
| | 434 | this.matchType = matchType == null ? KeyMatchType.EQ : matchType; |
| 318 | 435 | this.containsPattern = KeyMatchType.REGEX.equals(matchType) |
| 319 | 436 | ? Predicates.stringContainsPattern(Pattern.compile(label)) |
| 320 | 437 | : null; |
| … |
… |
public abstract class Condition {
|
| 324 | 441 | public boolean applies(Environment e) { |
| 325 | 442 | switch(e.getContext()) { |
| 326 | 443 | case PRIMITIVE: |
| 327 | | if (KeyMatchType.TRUE.equals(matchType)) |
| | 444 | switch (matchType) { |
| | 445 | case TRUE: |
| 328 | 446 | return e.osm.isKeyTrue(label) ^ negateResult; |
| 329 | | else if (KeyMatchType.FALSE.equals(matchType)) |
| | 447 | case FALSE: |
| 330 | 448 | return e.osm.isKeyFalse(label) ^ negateResult; |
| 331 | | else if (KeyMatchType.REGEX.equals(matchType)) { |
| | 449 | case REGEX: |
| 332 | 450 | return Utils.exists(e.osm.keySet(), containsPattern) ^ negateResult; |
| 333 | | } else { |
| | 451 | default: |
| 334 | 452 | return e.osm.hasKey(label) ^ negateResult; |
| 335 | 453 | } |
| 336 | 454 | case LINK: |
| … |
… |
public abstract class Condition {
|
| 340 | 458 | } |
| 341 | 459 | } |
| 342 | 460 | |
| | 461 | /** |
| | 462 | * Get the matched key and the corresponding value. |
| | 463 | * <p> |
| | 464 | * WARNING: This ignores {@link #negateResult}. |
| | 465 | * <p> |
| | 466 | * WARNING: For regexp, the regular expression is returned instead of a key if the match failed. |
| | 467 | * @param p The primitive to get the value from. |
| | 468 | * @return The tag. |
| | 469 | */ |
| 343 | 470 | public Tag asTag(OsmPrimitive p) { |
| 344 | 471 | String key = label; |
| 345 | 472 | if (KeyMatchType.REGEX.equals(matchType)) { |