Ticket #3807: josm-tags-search.patch

File josm-tags-search.patch, 3.5 KB (added by avarab@…, 14 years ago)

Add a tags: search operator

  • src/org/openstreetmap/josm/actions/search/SearchCompiler.java

     
    414414        @Override public String toString() {return "nodes="+minCount+"-"+maxCount;}
    415415    }
    416416
     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
    417446    private static class Modified extends Match {
    418447        @Override public boolean match(OsmPrimitive osm) {
    419448            return osm.isModified() || osm.isNew();
     
    609638            return new ExactType(value);
    610639        else if (key.equals("user"))
    611640            return new UserMatch(value);
     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            }
    612653        else if (key.equals("nodes")) {
    613654            try {
    614655                String[] range = value.split("-");
  • src/org/openstreetmap/josm/actions/search/SearchAction.java

     
    111111                    + "<li>"+tr("<b>user:</b>... - all objects changed by user")+"</li>"
    112112                    + "<li>"+tr("<b>id:</b>... - object with given ID (0 for new objects)")+"</li>"
    113113                    + "<li>"+tr("<b>nodes:</b>... - object with given number of nodes")+"</li>"
     114                    + "<li>"+tr("<b>tags:</b>... - object with given number of tags")+"</li>"
    114115                    + "<li>"+tr("<b>modified</b> - all changed objects")+"</li>"
    115116                    + "<li>"+tr("<b>selected</b> - all selected objects")+"</li>"
    116117                    + "<li>"+tr("<b>incomplete</b> - all incomplete objects")+"</li>"