Ticket #2663: search.patch
| File search.patch, 3.3 KB (added by , 17 years ago) |
|---|
-
src/org/openstreetmap/josm/actions/search/SearchCompiler.java
221 221 } 222 222 223 223 private static class ExactType extends Match { 224 private String type; 225 public ExactType(String type) {this.type = type;} 224 private final Class<?> type; 225 public ExactType(String type) throws ParseError { 226 if ("node".equals(type)) { 227 this.type = Node.class; 228 } else if ("way".equals(type)) { 229 this.type = Way.class; 230 } else if ("relation".equals(type)) { 231 this.type = Relation.class; 232 } else { 233 throw new ParseError(tr("Unknown primitive type: {0}. Allowed values are node, way or relation", 234 type)); 235 } 236 } 226 237 @Override public boolean match(OsmPrimitive osm) { 227 if (osm instanceof Node) 228 return type.equals("node"); 229 if (osm instanceof Way) 230 return type.equals("way"); 231 if (osm instanceof Relation) 232 return type.equals("relation"); 233 throw new IllegalStateException("unknown class "+osm.getClass()); 238 return osm.getClass() == type; 234 239 } 235 240 @Override public String toString() {return "type="+type;} 236 241 } … … 442 447 } 443 448 } 444 449 445 private Match parseKV(String key, String value) {450 private Match parseKV(String key, String value) throws ParseError { 446 451 if (key.equals("type")) { 447 452 return new ExactType(value); 448 453 } else if (key.equals("user")) { 449 454 return new UserMatch(value); 450 455 } else if (key.equals("nodes")) { 451 456 try { 452 return new NodeCount(Integer.parseInt(value)); 453 } catch(Exception x) {} 454 455 try { 456 String[] range = value.split("-", 2); 457 return new NodeCountRange(Integer.parseInt(range[0]), Integer.parseInt(range[1])); 458 } catch(Exception x) {} 459 460 return new NodeCount(0); 457 String[] range = value.split("-"); 458 if (range.length == 1) { 459 return new NodeCount(Integer.parseInt(value)); 460 } else if (range.length == 2) { 461 return new NodeCountRange(Integer.parseInt(range[0]), Integer.parseInt(range[1])); 462 } else { 463 throw new ParseError(tr("Wrong number of parameters for nodes operator.")); 464 } 465 } catch (NumberFormatException e) { 466 throw new ParseError(tr("Incorrect value of nodes operator: {0}. Nodes operator expects number of nodes or range, for example nodes:10-20", value)); 467 } 468 461 469 } else if (key.equals("id")) { 462 470 try { 463 471 return new Id(Long.parseLong(value)); 464 472 } catch (NumberFormatException x) { 465 return new Id(0);473 throw new ParseError(tr("Incorrect value of id operator: {0}. Number is expected.", value)); 466 474 } 467 475 } else { 468 476 return new KeyValue(key, value);
