Changeset 6429 in josm for trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
- Timestamp:
- 2013-11-30T23:37:57+01:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r6380 r6429 28 28 import org.openstreetmap.josm.tools.DateUtils; 29 29 import org.openstreetmap.josm.tools.Geometry; 30 import org.openstreetmap.josm.tools.Predicate; 30 31 31 32 /** … … 207 208 * Base class for all search operators. 208 209 */ 209 abstract public static class Match {210 abstract public static class Match implements Predicate<OsmPrimitive> { 210 211 211 212 abstract public boolean match(OsmPrimitive osm); … … 231 232 } 232 233 return true; 234 } 235 236 @Override 237 public final boolean evaluate(OsmPrimitive object) { 238 return match(object); 233 239 } 234 240 } … … 515 521 } 516 522 @Override public String toString() {return key+"="+value;} 523 } 524 525 public static class ValueComparison extends Match { 526 private final String key; 527 private final String referenceValue; 528 private final int compareMode; 529 530 public ValueComparison(String key, String referenceValue, int compareMode) { 531 this.key = key; 532 this.referenceValue = referenceValue; 533 this.compareMode = compareMode; 534 } 535 536 @Override 537 public boolean match(OsmPrimitive osm) { 538 int compareResult; 539 try { 540 compareResult = Double.compare( 541 Double.parseDouble(osm.get(key)), 542 Double.parseDouble(referenceValue) 543 ); 544 } catch (Exception ignore) { 545 compareResult = osm.get(key).compareTo(referenceValue); 546 } 547 return compareMode < 0 ? compareResult < 0 : compareMode > 0 ? compareResult > 0 : compareResult == 0; 548 } 517 549 } 518 550 … … 1231 1263 // factor consists of key:value or key=value 1232 1264 String key = tokenizer.getText(); 1233 if (tokenizer.readIfEqual(Token.EQUALS)) 1265 if (tokenizer.readIfEqual(Token.EQUALS)) { 1234 1266 return new ExactKeyValue(regexSearch, key, tokenizer.readTextOrNumber()); 1235 else if (tokenizer.readIfEqual(Token.COLON)) { 1267 } else if (tokenizer.readIfEqual(Token.LESS_THAN)) { 1268 return new ValueComparison(key, tokenizer.readTextOrNumber(), -1); 1269 } else if (tokenizer.readIfEqual(Token.GREATER_THAN)) { 1270 return new ValueComparison(key, tokenizer.readTextOrNumber(), +1); 1271 } else if (tokenizer.readIfEqual(Token.COLON)) { 1236 1272 // see if we have a Match that takes a data parameter 1237 1273 SimpleMatchFactory factory = simpleMatchFactoryMap.get(key);
Note:
See TracChangeset
for help on using the changeset viewer.