| 417 | private static class TagCount extends Match { |
| 418 | private int count; |
| 419 | public TagCount(int count) {this.count = count;} |
| 420 | @Override public boolean match(OsmPrimitive osm) { |
| 421 | int size = osm.getKeys().size(); |
| 422 | return size == count; |
| 423 | } |
| 424 | @Override public String toString() {return "tags="+count;} |
| 425 | } |
| 426 | |
| 427 | private static class TagCountRange extends Match { |
| 428 | private int minCount; |
| 429 | private int maxCount; |
| 430 | public TagCountRange(int minCount, int maxCount) { |
| 431 | if(maxCount < minCount) { |
| 432 | this.minCount = maxCount; |
| 433 | this.maxCount = minCount; |
| 434 | } else { |
| 435 | this.minCount = minCount; |
| 436 | this.maxCount = maxCount; |
| 437 | } |
| 438 | } |
| 439 | @Override public boolean match(OsmPrimitive osm) { |
| 440 | int size = osm.getKeys().size(); |
| 441 | return (size >= minCount) && (size <= maxCount); |
| 442 | } |
| 443 | @Override public String toString() {return "tags="+minCount+"-"+maxCount;} |
| 444 | } |
| 445 | |
| 641 | else if (key.equals("tags")) |
| 642 | try { |
| 643 | String[] range = value.split("-"); |
| 644 | if (range.length == 1) |
| 645 | return new TagCount(Integer.parseInt(value)); |
| 646 | else if (range.length == 2) |
| 647 | return new TagCountRange(Integer.parseInt(range[0]), Integer.parseInt(range[1])); |
| 648 | else |
| 649 | throw new ParseError(tr("Wrong number of parameters for tags operator.")); |
| 650 | } catch (NumberFormatException e) { |
| 651 | throw new ParseError(tr("Incorrect value of tags operator: {0}. Tags operator expects number of tags or range, for example tags:1 or tags:2-5", value)); |
| 652 | } |