Changeset 6645 in josm
- Timestamp:
- 2014-01-06T18:40:17+01:00 (11 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/data/validator/combinations.mapcss
r6550 r6645 71 71 *[source:height ][!height], 72 72 *[source:lanes ][!lanes], 73 *[/source:(addr:)?postcode/ ][!addr:postcode], 74 *[/source:(addr:)?housenumber/ ][!addr:housenumber], 73 *[source:postcode ][!addr:postcode], 74 *[source:housenumber ][!addr:housenumber], 75 *[source:addr:postcode ][!addr:postcode], 76 *[source:addr:housenumber ][!addr:housenumber], 75 77 *[source:addr ][!/^addr:/], 76 78 *[source:maxspeed ][!/^maxspeed:?/] { -
trunk/data/validator/deprecated.mapcss
r6633 r6645 179 179 180 180 /* from http://wiki.openstreetmap.org/wiki/Conditional_restrictions#Deprecated_tags */ 181 *[/(day|date|hour)_(on|off)/][!restriction] { 181 *[day_on][!restriction], 182 *[day_off][!restriction], 183 *[date_on][!restriction], 184 *[date_off][!restriction], 185 *[hour_on][!restriction], 186 *[hour_off][!restriction] { 182 187 throwWarning: tr("{0} is deprecated", "{0.key}"); 183 188 suggestAlternative: "*:conditional"; -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java
r6630 r6645 16 16 import org.openstreetmap.josm.gui.mappaint.Environment; 17 17 import org.openstreetmap.josm.tools.CheckParameterUtil; 18 import org.openstreetmap.josm.tools.Predicate; 18 19 import org.openstreetmap.josm.tools.Predicates; 19 20 import org.openstreetmap.josm.tools.Utils; … … 26 27 switch (context) { 27 28 case PRIMITIVE: 28 return new KeyValueCondition(k, v, op, considerValAsKey); 29 return KeyValueRegexpCondition.SUPPORTED_OPS.contains(op) && !considerValAsKey 30 ? new KeyValueRegexpCondition(k, v, op, false) 31 : new KeyValueCondition(k, v, op, considerValAsKey); 29 32 case LINK: 30 33 if (considerValAsKey) … … 180 183 public String toString() { 181 184 return "[" + k + "'" + op + "'" + v + "]"; 185 } 186 } 187 188 public static class KeyValueRegexpCondition extends KeyValueCondition { 189 190 public final Pattern pattern; 191 public static final EnumSet<Op> SUPPORTED_OPS = EnumSet.of(Op.REGEX, Op.NREGEX); 192 193 public KeyValueRegexpCondition(String k, String v, Op op, boolean considerValAsKey) { 194 super(k, v, op, considerValAsKey); 195 CheckParameterUtil.ensureThat(!considerValAsKey, "considerValAsKey is not supported"); 196 CheckParameterUtil.ensureThat(SUPPORTED_OPS.contains(op), "Op must be REGEX or NREGEX"); 197 this.pattern = Pattern.compile(v); 198 } 199 200 @Override 201 public boolean applies(Environment env) { 202 final String value = env.osm.get(k); 203 return value != null && (op.equals(Op.REGEX) 204 ? pattern.matcher(value).find() 205 : !pattern.matcher(value).find()); 182 206 } 183 207 } … … 244 268 public final boolean negateResult; 245 269 public final KeyMatchType matchType; 270 public Predicate<String> containsPattern; 246 271 247 272 public KeyCondition(String label, boolean negateResult, KeyMatchType matchType){ … … 249 274 this.negateResult = negateResult; 250 275 this.matchType = matchType; 276 this.containsPattern = KeyMatchType.REGEX.equals(matchType) 277 ? Predicates.stringContainsPattern(Pattern.compile(label)) 278 : null; 251 279 } 252 280 … … 259 287 else if (KeyMatchType.FALSE.equals(matchType)) 260 288 return e.osm.isKeyFalse(label) ^ negateResult; 261 else if (KeyMatchType.REGEX.equals(matchType)) 262 return Utils.exists(e.osm.keySet(), Predicates.stringContainsPattern(Pattern.compile(label))) ^ negateResult;263 else289 else if (KeyMatchType.REGEX.equals(matchType)) { 290 return Utils.exists(e.osm.keySet(), containsPattern) ^ negateResult; 291 } else { 264 292 return e.osm.hasKey(label) ^ negateResult; 293 } 265 294 case LINK: 266 295 Utils.ensure(false, "Illegal state: KeyCondition not supported in LINK context");
Note:
See TracChangeset
for help on using the changeset viewer.