Changeset 1625 in josm for trunk/src/org/openstreetmap/josm/actions
- Timestamp:
- 2009-05-28T17:55:57+02:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r1607 r1625 222 222 223 223 private static class ExactType extends Match { 224 private String type; 225 public ExactType(String type) {this.type = type;} 226 @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()); 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 } 237 @Override public boolean match(OsmPrimitive osm) { 238 return osm.getClass() == type; 234 239 } 235 240 @Override public String toString() {return "type="+type;} … … 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); … … 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 {
Note:
See TracChangeset
for help on using the changeset viewer.