Changeset 6429 in josm for trunk/src/org
- Timestamp:
- 2013-11-30T23:37:57+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions/search
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/PushbackTokenizer.java
r6380 r6429 59 59 RIGHT_PARENT(marktr("<right parent>")), COLON(marktr("<colon>")), EQUALS(marktr("<equals>")), 60 60 KEY(marktr("<key>")), QUESTION_MARK(marktr("<question mark>")), 61 EOF(marktr("<end-of-file>")) ;61 EOF(marktr("<end-of-file>")), LESS_THAN("<less-than>"), GREATER_THAN("<greater-than>"); 62 62 63 63 private Token(String name) { … … 82 82 } 83 83 84 private static final List<Character> specialChars = Arrays.asList( new Character[] {'"', ':', '(', ')', '|', '^', '=', '?'});85 private static final List<Character> specialCharsQuoted = Arrays.asList( new Character[] {'"'});84 private static final List<Character> specialChars = Arrays.asList('"', ':', '(', ')', '|', '^', '=', '?', '<', '>'); 85 private static final List<Character> specialCharsQuoted = Arrays.asList('"'); 86 86 87 87 private String getString(boolean quoted) { … … 134 134 getChar(); 135 135 return Token.EQUALS; 136 case '<': 137 getChar(); 138 return Token.LESS_THAN; 139 case '>': 140 getChar(); 141 return Token.GREATER_THAN; 136 142 case '(': 137 143 getChar(); -
trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
r6380 r6429 395 395 .addKeyword("*=<i>value</i>", null, tr("''value'' in any key")) 396 396 .addKeyword("<i>key</i>=", null, tr("matches if ''key'' exists")) 397 .addKeyword("<i>key</i>><i>value</i>", null, tr("matches if ''key'' is greater than ''value'' (analogously, less than)")) 397 398 , GBC.eol()); 398 399 right.add(new SearchKeywordRow(hcbSearchString) -
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.